Skip to content

[code-scanning-fix] Fix go/unsafe-quoting: escape single quotes in GH_AW_UPGRADE_OPTIONS - #58495

Merged
pelikhan merged 2 commits into
mainfrom
fix/alert-673-unsafe-quoting-218b5423648894df
Sep 4, 2026
Merged

[code-scanning-fix] Fix go/unsafe-quoting: escape single quotes in GH_AW_UPGRADE_OPTIONS#58495
pelikhan merged 2 commits into
mainfrom
fix/alert-673-unsafe-quoting-218b5423648894df

Conversation

@github-actions

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

Copy link
Copy Markdown
Contributor

Security Fix: Unsafe YAML single-quote embedding in auto-upgrade workflow generator

Alert Number: #673
Severity: critical
Rule: go/unsafe-quoting
CWE: CWE-78, CWE-89, CWE-94

Vulnerability Description

generateAutoUpdateWorkflowYAML (in pkg/workflow/auto_update_workflow.go) builds the GH_AW_UPGRADE_OPTIONS environment value by JSON-encoding upgradeOptions and embedding the raw JSON string directly inside a single-quoted YAML scalar:

upgradeOptionsEnv = "\n          GH_AW_UPGRADE_OPTIONS: '" + string(encodedOptions) + "'"

JSON encoding does not escape single quotes. If any upgrade option string contains a ' character, it would prematurely close the YAML single-quoted scalar, corrupting the generated workflow YAML structure and potentially allowing injection of unintended YAML/shell content into the generated GitHub Actions workflow file.

Location

  • File: pkg/workflow/auto_update_workflow.go
  • Line: 208

Fix Applied

Wrapped the encoded JSON value with the existing escapeYAMLSingleQuoted helper (already used elsewhere in this package, e.g. observability_otlp.go, evals_steps.go, central_slash_command_workflow.go) which doubles embedded single quotes per YAML single-quoted scalar escaping rules before embedding the value.

Changes Made:

  • Changed string(encodedOptions) to escapeYAMLSingleQuoted(string(encodedOptions)) when constructing the GH_AW_UPGRADE_OPTIONS env line.

Security Best Practices

  • Reused an existing, tested escaping helper rather than introducing new escaping logic.
  • Minimal, surgical change scoped to the vulnerable line only.

Testing Considerations

  • Ran go build ./pkg/workflow/... — succeeds.
  • Ran targeted tests: go test ./pkg/workflow/ -run TestGenerateAutoUpdateWorkflow — all 12 tests pass, including TestGenerateAutoUpdateWorkflow_UpgradeOptions.

Automated by: Code Scanning Fixer Workflow
Run ID: 33875303219

Generated by 🔒 Code Scanning Fixer · copilot · auto · 28.5 AIC · ⌖ 10.8 AIC · ⊞ 10.9K ·

  • expires on Sep 6, 2026, 5:07 AM UTC-08:00

Warning

Firewall blocked 1 domain

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

  • github.com

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

network:
  allowed:
    - defaults
    - "github.com"

See Network Configuration for more information.

Generated by 👨‍🍳 PR Sous Chef · pi · gpt54 · 36.3 AIC · ⌖ 8.69 AIC · ⊞ 9K ·
Comment /souschef to run again


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

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

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Ponytail Reviewer failed. Please review the logs for details.

Warning

Threat Detection Engine Failure — The analysis engine could not complete. This is a tooling failure, not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs for details.

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 #58495

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Test Quality Sentinel completed test quality analysis.

No test files were added or modified in this PR. Test Quality Sentinel skipped.

Warning

Firewall blocked 1 domain

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

  • github.com

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

network:
  allowed:
    - defaults
    - "github.com"

See Network Configuration for more information.

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Sep 4, 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 4, 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 does not have the 'implementation' label and has ≤100 new lines of code in business logic directories.

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

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 critical quoting fix lacks a generator-level regression test using an apostrophe-containing value.

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

Pull request overview

Escapes apostrophes in JSON embedded in generated YAML, preventing unsafe scalar termination.

