Skip to content

Move max AI credits expression to step env and validate integer in shell run block - #58116

Merged
pelikhan merged 2 commits into
mainfrom
copilot/fix-codeql-injection-alert
Sep 3, 2026
Merged

Move max AI credits expression to step env and validate integer in shell run block#58116
pelikhan merged 2 commits into
mainfrom
copilot/fix-codeql-injection-alert

Conversation

Copilot AI commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Compiled workflows previously interpolated ${{ vars.GH_AW_DEFAULT_DETECTION_MAX_AI_CREDITS || '400' }} (and agent equivalent) directly into executable shell run: bodies, triggering CodeQL actions/code-injection/medium alerts. This PR shifts expression evaluation into step env: blocks and adds shell-level integer validation before configuring the AWF firewall budget.

Changes

  • AWF Command Builder: Updated buildMaxAICreditsExport in pkg/workflow/awf_command_builder.go to stop embedding ${{ vars.* }} expressions in the shell script. The generated bash script now checks that GH_AW_MAX_AI_CREDITS strictly matches ^[0-9]+$, falling back to default budgets (400 for detection/evals, 1000 for agents) if invalid or empty.
  • Engine Environment Propagation: Added applyDefaultMaxAICreditsEnvToMap to Claude, Codex, Gemini, Pi, BehaviorDefined, and UniversalLLMConsumer engine execution step generators so GH_AW_MAX_AI_CREDITS is provided via YAML env:.
  • Golden Fixtures and Compiled Workflows: Updated unit tests in pkg/workflow/awf_config_test.go, refreshed wasm golden fixtures, and recompiled workflow lock files across the repository.

Example Generated Shell Change

# Before:
GH_AW_MAX_AI_CREDITS="${{ vars.GH_AW_DEFAULT_DETECTION_MAX_AI_CREDITS || '400' }}"

# After:
GH_AW_MAX_AI_CREDITS="${GH_AW_MAX_AI_CREDITS:-400}"
if [[ ! "$GH_AW_MAX_AI_CREDITS" =~ ^[0-9]+$ ]]; then
  GH_AW_MAX_AI_CREDITS="400"
fi

… in shell run block

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix CodeQL injection alert for GH_AW_DEFAULT_DETECTION_MAX_AI_CREDITS Move max AI credits expression to step env and validate integer in shell run block Sep 3, 2026
Copilot AI requested a review from pelikhan September 3, 2026 04:05
@pelikhan
pelikhan marked this pull request as ready for review September 3, 2026 04:05
Copilot AI balanced review requested due to automatic review settings September 3, 2026 04:05
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft.

No ADR enforcement needed: PR does not have the implementation label and has <=100 new lines of code in business logic directories (38 added).

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel skipped because pre-fetch PR data was unavailable: unable to fetch PR file list

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

⚠️ Security scanning failed for Ponytail Reviewer. Review the logs for details.

No review comments posted because the pre-fetched PR diff was empty.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • ab.chatgpt.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "ab.chatgpt.com"

See Network Configuration for more information.

Generated by Ponytail Reviewer for #58116

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

Warning

Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • api.github.com
  • github.com

[!TIP]
api.github.com is blocked because GitHub API access uses the built-in GitHub tools by default. Instead of adding api.github.com to network.allowed, use tools.github.mode: gh-proxy for direct pre-authenticated GitHub CLI access without requiring network access to api.github.com:

tools:
  github:
    mode: gh-proxy

See GitHub Tools for more information on gh-proxy mode.

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "api.github.com"
    - "github.com"

See Network Configuration for more information.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

Warning

Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • github.com
  • proxy.golang.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "github.com"
    - "proxy.golang.org"

See Network Configuration for more information.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Comment Memory

reviewed_at: 2026-09-03T04:09:00Z
review_event: COMMENT
top_themes:
  - no blocking issues found in max-ai-credits env migration
files_reviewed:
  - pkg/workflow/awf_command_builder.go
  - pkg/workflow/awf_config_test.go
  - pkg/workflow/awf_env.go
  - pkg/workflow/awf_env_test.go
  - pkg/workflow/claude_engine.go
  - pkg/workflow/codex_engine.go
  - pkg/workflow/gemini_engine.go
  - pkg/workflow/pi_engine.go
  - pkg/workflow/behavior_defined_engine.go
  - pkg/workflow/universal_llm_consumer_engine.go
  - pkg/workflow/copilot_engine_execution.go
