Repository navigation
Add analyzer for overbroad parent-path prefix checks - #80482
Conversation
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
This comment has been minimized.
This comment has been minimized.
|
✅ PR Code Quality Reviewer completed the code quality review. PR Code Quality ReviewerOutcome: The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken. The No-op messageCompleted static review of #80482: published one inline finding and a REQUEST_CHANGES review; recorded the outcome in review-history.
|
|
✅ PR Specification Reviewer completed successfully! Caution agentic threat detected DetailsPotential security threats were detected in the agent output. Detected threat types: prompt injection. Review the workflow run logs for details. PR Specification ReviewerOutcome: The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken. The
|
|
✅ Test Quality Sentinel completed test quality analysis.
|
|
✅ Ponytail Reviewer completed successfully!
|
🏗️ Design Decision Gate — ADR RequiredThis PR makes significant changes to core business logic (>100 new lines) but does not have a linked Architecture Decision Record (ADR). 📄 Draft ADR committed:
🔍 Evidence used
📋 What to do next
Once an ADR is linked in the PR body, this gate will re-run and verify the implementation matches the decision. 📋 Michael Nygard ADR Format ReferenceAn ADR must contain these four sections to be considered complete:
All ADRs are stored in
|
Comment MemoryPeek at saved memory (spec-review-history)History |
Comment MemoryPeek at saved memory (pr-code-quality-reviewer)Note This comment is managed by comment memory.Expand the saved memory block to view or edit the persistent context for this thread.
|
There was a problem hiding this comment.
Found one correctness risk: the analyzer reports a path-specific diagnostic for every exact strings.HasPrefix(..., "..") call, even when the value is not a filesystem path. Because it is registered in the aggregate analyzer set, this can create false positives and make eventual enforcement noisy or unsafe. Please narrow or otherwise validate path context before enabling enforcement. Static review only; no code execution or tests were run per review instructions.
🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~3 AIC · ⌖ ~2 AIC · ⊞ 1.7K
Comment /review to run again
| pos := pass.Fset.PositionFor(call.Pos(), false) | ||
| if filecheck.ShouldSkipFilename(pos.Filename, generatedFiles) || nolint.HasDirectiveForLinter(pos, noLintIndex, linterName) { | ||
| return | ||
| } |
There was a problem hiding this comment.
This diagnostic is emitted for every strings.HasPrefix(..., "..") call, without establishing that the first argument is a filesystem path. The same API is also commonly used for non-path strings (for example, syntax/token prefixes), so registering this analyzer in the aggregate set can produce false positives and make enforcement noisy or unsafe. Please either add a documented/narrower path-context heuristic or validate and account for non-path call sites before enabling enforcement.
There was a problem hiding this comment.
Added the path-context filter and documented the heuristic. The analyzer now only reports path-like names or path/filepath results; ordinary text checks are covered by negative fixtures. Implemented in fb4078f.
There was a problem hiding this comment.
What this change does: Adds an analyzer for overbroad parent-path prefix checks and registers it for use. CI enforcement is deferred.
Nice to have
- Select the second argument directly. The analyzer checks the prefix argument after confirming there are two arguments. The loop hides that simple selection; direct indexing with the existing lint suppression pattern removes six lines. Leaving it as-is adds code to read and maintain.
Verdict: Ship.
Lean: -6 lines possible.
Generated by ✂️ Ponytail Reviewer for #80482 · codex · routed: gpt61 medium · ~5 AIC · ⌖ ~1 AIC · ⊞ 176
Comment /ponytail to run again
| return | ||
| } | ||
| var prefix ast.Expr | ||
| for i, arg := range call.Args { |
There was a problem hiding this comment.
- Select the second argument directly: The length check above guarantees it exists, so replace this loop with
pass.TypesInfo.Types[call.Args[1]].Valueand the usualuncheckedsliceindexsuppression; this removes six lines of indirection for every call.
There was a problem hiding this comment.
Replaced the argument loop with direct access to call.Args[1] and the bounds-check suppression. Implemented in fb4078f.
Comment MemoryPeek at saved memory (review-history)History |
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /tdd and /grill-with-docs. The analyzer is well covered and the change is consistent. Two small nits are left as inline comments, and nothing blocks merge.
📋 Key Themes & Highlights
Verification
go test ./pkg/linters/hasprefixdotdotpathescape/ ./pkg/linters/passes.- The analyzer count moves 101 to 102 consistently across
registry.go,doc.go,spec_test.go, and the README. - Coverage includes aliased and dot imports, constant-folded prefixes, shadowed methods, generated files, and
nolint.
Positive Highlights
- ✅ Resolving
strings.HasPrefixby type throughTypesInfo.Usesavoids false positives from shadowed names. - ✅ Deferring CI enforcement in
notYetEnforcedis the right call. Production code has overbroad call sites, such aspkg/parser/include_expander.go:109andpkg/parser/remote_download_file.go:276. Enforcing this now would break CI.
Follow-up
- When enforcement is enabled, these call sites need a component-aware check or
filepath.IsLocal. Keep this as a tracked follow-up.
@copilot please address the review comments above.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~6 AIC · ⌖ ~2 AIC · ⊞ 7.1K
Comment /matt to run again
| return | ||
| } | ||
| var prefix ast.Expr | ||
| for i, arg := range call.Args { |
There was a problem hiding this comment.
[/codebase-design] The for loop only selects call.Args[1], and the len(call.Args) != 2 guard above already makes that index safe. A direct index is clearer.
💡 Suggested change
prefix := call.Args[1]This replaces the var prefix declaration and the four-line loop, and the i == 1 special case goes away with it.
@copilot please address this.
There was a problem hiding this comment.
Replaced the loop with direct call.Args[1] access. Implemented in fb4078f.
| "filepathwalkpreferwalkdir": "existing filepath.Walk calls need remediation before CI enforcement", | ||
| "formatintitoa": "existing FormatInt conversions need remediation before CI enforcement", | ||
| "fprintferrorunchecked": "existing production violations need remediation before enforcement; nolint suppression already works", | ||
| "hasprefixdotdotpathescape": "existing parent-path checks need review and remediation before CI enforcement", |
There was a problem hiding this comment.
[/codebase-design] The notYetEnforced map is kept in alphabetical order, and this entry breaks that order by sitting before goroutineresourceleak. Move it between hardcodedfilepath and httpclientnotimeout so the list stays sorted.
@copilot please address this.
There was a problem hiding this comment.
Moved the exemption entry between hardcodedfilepath and httpclientnotimeout. Implemented in fb4078f.
🧪 Test Quality Sentinel Report✅ Test Quality Score: 100/100 — Excellent
📊 Metrics (1 test)
🔎 Notes
Verdict
|
There was a problem hiding this comment.
✅ Test Quality Sentinel: 100/100. 0% implementation tests (threshold: 30%). No guideline violations.
🧪 Test quality analysis by Test Quality Sentinel · copilot · routed: haiku55 xhigh · ~5 AIC · ⌖ ~2 AIC · ⊞ 7.4K
Comment /review to run again
There was a problem hiding this comment.
🟡 Changes recommended
The linter reports intentional non-path two-dot prefix checks because it does not verify path provenance, requiring path-related filtering and a negative fixture.
1 open issue
1 file not reviewed
pkg/linters/hasprefixdotdotpathescape/testdata/src/checks/generated.go: Generated file
What changed in this PR
Adds hasprefixdotdotpathescape to gh-aw’s custom Go analyzers to flag strings.HasPrefix(value, "..") checks that also match names such as ..foo.
Changes:
- Matches standard-library calls through type information, including aliased and dot imports and constant prefixes.
- Adds fixtures for matching, separator-aware alternatives, shadowed names, generated files, and suppression directives.
- Registers and documents the analyzer while deferring CI enforcement pending review of existing call sites.
| File | Description |
|---|---|
pkg/linters/spec_test.go |
Adds the analyzer to documentation-contract checks. |
pkg/linters/registry.go |
Registers the analyzer. |
pkg/linters/README.md |
Documents its purpose and deferred enforcement. |
pkg/linters/hasprefixdotdotpathescape/testdata/src/dotimport/dotimport.go |
Covers dot-import matching. |
pkg/linters/hasprefixdotdotpathescape/testdata/src/checks/generated.go |
Covers generated-file exclusion. |
pkg/linters/hasprefixdotdotpathescape/testdata/src/checks/checks.go |
Adds positive and negative fixtures. |
pkg/linters/hasprefixdotdotpathescape/hasprefixdotdotpathescape.go |
Implements matching and diagnostics. |
pkg/linters/hasprefixdotdotpathescape/hasprefixdotdotpathescape_test.go |
Runs analyzer fixtures. |
pkg/linters/doc.go |
Updates the analyzer catalog and count. |
pkg/linters/doc_sync_test.go |
Records the CI-enforcement exemption. |
Review effort: Balanced (adaptive)
| if filecheck.ShouldSkipFilename(pos.Filename, generatedFiles) || nolint.HasDirectiveForLinter(pos, noLintIndex, linterName) { | ||
| return | ||
| } | ||
| pass.Reportf(call.Pos(), `strings.HasPrefix(value, "..") also matches names like "..foo"; check exact ".." and a separator, or use filepath.IsLocal`) |
There was a problem hiding this comment.
Added a path-context filter using path-like identifier components and typed path/filepath operations, with negative fixtures for ordinary text prefixes. Implemented in fb4078f.
There was a problem hiding this comment.
💥 [THE END] — Illustrated by Smoke Claude · claude · sonnet46 · ~76 AIC · ⌖ ~6 AIC · ⊞ 1K
Comment /smoke-claude to run again
| return | ||
| } | ||
| var prefix ast.Expr | ||
| for i, arg := range call.Args { |
There was a problem hiding this comment.
The loop for i, arg := range call.Args only selects call.Args[1]. Since the len(call.Args) != 2 guard above already ensures the index is safe, a direct prefix := call.Args[1] would be simpler and more idiomatic. 🔍
There was a problem hiding this comment.
Simplified the second-argument selection to direct call.Args[1] access. Implemented in fb4078f.
| if filecheck.ShouldSkipFilename(pos.Filename, generatedFiles) || nolint.HasDirectiveForLinter(pos, noLintIndex, linterName) { | ||
| return | ||
| } | ||
| pass.Reportf(call.Pos(), `strings.HasPrefix(value, "..") also matches names like "..foo"; check exact ".." and a separator, or use filepath.IsLocal`) |
There was a problem hiding this comment.
The diagnostic fires on any strings.HasPrefix(x, "..") call regardless of whether x is a filesystem path. Consider adding a path-context heuristic (e.g. checking the variable name or type) to reduce false positives on non-path string comparisons. 🛡️
There was a problem hiding this comment.
Added a documented path-context heuristic and negative text-prefix fixtures, so non-path strings are ignored. Implemented in fb4078f.
There was a problem hiding this comment.
🔵 Needs a closer look
The linter reports path-escape diagnostics for ordinary text-prefix checks because it does not verify path provenance, requiring narrower detection and a negative test fixture.
1 open issue
1 file not reviewed
pkg/linters/hasprefixdotdotpathescape/testdata/src/checks/generated.go: Generated file
Review effort: Balanced (adaptive)
|
🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:
Keeping the changes focused; human review and CI get the final taste test. No merging or CI triggering. Structured data{
"completed_task": 0,
"head": "676070950f6e14819d114d7c328a808323cbe76d",
"kind": "requested",
"schema_version": "1",
"state": "163ad523ba888a3e01ecd5190666a5d01c8a4d2ff565ecc12bcd5224f3c05162",
"work": [
"0f9272902c0a65c2eac6e2f75fec4faaf2db24281bf5c31862c745264c694679",
"16e4927c6db36f7de71629d60531d5d2033ebbcd1b6557df265d275ac1162173",
"35bd94315b2210222450554d1263fe288deb8d9c4d292cbfb132ebd5ab828802",
"70fb8205917c0800fd65558e4df6540334818484a55184be927c385b2922a112",
"a15672d4b005390d16c06c600c95d1cf6d249cf0c8d7e2c3a4dbabc3535e1494",
"aee998e56ab8fa70cca98e8fde036f7c82a47a81b8db490ed6a32631ebc65381",
"f708329ea63766bf1df33655f90ef95c02d70b6ab69e0f9e6a858f25ff475a97"
],
"workflow": "pr-sous-chef"
}
|
…asprefix-dotdot-path-escape Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

strings.HasPrefix(path, "..")also matches legitimate names such as..foo. The new analyzer flags this pattern and recommends a component-aware check orfilepath.IsLocal.strings.HasPrefixby type, including aliased and dot imports, and recognizes constant prefixes.nolintdirectives.<!-- START COPILOT CODING AGENT SUFFIX -->
✨ PR Review Safe Output Test - Run 45249368416