-
Notifications
You must be signed in to change notification settings - Fork 414
fix(gosec): align to v2.27.1, enforce nosec policy flags, add missing justifications #37100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -195,11 +195,12 @@ security-scan: security-gosec security-govulncheck | |
| .PHONY: security-gosec | ||
| security-gosec: | ||
| @echo "Running gosec security scanner..." | ||
| @command -v gosec >/dev/null || go install github.com/securego/gosec/v2/cmd/gosec@v2.23.0 | ||
| @command -v gosec >/dev/null || go install github.com/securego/gosec/v2/cmd/gosec@v2.27.1 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/diagnose] 💡 Suggested fixReplace the existence guard with an explicit version check: `@gosec_ver`=$$(gosec --version 2>/dev/null | grep -o 'v[0-9.]*' | head -1); \
if [ "$$gosec_ver" != "v2.27.1" ]; then \
go install github.com/securego/gosec/v2/cmd/gosec@v2.27.1; \
fiAlternatively, always install (unconditionally): |
||
| @# Exclusions configured in .golangci.yml (linters-settings.gosec.exclude) | ||
| @# Keep this list in sync with .golangci.yml for consistency | ||
| @GOPATH=$$(go env GOPATH); \ | ||
| PATH="$$GOPATH/bin:$$PATH" gosec -fmt=json -out=gosec-report.json -stdout -exclude-generated -track-suppressions \ | ||
| -nosec-require-rules -nosec-require-justification \ | ||
| -exclude=G101,G115,G204,G602,G301,G302,G304,G306 \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/diagnose] G304 is listed here in the global 💡 Why this matters and a suggested resolutionThe hybrid approach (global exclusion + per-line annotations) has an invisible gap: any new Option A — Drop global exclusion, rely on per-line suppression (recommended):
Option B — Accept documentation-only policy (current implicit choice):
|
||
| ./... | ||
|
Comment on lines
202
to
205
|
||
| @echo "✓ Gosec scan complete (results in gosec-report.json)" | ||
|
|
@@ -390,7 +391,7 @@ check-node-version: | |
| tools: ## Install build-time tools from tools.go | ||
| @echo "Installing build tools..." | ||
| @go install github.com/rhysd/actionlint/cmd/actionlint@v1.7.11 | ||
| @go install github.com/securego/gosec/v2/cmd/gosec@v2.23.0 | ||
| @go install github.com/securego/gosec/v2/cmd/gosec@v2.27.1 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/improve-codebase-architecture] The gosec version 💡 Suggested: single-source the versionDefine a variable at the top of the Makefile: GOSEC_VERSION ?= v2.27.1Then reference it everywhere: go install github.com/securego/gosec/v2/cmd/gosec@$(GOSEC_VERSION)For CI, either read the variable from the Makefile or define it in a shared env var / |
||
| @go install golang.org/x/tools/gopls@v0.21.1 | ||
| @go install golang.org/x/vuln/cmd/govulncheck@v1.1.4 | ||
| @echo "✓ Tools installed successfully" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,7 +45,7 @@ func IsRunnable(markdownPath string) (bool, error) { | |
|
|
||
| // Read the lock file - path is sanitized using filepath.Clean() to prevent path traversal attacks. | ||
| // The lockPath is derived from markdownPath which comes from trusted sources (CLI arguments, validated workflow paths). | ||
| contentBytes, err := os.ReadFile(cleanLockPath) // #nosec G304 | ||
| contentBytes, err := os.ReadFile(cleanLockPath) // #nosec G304 -- path is sanitized with filepath.Clean() and derived from trusted CLI argument | ||
|
Comment on lines
46
to
+48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/zoom-out] The identical lock-file read pattern appears twice in this file — once in 💡 Suggested: extract a shared helper// readLockFile reads and returns the contents of the compiled lock file at lockPath.
// The caller is responsible for sanitizing lockPath with filepath.Clean() before calling.
func readLockFile(cleanLockPath string) ([]byte, error) {
content, err := os.ReadFile(cleanLockPath) // #nosec G304 -- path is sanitized with filepath.Clean() and derived from trusted CLI argument
if err != nil {
return nil, fmt.Errorf("failed to read lock file: %w", err)
}
return content, nil
}This centralises the nosec annotation in one place and removes the maintenance risk of the two sites diverging again. |
||
| if err != nil { | ||
| return false, fmt.Errorf("failed to read lock file: %w", err) | ||
| } | ||
|
|
@@ -98,7 +98,7 @@ func getWorkflowInputs(markdownPath string) (map[string]*workflow.InputDefinitio | |
|
|
||
| // Read the lock file - path is sanitized using filepath.Clean() to prevent path traversal attacks. | ||
| // The lockPath is derived from markdownPath which comes from trusted sources (CLI arguments, validated workflow paths). | ||
| contentBytes, err := os.ReadFile(cleanLockPath) // #nosec G304 | ||
| contentBytes, err := os.ReadFile(cleanLockPath) // #nosec G304 -- path is sanitized with filepath.Clean() and derived from trusted CLI argument | ||
|
Comment on lines
99
to
+101
|
||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to read lock file: %w", err) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/diagnose]
pkg/cli/logs_download.gohas two active-rule nosec annotations using single-dash format that are not covered by this PR:G305 and G110 are not in the global
--excludelist, so they are actively suppressed by these annotations. The single-dash format (-) differs from the--convention reinforced by this PR. While-nosec-require-justificationlikely accepts any non-empty text after the rule ID, adopting--uniformly is worth confirming and patching to avoid surprises with future gosec versions.