comment_count: 0

Note

This comment is managed by comment memory.

It stores persistent context for this thread in the code block at the top of this comment.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

Warning

Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • api.github.com
  • github.com

[!TIP]
api.github.com is blocked because GitHub API access uses the built-in GitHub tools by default. Instead of adding api.github.com to network.allowed, use tools.github.mode: gh-proxy for direct pre-authenticated GitHub CLI access without requiring network access to api.github.com:

tools:
  github:
    mode: gh-proxy

See GitHub Tools for more information on gh-proxy mode.

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "api.github.com"
    - "github.com"

See Network Configuration for more information.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt54 · 48 AIC · ⌖ 7.34 AIC · ⊞ 23.5K ·
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No blocking correctness or maintainability regressions stood out in the max-ai-credits env migration.

### Review notes

I checked the changed runtime path in pkg/workflow/awf_command_builder.go and the engine env wiring across the touched engines. The new flow consistently moves the GitHub expression into step env, preserves the detection/evals/main default split, and validates the shell value before it is injected into the AWF config JSON. I did not find a changed-line issue that clearly justifies blocking this PR.

Warning

Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • api.github.com
  • github.com

[!TIP]
api.github.com is blocked because GitHub API access uses the built-in GitHub tools by default. Instead of adding api.github.com to network.allowed, use tools.github.mode: gh-proxy for direct pre-authenticated GitHub CLI access without requiring network access to api.github.com:

tools:
  github:
    mode: gh-proxy

See GitHub Tools for more information on gh-proxy mode.

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "api.github.com"
    - "github.com"

See Network Configuration for more information.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt54 · 48 AIC · ⌖ 7.34 AIC · ⊞ 23.5K
Comment /review to run again

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Budget validation and external-detector environment propagation have unresolved moderate issues.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Moves AI-credit expressions from executable shell bodies into step environments, adds runtime validation, and regenerates affected workflow artifacts.

Changes:

  • Propagates AI-credit defaults through engine environments.
  • Adds shell validation and fallback budgets.
  • Refreshes tests, golden fixtures, and compiled workflows.
