Skip to content

[code-scanning-fix] Fix go/unsafe-quoting: unsafe quoting in import cycle error message - #58189

Merged
pelikhan merged 2 commits into
mainfrom
fix-alert-671-unsafe-quoting-ff0d5bd89aeef225
Sep 3, 2026
Merged

[code-scanning-fix] Fix go/unsafe-quoting: unsafe quoting in import cycle error message#58189
pelikhan merged 2 commits into
mainfrom
fix-alert-671-unsafe-quoting-ff0d5bd89aeef225

Conversation

@github-actions

@github-actions github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Security Fix: Unsafe Quoting in Import Cycle Error Message

Alert Numbers: #671, #670
Severity: Critical
Rule: go/unsafe-quoting
CWE: CWE-78, CWE-89, CWE-94

Vulnerability Description

ImportCycleError.Error() in pkg/parser/import_error.go manually wrapped
untrusted import-path strings (importer, imported) in single quotes using
fmt.Sprintf("... '%s' from '%s' ...", ...). If an import path contained a
single quote character, it could break out of the enclosing quotes and alter
the structure of the resulting message, which is later displayed to users
and could be embedded in other formatted/templated output.

Location

  • File: pkg/parser/import_error.go
  • Line: 37

Fix Applied

Replaced the manual '%s' quoting with Go's built-in %q format verb, which
safely quotes and escapes special characters (including embedded quotes)
using standard Go string-escaping rules, eliminating the injection risk.

Changes Made:

  • Changed '%s' from '%s' to %q from %q in the Error() method of ImportCycleError.
  • Updated existing unit tests (pkg/parser/import_cycle_test.go) to expect
    the new double-quoted, safely-escaped output format.

Security Best Practices

  • Use language-provided safe formatting/escaping primitives (%q) instead of
    manual string concatenation/quoting for untrusted data embedded in messages.

Testing Considerations

  • Ran go test ./pkg/parser/... — all tests pass, including the updated
    TestImportCycleDetection_SelfImport and TestImportCycleError_FormattedOutput
    cases that assert on the exact error message format.

Automated by: Code Scanning Fixer Workflow
Run ID: 33725870616

Generated by 🔒 Code Scanning Fixer · copilot · auto · 36.6 AIC · ⌖ 9.8 AIC · ⊞ 10.9K ·

  • expires on Sep 4, 2026, 11:08 PM UTC-08:00

Generated by 👨‍🍳 PR Sous Chef · pi · gpt54 · 34.6 AIC · ⌖ 9.83 AIC · ⊞ 8.7K ·
Comment /souschef to run again


Branch refresh requested by PR Sous Chef run https://github.com/github/gh-aw/actions/runs/33740403993

Generated by 👨‍🍳 PR Sous Chef · pi · gpt54 · 29.2 AIC · ⌖ 8.78 AIC · ⊞ 9.2K ·
Comment /souschef to run again

…le error message

Fixes go/unsafe-quoting alert where circular import chain names were
manually wrapped in single quotes via fmt.Sprintf, allowing a single
quote in an import path to break out of the enclosing quotes. Replaced
with Go's %q verb which safely escapes special characters.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft.

No ADR enforcement needed: PR #58189 does not have the implementation label and has only 4 added lines in default business logic directories (<=100 threshold).

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

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

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

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

⚠️ Security scanning failed for Ponytail Reviewer. Review the logs for details.

Lean already. Ship.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • ab.chatgpt.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "ab.chatgpt.com"

See Network Configuration for more information.

Generated by Ponytail Reviewer for #58189

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

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

Copilot AI 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.

🟡 Changes recommended

The security fix lacks regression coverage for quote-bearing import paths.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Hardens import-cycle errors by safely quoting untrusted import paths.

Changes:

  • Replaces manual quoting with Go’s %q formatting.
  • Updates existing error-message expectations.
File summaries
File Review
pkg/parser/import_error.go Safely quotes paths in import-cycle errors.
pkg/parser/import_cycle_test.go Updates expected formatting, but needs coverage for embedded single and double quotes with exact escaping assertions.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

"circular import detected: b.md → c.md → d.md → b.md",
"Imports must form a directed acyclic graph",
"remove the import of 'b.md' from 'd.md'",
"remove the import of \"b.md\" from \"d.md\"",

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Skills-Based Review 🧠

Reviewed this 4-line security fix using /diagnosing-bugs and /codebase-design lenses — no actionable issues found.

📋 Key Themes & Highlights

