Skip to content

fix: reject arbitrary env.* expressions in markdown at compile time - #23070

Closed
pelikhan with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-env-expression-rejection
Closed

pelikhan with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-env-expression-rejection

Conversation

Copilot AI commented Mar 26, 2026 •

Copy link
Copy Markdown
Contributor

Arbitrary env.* expressions (e.g. ${{ env.GITHUB_TOKEN }}) were silently accepted by gh-aw compile and wired into the agent's runtime environment via the generated lock file — despite being explicitly prohibited by the documented safety policy. Workflow authors depending on compile-time rejection for accidental secret exposure had no protection.

env.GH_AW_* expressions (internal gh-aw system variables such as env.GH_AW_SAFE_OUTPUTS) remain allowed, as they are set by the gh-aw runtime itself and do not expose user-defined secrets.

Changes

  • Narrow env.* allowlist to env.GH_AW_* only — replaced envRegex/EnvRe with envGhAwRegex/EnvGhAwRe (^env\.GH_AW_[a-zA-Z0-9_]+$) in ExpressionValidationOptions and all validation paths (property-access and comparison-extraction)
  • Update error message allowed list — the hint shown on validation failure now lists env.GH_AW_* (gh-aw internal system variables only) instead of the previous env.*
  • Fix existing tests — authorized_env_variable renamed to unauthorized_env_variable (now expects error); multiple_unauthorized_expressions updated to also assert env.TEST is rejected; env variable with string default (env.X || 'literal') also now correctly errors
  • Add TestEnvExpressionRejection regression test — covers blocked cases (env.GITHUB_TOKEN, plain vars, underscores, hyphens, mixed-content markdown) and allowed cases (env.GH_AW_SAFE_OUTPUTS, env.GH_AW_WORKFLOW_ID_SANITIZED)
# Before
$ gh-aw compile env_direct.md
✓ Compiled successfully
# lock file contains: GH_AW_ENV_GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}

# After
$ gh-aw compile env_direct.md
error: 1 unauthorized expressions found
  - env.GITHUB_TOKEN
Use only allowed expressions:
  ...
  - env.GH_AW_* (gh-aw internal system variables only)

# Internal system variables still work
$ gh-aw compile safe-outputs.md   # uses ${{ env.GH_AW_SAFE_OUTPUTS }}
✓ Compiled successfully

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

Per the documented safety policy, env.* expressions (e.g. ${{ env.GITHUB_TOKEN }})
are prohibited in workflow markdown. This removes env.* from the expression
allowlist so gh-aw compile rejects them with a clear error instead of propagating
them into the generated lock file.

- Remove envRegex and EnvRe from ExpressionValidationOptions
- Remove env.* from allowed expressions list in error messages
- Update tests: env.* now expects errors (was incorrectly allowed)
- Add TestEnvExpressionRejection regression test

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/2909de21-a895-4fd2-ba4a-a786ff534ce5

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix gh-aw to reject env.* expressions in markdown fix: reject env.* expressions in markdown at compile time Mar 26, 2026
Copilot AI requested a review from pelikhan March 26, 2026 07:14
@pelikhan
pelikhan marked this pull request as ready for review March 26, 2026 07:23
Copilot AI review requested due to automatic review settings March 26, 2026 07:23

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.

Pull request overview

This PR enforces compile-time rejection of env.* GitHub Actions expressions embedded in workflow markdown, preventing them from being silently accepted and propagated into the generated lock/runtime environment.

Changes:

  • Removed env.* from the expression allowlist and from validation option plumbing (EnvRe / envRegex) so env.* is treated as unauthorized.
  • Updated the validation failure hint text to no longer list env.* as permitted.
  • Updated and added tests to ensure env.* (including env.X || 'literal') is rejected.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
pkg/workflow/expressions_benchmark_test.go Updates benchmark validators to match the simplified expression validation options (no EnvRe).
pkg/workflow/expression_safety_validation.go Removes env.* allowlisting and updates the user-facing “allowed expressions” hint accordingly.
pkg/workflow/expression_safety_test.go Adjusts existing expectations to treat env.* as unauthorized and adds a regression test covering env.* rejection cases.

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

Comment thread pkg/workflow/expression_safety_test.go Outdated
// env.* expressions were incorrectly allowed by the compile-time expression validator.
// These expressions are prohibited per the documented safety policy because they can
// expose environment variables (including secrets set as env vars) to AI agents.
// See: https://github.com/github/gh-aw/issues/XXXX

Copilot AI Mar 26, 2026

Copy link

Choose a reason for hiding this comment

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