File summaries
File Description
pkg/workflow/universal_llm_consumer_engine.go Adds budget environment propagation.
pkg/workflow/testdata/TestWasmGolden_CompileFixtures/with-imports.golden Refreshes compiled fixture.
pkg/workflow/testdata/TestWasmGolden_CompileFixtures/smoke-copilot.golden Refreshes compiled fixture.
pkg/workflow/testdata/TestWasmGolden_CompileFixtures/playwright-cli-mode.golden Refreshes compiled fixture.
pkg/workflow/testdata/TestWasmGolden_CompileFixtures/basic-copilot.golden Refreshes compiled fixture.
pkg/workflow/testdata/TestWasmGolden_AllEngines/pi.golden Refreshes Pi output.
pkg/workflow/testdata/TestWasmGolden_AllEngines/gemini.golden Refreshes Gemini output.
pkg/workflow/testdata/TestWasmGolden_AllEngines/copilot.golden Refreshes Copilot output.
pkg/workflow/testdata/TestWasmGolden_AllEngines/codex.golden Refreshes Codex output.
pkg/workflow/testdata/TestWasmGolden_AllEngines/claude.golden Refreshes Claude output.
pkg/workflow/pi_engine.go Adds Pi budget environment propagation.
pkg/workflow/gemini_engine.go Adds budget propagation; external detection can lose the value due to first-step extraction (moderate, 1 vote).
pkg/workflow/codex_engine.go Adds Codex budget environment propagation.
pkg/workflow/claude_engine.go Adds Claude budget environment propagation.
pkg/workflow/behavior_defined_engine.go Adds budget propagation; setup steps can prevent external detectors from receiving it (moderate, 1 vote).
pkg/workflow/awf_config_test.go Tests generated budget-validation logic.
pkg/workflow/awf_command_builder.go Adds shell validation; budget semantics remain incorrect (moderate, 2 votes), and an obsolete option remains (nit, 1 vote).
.github/workflows/workflow-health-manager.lock.yml Regenerates budget handling.
.github/workflows/smoke-copilot-aoai-entra.lock.yml Regenerates budget handling.
.github/workflows/smoke-copilot-aoai-apikey.lock.yml Regenerates budget handling.
.github/workflows/semantic-function-refactor.lock.yml Moves the budget expression into the environment.
.github/workflows/schema-consistency-checker.lock.yml Regenerates budget handling.
.github/workflows/safe-output-health.lock.yml Moves the budget expression into the environment.
.github/workflows/pr-triage-agent.lock.yml Regenerates budget handling.
.github/workflows/portfolio-analyst.lock.yml Moves the budget expression into the environment.
.github/workflows/notion-issue-summary.lock.yml Moves the budget expression into the environment.
.github/workflows/hippo-embed.lock.yml Moves the budget expression into the environment.
.github/workflows/firewall.lock.yml Adds budget validation.
.github/workflows/example-permissions-warning.lock.yml Moves the budget expression into the environment.
.github/workflows/detection-analysis-report.lock.yml Moves the detection budget into the environment.
.github/workflows/daily-team-evolution-insights.lock.yml Adds detection-budget validation.
.github/workflows/daily-safe-output-optimizer.lock.yml Moves the detection budget into the environment.
.github/workflows/daily-regulatory.lock.yml Moves the detection budget into the environment.
.github/workflows/daily-observability-report.lock.yml Moves the detection budget into the environment.
.github/workflows/daily-max-ai-credits-test.lock.yml Updates budget test workflow output.
.github/workflows/daily-grader-audit.lock.yml Moves the detection budget into the environment.
.github/workflows/daily-compiler-quality.lock.yml Adds detection-budget validation.
.github/workflows/daily-cli-tools-tester.lock.yml Moves the detection budget into the environment.
.github/workflows/daily-arxiv-researcher.lock.yml Adds detection-budget validation.
.github/workflows/copilot-centralization-optimizer.lock.yml Moves the detection budget into the environment.
.github/workflows/copilot-centralization-drilldown.lock.yml Moves the detection budget into the environment.
.github/workflows/codex-github-remote-mcp-test.lock.yml Moves the agent budget into the environment.
.github/workflows/code-simplifier.lock.yml Adds detection-budget validation.
.github/workflows/ci-coach.lock.yml Adds detection-budget validation.
.github/workflows/audit-workflows.lock.yml Moves the detection budget into the environment.
.github/workflows/archivx-agentic-workflows-analyzer.lock.yml Moves the detection budget into the environment.
.github/workflows/agent-performance-analyzer.lock.yml Adds detection-budget validation.
.github/workflows/agent-job-health.lock.yml Moves the detection budget into the environment.
Review details
  • Files reviewed: 61/312 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@@ -346,6 +346,7 @@ touch %s

// Add safe outputs env
applySafeOutputEnvToMap(env, workflowData)
applyDefaultMaxAICreditsEnvToMap(env, workflowData)

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Skills-Based Review 🧠

Applied /codebase-design — one actionable finding on a now-dead config flag; core CodeQL fix itself is sound and well-tested.

📋 Key Themes & Highlights

Key Themes

  • Dead config field: ResolveMaxAICreditsFromEnv in AWFCommandConfig is set true only by the copilot engine but is never read by buildMaxAICreditsExport/buildAWFConfigFileSetup. Behavior is unconditional for all engines now, so the flag misleads future readers into thinking other engines keep the old inline-expression path.

Positive Highlights

  • ✅ Correctly moves the ${{ vars.* }} expression out of the shell run: body and into step env:, addressing the CodeQL actions/code-injection/medium finding at its root rather than just suppressing it.
  • ✅ Adds a defensive ^[0-9]+$ regex check before using the env value in the generated AWF config JSON, preventing malformed/injected values from reaching the firewall budget.
  • ✅ Good test coverage added in awf_config_test.go and awf_env_test.go covering agent/detection/evals default fallback paths.

Warning

Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • github.com
  • proxy.golang.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "github.com"
    - "proxy.golang.org"

See Network Configuration for more information.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · sonnet50 · 98.3 AIC · ⌖ 13.7 AIC · ⊞ 10.3K
Comment /matt to run again

@pelikhan
pelikhan merged commit 8e30bcd into main Sep 3, 2026
95 of 106 checks passed
@pelikhan
pelikhan deleted the copilot/fix-codeql-injection-alert branch September 3, 2026 04:28
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.88.2

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.

gh aw compile generates CodeQL injection alert for GH_AW_DEFAULT_DETECTION_MAX_AI_CREDITS in shell run block

3 participants