Key Themes

  • Root cause properly addressed: replaced manual '%s' quoting with Go's %q verb, which safely escapes embedded quotes/control characters — the correct fix for the CWE-78/89/94 class of issue described.
  • Regression coverage present: existing tests (TestImportCycleDetection_SelfImport, TestImportCycleError_FormattedOutput) were updated to assert on the new %q-quoted output, so the format change is pinned and any future regression to unsafe quoting would be caught.
  • Change is scoped and consistent: only the one Sprintf call and its two dependent test assertions were touched; no unrelated code was modified.

Positive Highlights

  • ✅ Uses the language-provided safe formatting primitive (%q) instead of ad-hoc escaping logic.
  • ✅ Tests updated in the same PR rather than left to bit-rot.

@copilot please address the review comments above.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · sonnet50 · 16.8 AIC · ⌖ 14.5 AIC · ⊞ 10.3K
Comment /matt to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewed with the Impeccable skills lens (change classified as mixed_unclear -> critique/audit); this PR has no UI surface, so those Impeccable modes don't meaningfully apply here.

The change itself is a correct, minimal security fix: replaces manual '%s' quoting with Go's %q verb in ImportCycleError.Error(), safely escaping untrusted import-path strings and eliminating the quote-breakout risk (CWE-78/89/94). Tests were updated consistently to match the new double-quoted, escaped output format.

No blocking issues found.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · copilot · sonnet50 · 16.1 AIC · ⌖ 13.3 AIC · ⊞ 8.3K

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Comment Memory

reviewed_at: 2026-09-03T07:38:51.556+00:00
review_event: REQUEST_CHANGES
top_themes:
  - executable script permissions were dropped across 12 tracked entrypoints
files_reviewed:
  - pkg/parser/import_error.go
  - pkg/parser/import_cycle_test.go
  - .github/graders/daily-file-diet-operational-value.sh
  - .github/skills/github-discussion-query/query-discussions.py
  - .github/skills/github-discussion-query/query-discussions.sh
  - .github/skills/github-issue-query/query-issues.sh
  - .github/skills/github-labels-query/query-labels.sh
  - .github/skills/github-pr-query/query-prs.sh
  - .github/skills/github-workflows-query/query-workflows.sh
  - .github/skills/jqschema/jqschema.sh
  - .github/skills/operational-value-designer/scripts/operational-value-evaluator-path.sh
  - .github/skills/operational-value-designer/scripts/verify-operational-value-evaluator.sh
  - .github/skills/operational-value-designer/tests/test.sh
  - .github/skills/resolve-merge-conflicts/resolve.sh
comment_count: 1

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 · copilot · gpt54 · 26.9 AIC · ⌖ 7.42 AIC · ⊞ 21.8K ·
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Verdict

I don't see a changed-line defect here that warrants blocking this PR. The %q switch is the correct hardening change, and the test updates match the new escaping behavior.

Highlights

The patch is narrowly scoped to the vulnerable formatting path, and the updated assertions cover the externally visible message change without widening behavior elsewhere.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt54 · 26.9 AIC · ⌖ 7.42 AIC · ⊞ 21.8K
Comment /review to run again

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please take the next forward-progress pass on this PR.

  • Copilot review still asks for regression coverage around quote-bearing import paths in pkg/parser/import_cycle_test.go, especially embedded single/double quotes with exact escaping assertions.
  • The other workflow reviews look non-blocking; please address that remaining coverage gap, rerun the relevant tests, and summarize the exact escaping cases you validated.
  • After pushing the follow-up, run the pr-finisher skill and call out any remaining maintainer-facing blocker.

Generated by 👨‍🍳 PR Sous Chef · pi · gpt54 · 34.6 AIC · ⌖ 9.83 AIC · ⊞ 8.7K ·
Comment /souschef to run again

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

Copilot AI commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

@copilot Please take the next forward-progress pass on this PR.

  • Copilot review still asks for regression coverage around quote-bearing import paths in pkg/parser/import_cycle_test.go, especially ...

Added regression coverage in f18eecc. The test uses import paths containing both embedded single quotes (importer's ..., imported's ...) and double quotes, and asserts the exact %q output with escaped \" characters in the recommendation.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please take the next forward-progress pass on this PR.

  • Your latest follow-up says the regression coverage for quote-bearing import paths is already on HEAD; please close the loop by running the pr-finisher skill and confirming whether any maintainer-facing blocker remains.
  • Specifically call out the exact escaping cases now covered in pkg/parser/import_cycle_test.go and whether any review state still needs to be refreshed.

Generated by PR Sous Chef: https://github.com/github/gh-aw/actions/runs/33738703891

