Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 22, 2026

Addresses feedback on #11382 to simplify JSON escaping when embedding values in YAML dictionaries.

Changes

  • Replace manual POSIX-style single-quote escaping ('\'') with Go's %q format specifier
  • Remove strings.ReplaceAll logic and strings import

Example

Before:

escapedJSON := strings.ReplaceAll(string(viewsJSON), `\`, `\\`)
escapedJSON = strings.ReplaceAll(escapedJSON, `'`, `'\''`)
customEnvVars = append(customEnvVars, fmt.Sprintf("GH_AW_PROJECT_VIEWS: '%s'\n", escapedJSON))
// Generates: GH_AW_PROJECT_VIEWS: '[{"name":"Test'\''s View"}]'

After:

customEnvVars = append(customEnvVars, fmt.Sprintf("GH_AW_PROJECT_VIEWS: %q\n", string(viewsJSON)))
// Generates: GH_AW_PROJECT_VIEWS: "[{\"name\":\"Test's View\"}]"

Both approaches are safe. The %q approach matches the pattern used in add_comment.go and handles all edge cases automatically.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

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>
Copilot AI changed the title [WIP] Fix JSON single quote escaping in YAML dictionary implementation Replace manual quote escaping with %q format specifier Jan 22, 2026
Copilot AI requested a review from pelikhan January 22, 2026 21:34
@pelikhan pelikhan marked this pull request as ready for review January 22, 2026 22:39
@pelikhan pelikhan merged commit 793febd 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:40
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