Skip to content

Harden command argument validation for pip/uv checks and npm lockfile execution context - #53957

Merged
pelikhan merged 5 commits into
mainfrom
copilot/sighthound-fix-security-findings
Aug 19, 2026
Merged

Harden command argument validation for pip/uv checks and npm lockfile execution context#53957
pelikhan merged 5 commits into
mainfrom
copilot/sighthound-fix-security-findings

Conversation

CopilotAI commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Sighthound flagged multiple exec.Command call sites as potential command-injection paths where arguments may originate from workflow/frontmatter data. This change tightens validation at argument/context boundaries so dynamic values are rejected before process execution.

  • Pip/uv command argument boundary hardening

    • Added validatePipCommandPackageArg in pkg/workflow/pip_validation.go.
    • Applied it before pip command invocation to enforce:
      • no leading -
      • no control characters
      • PyPI/PEP-508 package-name allowlist (validatePipPackageName)
  • npm lockfile generation execution context hardening

    • Updated generatePackageLock in pkg/workflow/dependabot_manifests.go to normalize and validate workflowDir before setting cmd.Dir.
    • Enforces absolute/safe path resolution and verifies the target is an existing directory.
  • Focused security regression coverage

    • Added tests for pip command-arg validation cases in pkg/workflow/argument_injection_test.go (valid package, hyphen-prefix, control chars, whitespace, separator patterns).
    • Added invalid-workflow-dir rejection test in pkg/workflow/dependabot_test.go.
funcvalidatePipCommandPackageArg(pkgNamestring) error {
ifstrings.HasPrefix(pkgName, "-") {
returnerrors.New("names must not start with '-'")
}
ifstrings.IndexFunc(pkgName, unicode.IsControl) >=0 {
returnerrors.New("names must not contain control characters")
}
returnvalidatePipPackageName(pkgName) // PEP-508 allowlist
}

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 10.8 AIC · ⌖ 8.39 AIC · ⊞ 9.3K ·
Comment /souschef to run again

CopilotAIand others added 2 commits August 19, 2026 10:33
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
CopilotAI changed the title [WIP] Fix security findings in github/gh-awHarden command argument validation for pip/uv checks and npm lockfile execution contextAug 19, 2026
CopilotAI requested a review from pelikhanAugust 19, 2026 10:39
@pelikhan
pelikhan marked this pull request as ready for review August 19, 2026 10:41
CopilotAI balanced review requested due to automatic review settings August 19, 2026 10:41
@github-actions

github-actionsBot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actionsBot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel skipped because pre-fetch PR data was unavailable: unable to fetch test file diff

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actionsBot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actionsBot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Ponytail Reviewer completed successfully!

Reviewed PR #53957 diff for over-engineering (ponytail-review). Changes are minimal, focused security hardening: one small validation helper (validatePipCommandPackageArg) consolidating existing checks, and path normalization/stat checks before exec.Command. No speculative abstractions, dead code, reinvented stdlib, or unnecessary flexibility found. Lean already. Ship.

Generated by Ponytail Reviewer for #53957

@github-actions

github-actionsBot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR does not have the 'implementation' label and has ≪100 new lines of code in business logic directories (69 additions across 4 files, threshold is 100).

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

Copy link
Copy Markdown
Contributor

Comment Memory

reviewed_at: 2026-08-19T10:44:33Z
review_event: REQUEST_CHANGES
top_themes:
- inconsistent pip vs uv command-argument validation
- missing positive regression coverage for absolute workflowDir normalization
files_reviewed:
- pkg/workflow/argument_injection_test.go
- pkg/workflow/dependabot_manifests.go
- pkg/workflow/dependabot_test.go
- pkg/workflow/pip_validation.go
comment_count: 2

Note

This comment is managed by comment memory.

It stores persistent context for this thread in the code block at the top of this comment.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · gpt54 · 9.28 AIC · ⌖ 9.08 AIC · ⊞ 7K ·
Comment /review to run again

