Skip to content

fix: gmpctl hardening#1938

Closed
bwplotka wants to merge 2 commits into
mainfrom
fix-git-command-injection-20260520
Closed

fix: gmpctl hardening#1938
bwplotka wants to merge 2 commits into
mainfrom
fix-git-command-injection-20260520

Conversation

@bwplotka

@bwplotka bwplotka commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

A few fixes.

Includes:

  • Only set GPG_TTY if a valid TTY was successfully detected.
  • Optimize directory walks with filepath.WalkDir in cmd_vulnfix.go.
  • Forward stderr for temp schema run in cmd_vulnfix.go.
  • Use idiomatic string comparison for branch == "main".
  • Use find -prune to efficiently skip large directories in lib.sh.
  • Add CVSSMetricV30 fallback to NVD API severity parsing in nvdapi.go.
  • Enable main branch vulnfix.
  • Dependency, tagging, cache, and semconv sync fixes.
  • Fix documentation format (CI was adding +go downloading on a cold cache)
  • Pin TOOLCHAIN to Go 1.25 for consistent Go version behavior, while allowing 1.26 (future) on images

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances the gmpctl tool by automating Go version detection from Dockerfiles, resolving OpenTelemetry schema version conflicts, adding automated pull request creation via the GitHub CLI, and introducing a thread-safe cache for NVD API severity lookups. Feedback on these changes focuses on improving robustness and performance, such as handling non-interactive environments gracefully in TTY detection, utilizing filepath.WalkDir and find -prune for more efficient directory traversal, capturing standard error in command execution, using idiomatic string comparisons, and falling back to CVSS V3.0 metrics when V3.1 is missing.

Comment thread ops/gmpctl/git.go Outdated
Comment thread ops/gmpctl/git.go Outdated
Comment thread ops/gmpctl/cmd_vulnfix.go Outdated
Comment thread ops/gmpctl/cmd_vulnfix.go
Comment thread ops/gmpctl/cmd_vulnfix.go Outdated
Comment thread ops/gmpctl/gmp.go Outdated
Comment thread ops/gmpctl/lib.sh Outdated
Comment thread ops/gmpctl/vulnupdatelist/nvdapi.go
Comment thread ops/gmpctl/lib.sh
# This is faster than running requiring bingo and running bingo get.
cp "${dir}/.bingo/variables.env" "${dir}/.bingo/variables.env.bak"
echo "#!/bin/bash" >"${dir}/.bingo/variables.env" # Clean the file.
# NOTE: Only needed before 0.19.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc

@bwplotka bwplotka force-pushed the fix-git-command-injection-20260520 branch from 9324726 to 1fac05b Compare June 23, 2026 12:26
@bwplotka bwplotka changed the title [WIP] gmpctl fixes fix: gmpctl hardening Jun 23, 2026
@bwplotka bwplotka force-pushed the fix-git-command-injection-20260520 branch from 1fac05b to bbc8811 Compare June 23, 2026 13:28
Best effort fixes thanks to Gemini security scanning.

Includes:
- Only set GPG_TTY if a valid TTY was successfully detected.
- Optimize directory walks with filepath.WalkDir in cmd_vulnfix.go.
- Forward stderr for temp schema run in cmd_vulnfix.go.
- Use idiomatic string comparison for branch == "main".
- Use find -prune to efficiently skip large directories in lib.sh.
- Add CVSSMetricV30 fallback to NVD API severity parsing in nvdapi.go.
- Fix TestReplaceOtelImports to run git init in temp dir.
- Allow main vulnfix.
- Dependency, tagging, cache, and semconv sync fixes.
- Format documentation.
@bwplotka bwplotka force-pushed the fix-git-command-injection-20260520 branch from bbc8811 to ca69faf Compare June 23, 2026 13:31
@bwplotka bwplotka marked this pull request as ready for review June 23, 2026 13:32
@bwplotka bwplotka force-pushed the fix-git-command-injection-20260520 branch 3 times, most recently from ed1e0eb to d284b00 Compare June 23, 2026 15:19
Comment thread ops/gmpctl/cmd_vulnfix.go
}
// Update go version in go.mod to what toolchain is set to if it was updated by accident
// otherwise it won't work with our toolchain.
if _, err := runCommand(&cmdOpts{Dir: dir, Envs: opts}, "go", "mod", "edit", "-go=1.25.0"); err != nil {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incompatible with GOTOOLCHAIN=local, which is applied to ensure we're actually building with the toolchain from the build image.

Also, we do not want to lock in to a specific patch version. For 1.25, latest is 1.25.11, and we do not want to introduce new vulnerabilities from the toolchain because we're locked into .0.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately that also means it depends what Go version you have installed etc.

Comment thread ops/gmpctl/cmd_vulnfix.go
// We are hardcoding toolchain everywhere for now, until we have deps that require higher version.
// This makes it simpler to maintain dependencies across old versions, forks and tools (e.g. code gen).
// This follows what e.g. Prometheus is doing https://github.com/prometheus/prometheus/pull/18938#issue-4676291443
fmt.Sprintf("GOTOOLCHAIN=go1.25.0"),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GOTOOLCHAIN feels like the wrong tool to prevent dependency updates.

Signed-off-by: bwplotka <bwplotka@google.com>
@bwplotka bwplotka force-pushed the fix-git-command-injection-20260520 branch from d284b00 to 652ed09 Compare June 26, 2026 11:50
@bwplotka

Copy link
Copy Markdown
Collaborator Author

Newer version of the same, without toolchain #1971

@bwplotka bwplotka closed this Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants