Skip to content

fix(security): eliminate unsafe shell quoting of Gemini JSON config (CodeQL #554)#22765

Merged
pelikhan merged 4 commits intomainfrom
copilot/fix-code-scanning-alert-554
Mar 24, 2026
Merged

fix(security): eliminate unsafe shell quoting of Gemini JSON config (CodeQL #554)#22765
pelikhan merged 4 commits intomainfrom
copilot/fix-code-scanning-alert-554

Conversation

Copy link
Contributor

Copilot AI commented Mar 24, 2026

CodeQL flagged go/unsafe-quoting (critical) in generateGeminiSettingsStep: the JSON config was embedded inline into a bash run script inside single quotes, requiring manual '"'"' escaping for single quotes and leaving double-quote injection potential unaddressed.

Changes

  • Pass JSON via env var instead of inline shell interpolation — GH_AW_GEMINI_BASE_CONFIG is set as a step environment variable and referenced as "$GH_AW_GEMINI_BASE_CONFIG" in the script; double-quoted variable expansion is safe regardless of content
  • Remove manual escapingstrings.ReplaceAll(... "'", '"'"'") and the fmt.Sprintf template are gone
  • Remove unused strings import

Before:

jsonStr := strings.ReplaceAll(string(configJSON), "'", `'"'"'`)
command := fmt.Sprintf(`...
BASE_CONFIG='%s'
...`, jsonStr)
stepLines = FormatStepWithCommandAndEnv(stepLines, command, nil)

After:

command := `...
BASE_CONFIG="$GH_AW_GEMINI_BASE_CONFIG"
...`
env := map[string]string{"GH_AW_GEMINI_BASE_CONFIG": string(configJSON)}
stepLines = FormatStepWithCommandAndEnv(stepLines, command, env)

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw (http block)
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw i_tools.go (http block)
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw -pack /home/REDACTED/work/gh-aw/gh-aw/pkg/workflow/features_import_test.go /home/REDACTED/work/gh-aw/gh-aw/pkg/workflow/importable_tools_test.go (http block)
  • https://api.github.com/repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b
    • Triggering command: /usr/bin/gh gh api /repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b --jq .object.sha on' --ignore-path ../../../.prettierignore (http block)
    • Triggering command: /usr/bin/gh gh api /repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b --jq .object.sha --viewport-size 1280, 720 64/pkg/tool/linu-f /tmp/playwright-git --allowed-origin-C erignore 64/pkg/tool/linuconfig chec�� te '../../../**/remote.origin.url (http block)
  • https://api.github.com/repos/github/gh-aw
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw --jq .visibility .js' --ignore-path .prettierigno-errorsas --local x_amd64/vet (http block)
  • https://api.github.com/repos/github/gh-aw-actions/git/ref/tags/v0
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw-actions/git/ref/tags/v0 --jq .object.sha (http block)
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw-actions/git/ref/tags/v0 --jq .object.sha --verify .cfg 64/pkg/tool/linux_amd64/vet (http block)
  • https://api.github.com/repos/githubnext/agentics/git/ref/tags/
    • Triggering command: /usr/bin/gh gh api /repos/githubnext/agentics/git/ref/tags/# --jq .object.sha ./../pkg/workflo-errorsas (http block)
    • Triggering command: /usr/bin/gh gh api /repos/githubnext/agentics/git/ref/tags/# --jq .object.sha rite '../../../**/*.json' '!../../../pkg/workflo-errorsas .cfg 64/pkg/tool/linux_amd64/vet (http block)

If you need me to access, download, or install something from one of these locations, you can either:


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Copilot AI and others added 2 commits March 24, 2026 21:36
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/4694d1d5-d8f2-4d75-80e0-2090bdf82ebc
…ell quoting (CodeQL #554)

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/4694d1d5-d8f2-4d75-80e0-2090bdf82ebc
Copilot AI changed the title [WIP] Fix code scanning alert 554 fix(security): eliminate unsafe shell quoting of Gemini JSON config (CodeQL #554) Mar 24, 2026
Copilot AI requested a review from pelikhan March 24, 2026 21:43
@pelikhan pelikhan marked this pull request as ready for review March 24, 2026 21:47
Copilot AI review requested due to automatic review settings March 24, 2026 21:47
@pelikhan pelikhan merged commit 8514772 into main Mar 24, 2026
52 of 53 checks passed
@pelikhan pelikhan deleted the copilot/fix-code-scanning-alert-554 branch March 24, 2026 21:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Addresses CodeQL go/unsafe-quoting in the Gemini settings step by eliminating inline shell interpolation of JSON configuration and switching to passing the JSON via an environment variable.

Changes:

  • Move Gemini base JSON config from inline bash assignment to a step env var (GH_AW_GEMINI_BASE_CONFIG).
  • Remove manual single-quote escaping logic and the fmt.Sprintf template usage for the script.
  • Drop the now-unused strings import.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +166 to +169
env := map[string]string{
"GH_AW_GEMINI_BASE_CONFIG": string(configJSON),
}
stepLines = FormatStepWithCommandAndEnv(stepLines, command, env)
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

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

GH_AW_GEMINI_BASE_CONFIG is being set to raw JSON, but FormatStepWithCommandAndEnv currently renders env entries as KEY: <value> without YAML quoting/escaping. Because the value contains {}, :, and quotes, the generated workflow YAML will be parsed as a YAML object (or otherwise fail schema validation) instead of a string, so the env var may not be set and this step can break. Please ensure the env value is emitted as a YAML string scalar (e.g., by quoting/escaping in the step formatter, or by encoding the JSON for transport and decoding it in the script).

Copilot uses AI. Check for mistakes.
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.

3 participants