【问题标题】:go exec command security linting messages using golangci使用 golangci 执行命令安全 linting 消息
【发布时间】:2021-06-22 20:21:46
【问题描述】:

我正在为 golangci-lint 添加 gosec 的 linter,除以下内容外,所有内容均已涵盖:

exec.Command(params[0], params[1:]…)

我知道我可以禁用此 lint,但我不想这样做。有没有办法修复代码以满足这种 lint?

错误是:

 G204: Subprocess launched with function call as argument or cmd arguments ```

【问题讨论】:

    标签: go


    【解决方案1】:

    您可以使用注释排除特定行,而不是禁用 linter;

    exec.Command(params[0], params[1:]...) //nolint:gosec
    

    【讨论】:

      【解决方案2】:

      如果你想禁用这个检查,你可以

      exec.Command(params[0], params[1:]...) // #nosec G204

      【讨论】:

        【解决方案3】:

        硬编码命令调用。有no other optionsAFAIS。

        更新:从版本 1.40 开始,您的 gosec 选项可自定义,请参阅 https://github.com/golangci/golangci-lint 存储库中的示例配置 .golangci.example.yml

        linter-settings:
          gosec:
            # To select a subset of rules to run.
            # Available rules: https://github.com/securego/gosec#available-rules
            includes:
              - G401
              - G306
              - G101
            # To specify a set of rules to explicitly exclude.
            # Available rules: https://github.com/securego/gosec#available-rules
            excludes:
              - G204
            # To specify the configuration of rules.
            # The configuration of rules is not fully documented by gosec:
            # https://github.com/securego/gosec#configuration
            # https://github.com/securego/gosec/blob/569328eade2ccbad4ce2d0f21ee158ab5356a5cf/rules/rulelist.go#L60-L102
            config:
              G306: "0600"
              G101:
                pattern: "(?i)example"
                ignore_entropy: false
                entropy_threshold: "80.0"
                per_char_threshold: "3.0"
                truncate: "32"
        

        【讨论】:

        • 这是你的答案——你运行不同的命令。您还有哪些其他选项不会禁用它?重写功能,所以gosec 不会抱怨。或者您可以禁用消息。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-04-07
        • 2015-04-28
        • 2021-04-24
        • 2020-11-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多