fix(security): eliminate unsafe shell quoting of Gemini JSON config (CodeQL #554)#22765
fix(security): eliminate unsafe shell quoting of Gemini JSON config (CodeQL #554)#22765
Conversation
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
There was a problem hiding this comment.
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
envvar (GH_AW_GEMINI_BASE_CONFIG). - Remove manual single-quote escaping logic and the
fmt.Sprintftemplate usage for the script. - Drop the now-unused
stringsimport.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| env := map[string]string{ | ||
| "GH_AW_GEMINI_BASE_CONFIG": string(configJSON), | ||
| } | ||
| stepLines = FormatStepWithCommandAndEnv(stepLines, command, env) |
There was a problem hiding this comment.
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).
CodeQL flagged
go/unsafe-quoting(critical) ingenerateGeminiSettingsStep: the JSON config was embedded inline into a bashrunscript inside single quotes, requiring manual'"'"'escaping for single quotes and leaving double-quote injection potential unaddressed.Changes
GH_AW_GEMINI_BASE_CONFIGis 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 contentstrings.ReplaceAll(... "'", '"'"'")and thefmt.Sprintftemplate are gonestringsimportBefore:
After:
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/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)/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)/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/usr/bin/gh gh api /repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b --jq .object.sha on' --ignore-path ../../../.prettierignore(http block)/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/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/usr/bin/gh gh api /repos/github/gh-aw-actions/git/ref/tags/v0 --jq .object.sha(http block)/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//usr/bin/gh gh api /repos/githubnext/agentics/git/ref/tags/# --jq .object.sha ./../pkg/workflo-errorsas(http block)/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.