The test comment links to an issue placeholder (https://github.com/github/gh-aw/issues/XXXX). Please replace XXXX with the actual issue/PR number (or remove the link) so the reference doesn’t become a dead link in main.

Suggested change
// See: https://github.com/github/gh-aw/issues/XXXX
// See internal tracking for additional context.

Copilot uses AI. Check for mistakes.
@github-actions

Copy link
Copy Markdown
Contributor

Hey @Copilot (and @pelikhan 👋) — great security fix! Closing the gap where env.* expressions silently passed compile-time validation despite being explicitly prohibited by the safety policy is exactly the kind of hardening this project needs.

The change is clean, focused, and the test coverage is thorough — TestEnvExpressionRejection covers the key variants (tokens, underscores, hyphens, mixed markdown), and the existing authorized_env_variable → unauthorized_env_variable rename plus the env variable with string default case properly close the regression surface.

One small housekeeping nit before merge: the new regression test contains a placeholder issue reference:

// See: https://github.com/github/gh-aw/issues/XXXX

If this fix addresses a tracked issue, swapping XXXX for the real issue number will make it easy for future readers (and agents) to trace the history. If there's no upstream issue, the comment can simply be removed.

Otherwise, this PR looks ready for maintainer review! 🎉


📋 Contribution guidelines check
Check Result Notes
On-topic ✅ yes Security bug fix in pkg/workflow expression validator — core to the project
Follows process ✅ yes PR authored by Copilot agent, assigned by core team member pelikhan — matches documented agentic workflow
Focused ✅ yes Exclusively removes env.* from expression allowlist across implementation, tests, and benchmarks
New deps ✅ no No changes to go.mod / go.sum
Has tests ✅ yes 67 additions to expression_safety_test.go, including dedicated TestEnvExpressionRejection regression suite
Has description ✅ yes Excellent body: problem statement, change list with specific symbols, and clear before/after CLI transcript
Diff size — +67 / −21 across 3 files (88 lines total)

Verdict: 🟢 Aligned — Quality: lgtm

Generated by Contribution Check · ◷

@github-actions

github-actions Bot commented Mar 26, 2026 •

Copy link
Copy Markdown
Contributor

🩺 Examination complete! CI Failure Doctor has delivered the diagnosis. Prescription issued! 💊

All PR checks are passing — no action needed

@github-actions

github-actions Bot commented Mar 26, 2026 •

Copy link
Copy Markdown
Contributor

🩺 Examination complete! CI Failure Doctor has delivered the diagnosis. Prescription issued! 💊

All PR checks are passing — no action needed

@pelikhan

Copy link
Copy Markdown
Collaborator

/q the checks run in ci-doctor is incorrect.

It claims all check are ok in https://github.com/github/gh-aw/actions/runs/23596732674/job/68715465435#step:9:1

But this one is failing https://github.com/github/gh-aw/actions/runs/23582442412/job/68667964598

Fix ci-doctor checks download

@github-actions

github-actions Bot commented Mar 26, 2026 •

Copy link
Copy Markdown
Contributor

🎩 Mission equipment ready! Q has optimized your workflow. Use wisely, 007! 🔫

@pelikhan

Copy link
Copy Markdown
Collaborator

The previous fix was too broad - it blocked env.GH_AW_SAFE_OUTPUTS and
other internal gh-aw system variables, breaking TestOutputLabelJobGeneration
tests. Restore a narrow allowlist for env.GH_AW_* (internal system variables)
while keeping arbitrary env.* blocked.

Also: fix dead link in TestEnvExpressionRejection comment (replace XXXX
placeholder with descriptive note), and add env.GH_AW_* allowed cases to
the regression test.

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/0728c5f9-b421-4652-b5c7-df6340b400f5

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Mar 26, 2026

Copy link
Copy Markdown
Contributor Author

@copilot fix https://github.com/github/gh-aw/actions/runs/23582442412/job/68667964598

Fixed in 09dd9c0. The previous fix was too broad — it blocked env.GH_AW_SAFE_OUTPUTS and other internal gh-aw system variables, causing TestOutputLabelJobGenerationNoAllowedLabels and TestOutputLabelJobGenerationNullConfig to fail.

The updated fix narrows the allowlist: env.GH_AW_* (internal system variables used by the gh-aw runtime, e.g. GH_AW_SAFE_OUTPUTS, GH_AW_WORKFLOW_ID_SANITIZED) remain allowed, while all other arbitrary env.* expressions (e.g. env.GITHUB_TOKEN, env.MY_SECRET) are rejected at compile time.

Copilot AI changed the title fix: reject env.* expressions in markdown at compile time fix: reject arbitrary env.* expressions in markdown at compile time Mar 26, 2026
@pelikhan pelikhan closed this Mar 26, 2026
@github-actions
github-actions Bot deleted the copilot/fix-env-expression-rejection branch April 2, 2026 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gh-aw compiler must reject env.* expressions in markdown per documented safety policy

3 participants