Skip to content

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Jan 22, 2026

Security Fix: Unsafe Quoting in Project Views Configuration

Alert Number: #538
Severity: Critical
Rule: go/unsafe-quoting
CWE: CWE-78 (OS Command Injection), CWE-89 (SQL Injection), CWE-94 (Code Injection)

Vulnerability Description

The code was constructing a shell environment variable by embedding JSON data directly into a single-quoted string without proper escaping. If the JSON data contained a single quote character, it could break out of the enclosing quotes and potentially allow command injection.

Vulnerable Code (Line 47):

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

If viewsJSON contains the character ', it would prematurely close the string literal and potentially execute arbitrary shell commands.

Location

  • File: pkg/workflow/update_project_job.go
  • Line: 47
  • Function: buildUpdateProjectJob

Fix Applied

Added proper shell escaping for single quotes before embedding the JSON data into the environment variable string. The fix uses POSIX-compatible shell escaping:

  1. Escape backslashes first: \\\ (prevents interference with quote escaping)
  2. Escape single quotes: ''\'' (ends the quoted string, adds escaped quote, starts new quoted string)

Changes Made:

  • Added strings import for string manipulation
  • Replaced backslashes with double backslashes to prevent escape sequence interference
  • Replaced single quotes with '\'' (POSIX shell escape sequence)
  • Applied escaping to viewsJSON before embedding in the format string

Secure Code (Lines 48-52):

// Escape single quotes in JSON to prevent shell injection
// Replace backslashes first, then single quotes
escapedJSON := strings.ReplaceAll(string(viewsJSON), `\`, `\\`)
escapedJSON = strings.ReplaceAll(escapedJSON, `'`, `'\''`)
customEnvVars = append(customEnvVars, fmt.Sprintf("          GH_AW_PROJECT_VIEWS: '%s'\n", escapedJSON))

Security Best Practices

This fix follows CodeQL's recommendations for handling potentially untrusted data:

  1. Input Sanitization: Always escape special characters when embedding user-provided or dynamic data into shell commands
  2. Defense in Depth: The escaping approach handles both backslashes and quotes to prevent complex injection attempts
  3. POSIX Compliance: The '\'' technique works across all POSIX-compliant shells (bash, sh, zsh, etc.)
  4. Preserve Functionality: The fix maintains the original behavior while preventing injection attacks

Testing Considerations

  • Unit Tests: Consider adding tests with JSON data containing single quotes, backslashes, and other special characters
  • Integration Tests: Test the workflow with project views that contain special characters in their configuration
  • Security Testing: Verify that malicious input cannot break out of the quoted string

Automated by: Code Scanning Fixer Workflow
Run ID: 21263052463

AI generated by Code Scanning Fixer


Changeset

  • Type: patch
  • Description: Escape single quotes and backslashes when embedding JSON into shell environment variables to prevent shell injection (fixes go/unsafe-quoting).

Ahoy! This treasure was crafted by 🏴‍☠️ Changeset Generator

- 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
return nil, fmt.Errorf("failed to marshal views configuration: %w", err)
}
customEnvVars = append(customEnvVars, fmt.Sprintf(" GH_AW_PROJECT_VIEWS: '%s'\n", string(viewsJSON)))
// Escape single quotes in JSON to prevent shell injection
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot we are writing a value in a yaml dictionary. The ' ' are not stricly needed. Encode viewsJSON using the YAML Marshal encoder insteead.

Copy link
Contributor

Copilot AI commented Jan 22, 2026

@pelikhan I've opened a new pull request, #11386, to work on those changes. Once the pull request is ready, I'll request review from you.

* 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>
@pelikhan
Copy link
Contributor

@copilot recompile

Copy link
Contributor

Copilot AI commented Jan 22, 2026

@pelikhan I've opened a new pull request, #11392, to work on those changes. Once the pull request is ready, I'll request review from you.

…ing (#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>
@pelikhan pelikhan added the smoke label Jan 22, 2026
@github-actions
Copy link
Contributor Author

📰 BREAKING: Smoke Copilot is now investigating this pull request. Sources say the story is developing...

@github-actions
Copy link
Contributor Author

github-actions bot commented Jan 22, 2026

🎬 THE ENDSmoke Claude MISSION: ACCOMPLISHED! The hero saves the day! ✨

@github-actions
Copy link
Contributor Author

github-actions bot commented Jan 22, 2026

✨ The prophecy is fulfilled... Smoke Codex has completed its mystical journey. The stars align. 🌟

@github-actions
Copy link
Contributor Author

github-actions bot commented Jan 22, 2026

🎉 Yo ho ho! Changeset Generator found the treasure and completed successfully! ⚓💰

@github-actions
Copy link
Contributor Author

Smoke Test Results

Last 2 Merged PRs:

Test Results:

  • ✅ GitHub MCP
  • ✅ Safe Inputs GH CLI
  • ✅ Serena MCP
  • ✅ Playwright
  • ✅ File Writing
  • ✅ Bash Tool

Overall Status: PASS

cc @pelikhan

AI generated by Smoke Copilot

@github-actions
Copy link
Contributor Author

📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤

@github-actions
Copy link
Contributor Author

GitHub MCP (last 2 merged PRs): ✅ Replace manual quote escaping with %q format specifier for YAML encoding; Replace manual quote escaping with %q format specifier
safeinputs-gh pr list: ✅
Serena activate_project: ✅
Playwright github.com title contains "GitHub": ✅
Tavily search results: ✅
File write (/tmp/gh-aw/agent/smoke-test-codex-21267824404.txt): ✅
Bash cat verify: ✅
Overall status: PASS

AI generated by Smoke Codex

@github-actions
Copy link
Contributor Author

Smoke Test: PASS

Retrieved PRs:

Test Results: ✅ GitHub MCP | ✅ Safe Inputs GH CLI | ✅ Serena MCP | ✅ Playwright | ✅ Tavily | ✅ File Write | ✅ Bash

Overall Status: PASS

AI generated by Smoke Claude

@pelikhan pelikhan marked this pull request as ready for review January 22, 2026 23:00
@pelikhan pelikhan enabled auto-merge (squash) January 22, 2026 23:00
@pelikhan pelikhan merged commit 1b5ed9b into main Jan 22, 2026
48 checks passed
@pelikhan pelikhan deleted the fix/code-scanning-alert-538-unsafe-quoting-v2-00bd24b6b438b87e branch January 22, 2026 23:00
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.

3 participants