Generated by 👨‍🍳 PR Sous Chef · pi · gpt54 · 22.8 AIC · ⌖ 8.75 AIC · ⊞ 9.2K ·
Comment /souschef to run again

Copilot AI commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

@copilot Please take the next forward-progress pass on this PR.

  • Your latest follow-up says the regression coverage for quote-bearing import paths is already on HEAD; please close the loop by runnin...

HEAD is f18eecc and contains TestImportCycleError_QuoteBearingPaths in pkg/parser/import_cycle_test.go. It covers both single quotes (importer's, imported's) and double quotes ("path"), asserting the exact recommendation with both names rendered by %q and embedded double quotes escaped as \". The review thread itself remains unresolved, so that review state still needs maintainer/tooling refresh; no further code changes are needed.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please take the next forward-progress pass on this PR.

  • Your latest update says pkg/parser/import_cycle_test.go now covers both embedded single quotes and embedded double quotes with exact %q escaping assertions on HEAD f18eecc.
  • Please run the pr-finisher skill, request/reconcile refreshed review state for the still-unresolved review thread, and summarize whether anything beyond maintainer/tooling review refresh still blocks merge.
  • If no code work remains, say that explicitly in maintainer-facing terms.

Generated by PR Sous Chef: https://github.com/github/gh-aw/actions/runs/33740403993

Generated by 👨‍🍳 PR Sous Chef · pi · gpt54 · 29.2 AIC · ⌖ 8.78 AIC · ⊞ 9.2K ·
Comment /souschef to run again

Copilot AI commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

@copilot Please take the next forward-progress pass on this PR.

  • Your latest update says pkg/parser/import_cycle_test.go now covers both embedded single quotes and embedded double quotes with exac...

No code work remains. HEAD f18eecc already includes TestImportCycleError_QuoteBearingPaths, covering single quotes in importer's/imported's and double quotes in "path", with an exact assertion for %q output and escaped \". Refreshed PR state still shows the original review thread unresolved and the PR mergeable_state as blocked; maintainer/tooling review refresh and thread resolution remain the only merge blockers.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please take the next forward-progress pass on this PR.

  • Recent follow-up says HEAD already contains the escaping regression coverage and no further code work remains.
  • Please run the pr-finisher skill, request or reconcile refreshed review state for the still-unresolved review thread, and summarize whether anything beyond maintainer/tooling review refresh still blocks merge.
  • If no code work remains, say that explicitly.

Generated by PR Sous Chef: https://github.com/github/gh-aw/actions/runs/33751044673

Generated by 👨‍🍳 PR Sous Chef · pi · gpt54 · 18.5 AIC · ⌖ 10.9 AIC · ⊞ 8.9K ·
Comment /souschef to run again

Copilot AI commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

@copilot Please take the next forward-progress pass on this PR.

  • Recent follow-up says HEAD already contains the escaping regression coverage and no further code work remains....

No code work remains. Reconciled refreshed PR state: HEAD is still f18eecc, and TestImportCycleError_QuoteBearingPaths asserts single-quote-bearing names plus embedded double quotes are rendered by %q with exact \" escaping. The review thread remains unresolved and PR state remains blocked; maintainer/tooling review refresh and thread resolution are the only remaining blockers.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please take another pass on this PR. Please review the current status, refresh the branch if needed, address any outstanding review feedback or failing checks, and then use the pr-finisher skill to move it toward merge readiness.

Generated by 👨‍🍳 PR Sous Chef · pi · gpt54 · 8.18 AIC · ⌖ 8.66 AIC · ⊞ 8.7K ·
Comment /souschef to run again

Copilot AI commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

@copilot Please take another pass on this PR. Please review the current status, refresh the branch if needed, address any outstanding review feedback or failing checks, and then use the pr-finisher ...

Reconciled the current PR state. No code work remains: HEAD is unchanged at f18eecc, with TestImportCycleError_QuoteBearingPaths covering single quotes in importer's/imported's and embedded double quotes in "path", asserting exact %q output with \" escaping. Current branch CI runs for the prior action-required CGO/CWI checks are now successful; the latest PR-comment workflow is still in progress. The review thread remains unresolved and the PR is still merge-blocked by maintainer/tooling review state.

@pelikhan
pelikhan merged commit 707f8b8 into main Sep 3, 2026
36 checks passed
@pelikhan
pelikhan deleted the fix-alert-671-unsafe-quoting-ff0d5bd89aeef225 branch September 3, 2026 20:00
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

🎉 This pull request is included in a new release.

Release: v0.88.3

Sign up for free to 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.

4 participants