@github-actionsgithub-actionsBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Requesting changes

This hardening pass is pointed in the right direction, but it still leaves one real gap and misses a regression test for the new npm directory validation.

The blocking themes
  • validatePipCommandPackageArg is only wired into the warning-only pip validation path; the uv validation path still uses the older helper directly, so control-character rejection is inconsistent across two command-invocation paths.
  • The new generatePackageLock path validation only has a rejection test; it does not prove the happy path still runs from the normalized absolute directory, which is the actual behavior this patch changed.

🔎 Code quality review by PR Code Quality Reviewer · gpt54 · 9.28 AIC · ⌖ 9.08 AIC · ⊞ 7K
Comment /review to run again

Comment threadpkg/workflow/pip_validation.go
Comment threadpkg/workflow/dependabot_test.go
@github-actionsgithub-actionsBot mentioned this pull request Aug 19, 2026

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Hardens package-validation commands and npm lockfile generation against unsafe dynamic inputs.

Changes:

  • Adds strict pip package-argument validation.
  • Validates npm’s working directory before execution.
  • Adds focused security regression tests.
Show a summary per file
FileDescription
pkg/workflow/pip_validation.goValidates pip command arguments.
pkg/workflow/dependabot_manifests.goNormalizes and checks npm’s working directory.
pkg/workflow/argument_injection_test.goTests unsafe pip arguments.
pkg/workflow/dependabot_test.goTests invalid workflow-directory rejection.

Review details

  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment threadpkg/workflow/dependabot_manifests.go

@github-actionsgithub-actionsBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Skills-Based Review 🧠

Applied /diagnosing-bugs and /tdd — requesting changes on one correctness gap and two test-coverage issues.

📋 Key Themes & Highlights

Key Themes

  • Incomplete guard coverage: validatePipCommandPackageArg (new control-char + hyphen + PEP-508 check) is only wired into the pip-fallback path. The direct uv path still calls validatePipPackageName without the control-character guard, leaving a gap for the same injection class this PR aims to close.
  • Stale #nosec comment: the G204 annotation in validatePythonPackagesWithPip still names validatePipPackageName instead of the new validatePipCommandPackageArg, which could mislead future security auditors.
  • Narrow regression tests: TestGeneratePackageLock_RejectsInvalidWorkflowDir tests only a newline; relative traversal (../) and nonexistent-path cases are not covered.

Positive Highlights

  • ✅ The new validatePipCommandPackageArg is a clean, composable guard — centralising three distinct checks in one function is exactly the right design.
  • ✅ The filepath.Abs → ValidateAbsolutePath → os.Stat → IsDir chain in generatePackageLock is thorough and correctly uses the resolved absWorkflowDir in both cmd.Dir and the lockfile path.
  • ✅ The added tests are clearly structured and descriptive; the table-driven style is consistent with the rest of the test suite.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 49.2 AIC · ⌖ 13.2 AIC · ⊞ 7.8K
Comment /matt to run again

Comments that could not be inline-anchored

pkg/workflow/pip_validation.go:173

[/diagnosing-bugs] Control-character injection is not blocked on the direct uv execution path. validatePipCommandPackageArg (which adds the unicode.IsControl guard) is only wired into validatePythonPackagesWithPip — the pip-fallback path. When uv is available, validatePipPackageName is still called directly at this line, so a pkgName containing \n or other control characters reaches exec.Command(uvPath, &quot;pip&quot;, &quot;show&quot;, pkgName) uninspected.

<details>
<summary>💡 Suggested …

pkg/workflow/pip_validation.go:88

[/diagnosing-bugs] The #nosec G204 comment at this line still says &quot;validated above by validatePipPackageName&quot; but the guard has been renamed to validatePipCommandPackageArg. This stale comment could mislead future auditors into thinking only PEP-508 validation is in effect, not the control-character check.

<details>
<summary>💡 Suggested fix</summary>

Update the comment to reflect the actual guard function name:

// #nosec G204 -- pipPath is resolved by fileutil.ResolveExecut…</details><details><summary>pkg/workflow/dependabot_test.go:714</summary>**[/tdd]**The`TestGeneratePackageLock_RejectsInvalidWorkflowDir`testonlycoversacontrol-characterinthepath (`&quot;bad\nworkflow-dir&quot;`). Apath-traversalinputsuchas`&quot;/tmp/../etc/passwd&quot;`orarelativepath (`&quot;../secrets&quot;`) wouldexercisethe`ValidateAbsolutePath`and`filepath.Abs`guardsaddedforthe`cmd.Dir` hardening. Withoutthesecasesafuturerefactorthataccidentallydropstheabsolute-pathcheckwouldnotbecaught.
&lt;details&gt;
&lt;summary&gt;💡 Suggestedadditionaltestcases&lt;/su</details>

@github-actionsgithub-actionsBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The hardening changes are correct and well-tested.

  • validatePipCommandPackageArg cleanly layers hyphen-prefix and control-character rejection before the existing PEP 508 regex, covering injection vectors not previously guarded.
  • generatePackageLock now resolves, validates, and stat-checks the working directory before passing it to exec.Command, eliminating the unvalidated path risk.

Test coverage is appropriate for both additions. No blocking issues.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 24 AIC · ⌖ 8.8 AIC · ⊞ 5.7K

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please address the latest maintainer-visible blockers on this PR, refresh the branch if needed, and then run the pr-finisher skill before handing back for maintainer review.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 25 AIC · ⌖ 8.11 AIC · ⊞ 9.3K ·
Comment /souschef to run again

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

CopilotAI commented Aug 19, 2026

Copy link
Copy Markdown
ContributorAuthor

@copilot Please address the latest maintainer-visible blockers on this PR, refresh the branch if needed, and then run the pr-finisher skill before handing back for maintainer review.

Generated by...

Addressed the maintainer-visible blockers in d782d83 and ran the pr-finisher flow locally. CI will need a maintainer re-trigger because agent pushes do not start new workflow runs.

@github-actions

Copy link
Copy Markdown
Contributor

PR Triage

  • Category: bug
  • Risk: high
  • Priority score: 72/100 (impact 35 + urgency 20 + quality 17)
  • Recommended action: fast_track

Security hardening: tightens command-injection validation at exec.Command argument boundaries for pip/uv and npm lockfile execution.

Generated by 🔧 PR Triage Agent · auto · 44.3 AIC · ⌖ 2.78 AIC · ⊞ 8.3K ·

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot This PR has reviewer follow-up that appears addressed in thread replies, but the threads are still unresolved. Please verify the implemented fixes, resolve the open threads if the feedback is satisfied, and then run the pr-finisher skill.

Open review threads (newest first):

Also attempt a branch refresh if GitHub offers one.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 10.8 AIC · ⌖ 8.39 AIC · ⊞ 9.3K ·
Comment /souschef to run again

CopilotAI commented Aug 19, 2026

Copy link
Copy Markdown
ContributorAuthor

@copilot This PR has reviewer follow-up that appears addressed in thread replies, but the threads are still unresolved. Please verify the implemented fixes, resolve the open threads if the feedback is...

Verified the fixes and review state: all three referenced review threads are now resolved. The branch is refreshed against current main via merge commit 8f56e1c. Ran the pr-finisher flow locally; targeted workflow tests, make test-unit-all, make test, and make recompile pass. make lint still reports unrelated pre-existing pkg/intent/governance_formal_test.go testifylint issues on files outside this PR’s diff.

@pelikhan
pelikhan merged commit 22266da into mainAug 19, 2026
25 checks passed
@pelikhan
pelikhan deleted the copilot/sighthound-fix-security-findings branch August 19, 2026 14:45
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.87.2

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[sighthound] Security findings in github/gh-aw

4 participants

@gh-aw-bot@pelikhan