Changes:

  • Applies the existing YAML single-quote escaping helper to upgrade options.
File summaries
File Description
pkg/workflow/auto_update_workflow.go Safely embeds upgrade options in YAML.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Balanced

return "", fmt.Errorf("failed to encode auto-upgrade options: %w", err)
}
upgradeOptionsEnv = "\n GH_AW_UPGRADE_OPTIONS: '" + string(encodedOptions) + "'"
upgradeOptionsEnv = "\n GH_AW_UPGRADE_OPTIONS: '" + escapeYAMLSingleQuoted(string(encodedOptions)) + "'"

@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 🧠

Applied /diagnosing-bugs. The fix is a correct, minimal, surgical one-liner that reuses the existing escapeYAMLSingleQuoted helper already used elsewhere in the package — good practice, no new escaping logic introduced.

📋 Key Themes & Highlights

Key Themes

  • Missing regression test: no test covers an upgrade option containing a single quote to verify the vulnerability stays fixed.

Positive Highlights

  • ✅ Root cause addressed directly (unescaped single quote in YAML single-quoted scalar), not just a symptom patch.
  • ✅ Reuses an existing, already-tested helper rather than inventing new escaping logic.
  • ✅ Change is scoped to exactly the vulnerable line.

Approving since the fix itself is correct and low-risk; the missing regression test is a minor follow-up, not a blocker.

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

return "", fmt.Errorf("failed to encode auto-upgrade options: %w", err)
}
upgradeOptionsEnv = "\n GH_AW_UPGRADE_OPTIONS: '" + string(encodedOptions) + "'"
upgradeOptionsEnv = "\n GH_AW_UPGRADE_OPTIONS: '" + escapeYAMLSingleQuoted(string(encodedOptions)) + "'"

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.

[/diagnosing-bugs] Correct minimal fix reusing the existing escapeYAMLSingleQuoted helper. However, no regression test was added exercising an upgrade option value containing a single quote to confirm the generated YAML stays valid and GH_AW_UPGRADE_OPTIONS round-trips correctly.

💡 Suggested test
func TestGenerateAutoUpdateWorkflow_UpgradeOptionsWithQuote(t *testing.T) {
    opts := AutoUpdateOptions{UpgradeOptions: []string{"--flag=it's"}}
    yamlStr, err := generateAutoUpdateWorkflowYAML(..., opts)
    require.NoError(t, err)
    // parse yamlStr and assert GH_AW_UPGRADE_OPTIONS decodes back to the original JSON
}

Without this test, a future refactor could silently reintroduce the go/unsafe-quoting vulnerability since nothing currently asserts the quote-escaping behavior for this specific code path.

@copilot please address this.

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Comment Memory

reviewed_at: 2026-09-04T13:40:02Z
review_event: COMMENT
top_themes:
  - yaml-single-quote fix is correct
  - no merge-blocking issues on changed line
files_reviewed:
  - pkg/workflow/auto_update_workflow.go
comment_count: 0

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 · 18.8 AIC · ⌖ 7.31 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 dont see a merge-blocking regression in the changed line. The patch correctly routes the JSON blob through the existing YAML single-quote escaper, which is the right fix for the reported injection risk.

Why Im not requesting changes

The only changed line now matches the escaping pattern already used for other JSON-valued YAML env vars in this package. I also checked the nearby tests and generated workflow expectation; nothing in the diff introduces a new correctness, performance, or maintainability issue on the changed line.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt54 · 18.8 AIC · ⌖ 7.31 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.

Minimal, correct security fix: reuses the existing tested escapeYAMLSingleQuoted helper to properly escape embedded single quotes in the GH_AW_UPGRADE_OPTIONS YAML value, matching the pattern used elsewhere in the package. No issues found.

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

@pelikhan
pelikhan merged commit 36b5fa1 into main Sep 4, 2026
32 checks passed
@pelikhan
pelikhan deleted the fix/alert-673-unsafe-quoting-218b5423648894df branch September 4, 2026 15:07
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.

2 participants