Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 22, 2026

The security fix for CodeQL alert #538 (go/unsafe-quoting) was using manual shell-style quote escaping ('\'') for JSON data embedded in a YAML dictionary value, which is unnecessary and incorrect for YAML context.

Changes

  • Replaced manual escaping with %q format specifier - Go's %q provides proper quoting and escaping for string literals, handling special characters correctly for YAML
  • Removed string manipulation logic - Eliminated manual strings.ReplaceAll() calls for backslashes and quotes
  • Recompiled workflows - Applied the fix across all generated workflow lock files

Before/After

Before (manual shell escaping):

escapedJSON := strings.ReplaceAll(string(viewsJSON), `\`, `\\`)
escapedJSON = strings.ReplaceAll(escapedJSON, `'`, `'\''`)
customEnvVars = append(customEnvVars, fmt.Sprintf("          GH_AW_PROJECT_VIEWS: '%s'\n", escapedJSON))

After (Go format specifier):

customEnvVars = append(customEnvVars, fmt.Sprintf("          GH_AW_PROJECT_VIEWS: %q\n", string(viewsJSON)))

The %q format specifier produces a properly quoted Go string literal that is safe for YAML parsing while still preventing injection attacks.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix go/unsafe-quoting: Escape single quotes in JSON data Replace manual quote escaping with %q format specifier for YAML encoding Jan 22, 2026
Copilot AI requested a review from pelikhan January 22, 2026 22:47
@pelikhan pelikhan marked this pull request as ready for review January 22, 2026 22:53
@pelikhan pelikhan merged commit c40a9a9 into fix/code-scanning-alert-538-unsafe-quoting-v2-00bd24b6b438b87e Jan 22, 2026
@pelikhan pelikhan deleted the copilot/sub-pr-11382 branch January 22, 2026 22:53
pelikhan added a commit that referenced this pull request Jan 22, 2026
…ON data (#11382)

* Fix go/unsafe-quoting: Escape single quotes in JSON data

- Add proper shell escaping for JSON data embedded in environment variables
- Prevents potential command injection via single quotes in user data
- Fixes CodeQL alert #538 (Critical severity)
- Uses POSIX-compatible '\''escaping technique

Security: Addresses CWE-78, CWE-89, CWE-94

* Replace manual quote escaping with %q format specifier (#11386)

* Initial plan

* Use %q for JSON escaping in YAML dictionary values

Replaced manual single-quote escaping with Go's %q format specifier, which:
- Automatically handles all special characters and escaping
- Produces cleaner YAML with double quotes instead of single quotes
- Follows existing codebase patterns (e.g., add_comment.go)
- Simplifies code by removing manual string replacement logic

This addresses the feedback to use simpler escaping for JSON data in YAML dictionary values.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

* Replace manual quote escaping with %q format specifier for YAML encoding (#11392)

* Initial plan

* Recompile workflows after security fix

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

* Add changeset [skip-ci]

---------

Co-authored-by: Code Scanning Fixer Bot <code-scanning-bot@github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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