Skip to content

Add safe-output-credentials lint rule - #79268

Merged
pelikhan merged 7 commits into
mainfrom
pelikhan/safe-outputs-write-token-guards
Nov 19, 2026
Merged

pelikhan merged 7 commits into
mainfrom
pelikhan/safe-outputs-write-token-guards

Conversation

@pelikhan

Copy link
Copy Markdown
Collaborator

Custom safe-outputs.steps are trusted, but they run inside the safe_outputs job after the compiler has minted write-scoped GitHub App tokens and configured persisted git credentials for the safe-output handlers. A well-meaning step can accidentally reuse or disturb those credentials. This adds an AW lint rule (gh aw lint) to catch the common accidental misuses.

What safe-output-credentials flags

For each authored safe-outputs.steps[N]:

  • Minted token reuse: references to compiler-minted steps.*-app-token outputs (dot or bracket form) in any step field, unless the token step id is declared by the user's own steps.
  • Environment mutation: writes to $GITHUB_ENV / $GITHUB_PATH, or core.exportVariable / core.addPath in run or with.script. These change the environment of later handler steps that hold write tokens.
  • Credential-persisting checkout: actions/checkout without persist-credentials: false, which would replace the workspace and git credentials prepared for handlers.
  • Tampering with handler inputs: write operations (>/>>, tee, sed -i, rm, truncate, mv/cp destination) on $GH_AW_AGENT_OUTPUT, $GH_AW_SAFE_OUTPUTS, /tmp/gh-aw/, or ${RUNNER_TEMP}/gh-aw/. Handlers apply these after threat detection.

Severity is error in strict mode and warning with strict: false (via sourcePolicySeverity). Diagnostics are per step with precise paths (e.g. safe-outputs.steps[0].env) and value-free messages.

Notes for reviewers

  • This is a lint rule only; no compiler behavior changes. I prototyped it as a compiler validator first but moved it to pkg/workflow/lint per the request.
  • No CTR-* threat ID is assigned, since none currently covers this.
  • Detection is lexical and intentionally conservative (reads from /tmp/gh-aw and copies from it are allowed).
  • No existing workflow in .github/workflows triggers the rule.

Testing

  • New safe_output_credentials_test.go policy tests (19 cases), plus contract, spec, default-registry, value-free failure, and CLI lint test entries.
  • make agent-report-progress passes.

Docs: added a row to the workflow-linters rule table and a paragraph in the safe-outputs reference.

pelikhan and others added 2 commits November 19, 2026 04:39
Flag authored safe-outputs.steps that use compiler-minted App tokens,
write GITHUB_ENV/GITHUB_PATH, check out with persisted credentials, or
modify agent output/patch files under /tmp/gh-aw. Error in strict mode,
warning otherwise.

Co-authored-by: Copilot App <[email protected]>
Add per-finding threat IDs via Rule.FindingThreatRuleIDs (registry-owned),
update the compiler threat spec to 1.0.104 with catalog rules, implementation
and lint mappings, conformance tests T-CTR-050–T-CTR-053, compliance map,
changelog, and docs.

Co-authored-by: Copilot App <[email protected]>
@pelikhan
pelikhan marked this pull request as ready for review November 19, 2026 12:51
Copilot AI adaptive review requested due to automatic review settings November 19, 2026 12:51
@github-actions

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer is reviewing this pull request using Matt Pocock's engineering skills...

@github-actions

Copy link
Copy Markdown
Contributor

🚀 PR Specification Reviewer has started processing this pull request

@github-actions

Copy link
Copy Markdown
Contributor

🔎 PR Code Quality Reviewer is reviewing code quality for this pull request...

@github-actions

Copy link
Copy Markdown
Contributor

🔍 Design Decision Gate 🏗️ is checking for design decision records on this pull request...

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Warning

Threat detection engine error

Threat detection could not complete its analysis due to a tooling error. This is not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs to troubleshoot the error.

Ponytail Reviewer

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated by Ponytail Reviewer for #79268 · codex · routed: gpt61 medium · ~5 AIC · ⊞ 185 · ◷

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Warning

Threat detection engine error

Threat detection could not complete its analysis due to a tooling error. This is not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs to troubleshoot the error.

Test Quality Sentinel

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

🧪 Test quality analysis by Test Quality Sentinel · copilot · routed: haiku55 xhigh · ~1 AIC · ⊞ 7.2K · ◷

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

Unresolved lint-rule defects reject valid strict workflows and miss unsafe operations, with additional undocumented compilation failures and shared-slice isolation issues.

9 open issues
What changed in this PR

Adds safe-output-credentials to gh-aw’s default workflow linter to catch accidental misuse of write credentials by authored safe-output steps.

Changes:

  • Checks token reuse, environment mutation, credential-persisting checkouts, and handler-input writes.
  • Adds per-finding threat IDs and exposes them in CLI rule listings.
  • Extends policy tests, reference documentation, and the threat specification.
File Description
specs/​compiler-threat-detection-spec.md Defines CTR-035–038 and per-finding threat mappings.
specs/​compiler-threat-detection-compliance/​README.md Maps the new threats to conformance tests.
specs/​compiler-threat-detection-changelog.md Records specification version 1.0.104.
pkg/​workflow/​lint/​threat_policy_test.go Adds malformed-input and value-free diagnostic cases.
pkg/​workflow/​lint/​spec_test.go Includes the new public rule constructor.
pkg/​workflow/​lint/​safe_output_credentials.go Implements the four credential-related checks.
pkg/​workflow/​lint/​safe_output_credentials_test.go Exercises detection, exemptions, and severity.
pkg/​workflow/​lint/​rule_contract_test.go Adds rule-contract and per-finding threat assertions.
pkg/​workflow/​lint/​README.md Lists the new rule constructor.
pkg/​workflow/​lint/​lint.go Registers the rule and supports per-finding threat IDs.
pkg/​workflow/​lint/​lint_test.go Updates the expected default rule list.
pkg/​cli/​lint_workflow_test.go Adds CLI coverage for the rule.
pkg/​cli/​lint_command.go Displays multiple threat IDs in rule listings.
docs/​src/​content/​docs/​reference/​workflow-linters.md Documents the rule and strict-mode severity.
docs/​src/​content/​docs/​reference/​safe-outputs.md Describes credential-misuse checks for custom steps.

Review effort: Max (adaptive)

Comment thread pkg/workflow/lint/lint.go
if rule.ThreatRuleID != "" && !threatRuleIDPattern.MatchString(rule.ThreatRuleID) {
return nil, fmt.Errorf("lint rule %q requires a compiler threat ID in CTR-NNN form", rule.ID)
}
for _, id := range rule.FindingThreatRuleIDs {

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.

Fixed in 237f6c0: registration and retrieval clone the nested threat ID slices.

Comment thread pkg/workflow/lint/lint.go
PullRequestTargetRolesRule(),
UntrustedRolesDetectionRule(),
SafeOutputShellExpansionRule(),
SafeOutputCredentialsRule(),

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.

Fixed in 237f6c0: compilation excludes this rule, with a regression test.

}
}

const safeOutputInputPath = `["']?(?:\$\{?GH_AW_AGENT_OUTPUT\}?|\$\{?GH_AW_SAFE_OUTPUTS\}?|/tmp/gh-aw/|\$\{?RUNNER_TEMP\}?/gh-aw/|\$\{\{\s*runner\.temp\s*\}\}/gh-aw/)`

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.

Fixed in 237f6c0: directory roots and descendants are matched without matching similarly named paths.

const safeOutputInputPath = `["']?(?:\$\{?GH_AW_AGENT_OUTPUT\}?|\$\{?GH_AW_SAFE_OUTPUTS\}?|/tmp/gh-aw/|\$\{?RUNNER_TEMP\}?/gh-aw/|\$\{\{\s*runner\.temp\s*\}\}/gh-aw/)`

var (
safeOutputMintedTokenRE = regexp.MustCompile(`(?i)\bsteps\s*(?:\.\s*([A-Za-z0-9_-]+-app-token)\b|\[\s*['"]([A-Za-z0-9_-]+-app-token)['"]\s*\])`)

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.

Fixed in 237f6c0: full step IDs, including suffixes and indexed IDs, are checked.

const safeOutputInputPath = `["']?(?:\$\{?GH_AW_AGENT_OUTPUT\}?|\$\{?GH_AW_SAFE_OUTPUTS\}?|/tmp/gh-aw/|\$\{?RUNNER_TEMP\}?/gh-aw/|\$\{\{\s*runner\.temp\s*\}\}/gh-aw/)`

var (
safeOutputMintedTokenRE = regexp.MustCompile(`(?i)\bsteps\s*(?:\.\s*([A-Za-z0-9_-]+-app-token)\b|\[\s*['"]([A-Za-z0-9_-]+-app-token)['"]\s*\])`)

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.

Fixed in 237f6c0: outcome and conclusion reads are exempted and covered by a regression test.


var (
safeOutputMintedTokenRE = regexp.MustCompile(`(?i)\bsteps\s*(?:\.\s*([A-Za-z0-9_-]+-app-token)\b|\[\s*['"]([A-Za-z0-9_-]+-app-token)['"]\s*\])`)
safeOutputEnvFileRE = regexp.MustCompile(`\$\{?(?:GITHUB_ENV|GITHUB_PATH)\b`)

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.

Fixed in 237f6c0: write destinations are checked across shell, PowerShell and Actions-context forms; reads are permitted.

Comment on lines +55 to +62
declared := make(map[string]struct{})
for _, raw := range steps {
if step, ok := raw.(map[string]any); ok {
if id, ok := step["id"].(string); ok {
declared[strings.ToLower(id)] = struct{}{}
}
}
}

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.

Fixed in 237f6c0: authored pre-step and setup-step IDs, including the job alias, are included.

return "", false
}
uses = strings.TrimSpace(uses)
if uses != "actions/checkout" && !strings.HasPrefix(uses, "actions/checkout@") {

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.

Fixed in 237f6c0 using the shared action and boolean parsing helpers.

Comment on lines +169 to +175
for _, command := range strings.FieldsFunc(line, func(r rune) bool { return r == ';' || r == '|' || r == '&' }) {
if safeOutputTamperRE.MatchString(command) {
return true
}
if safeOutputMoveCopyRE.MatchString(command) {
fields := strings.Fields(command)
if len(fields) > 2 && slices.ContainsFunc(fields[len(fields)-1:], safeOutputInputTargetRE.MatchString) {

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.

Fixed in 237f6c0: shell command write operands are inspected, with regression cases for the reported examples.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

Warning

Threat detection engine error

Threat detection could not complete its analysis due to a tooling error. This is not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs to troubleshoot the error.

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Review (pkg/workflow/lint/lint.go:121): address unresolved feedback - Review comment
  3. Review (pkg/workflow/lint/lint.go:261): address unresolved feedback - Review comment
  4. Review (pkg/workflow/lint/safe_output_credentials.go:25): address unresolved feedback - Review comment
  5. Review (pkg/workflow/lint/safe_output_credentials.go:28): address unresolved feedback - Review comment
  6. Review (pkg/workflow/lint/safe_output_credentials.go:28): address unresolved feedback - Review comment
  7. Review (pkg/workflow/lint/safe_output_credentials.go:29): address unresolved feedback - Review comment
  8. Review (pkg/workflow/lint/safe_output_credentials.go:62): address unresolved feedback - Review comment
  9. Review (pkg/workflow/lint/safe_output_credentials.go:148): address unresolved feedback - Review comment
  10. Review (pkg/workflow/lint/safe_output_credentials.go:175): address unresolved feedback - Review comment

Keeping the changes focused; human review and CI get the final taste test. No merging or CI triggering.

Structured data
{
  "completed_task": 0,
  "head": "2b7002c58ab2eb00c9c8cbf2c7585092d0911f17",
  "kind": "requested",
  "schema_version": "1",
  "state": "bc47e247bda15f3e20638adcf3b358fe5acf89cd6bb5682081ed118c9685fc57",
  "work": [
    "38e84294bbdaccf5100894c54662be1f8db12f2e84340bebe73828999670f71b",
    "3a48c5cfdc46cc3b15fa87dfc2b96661c195bb4577df61c2766f356424449376",
    "608bcba1ae40395c4b39dd69c4132a565f9f6307229076673a346062980ffde1",
    "7be24eb78cf4bea4ae65dd4573a5705fa3341f343ce6842e9305b95ff15cb4ed",
    "bd04108f4c44bde7c656b7a621361977f91afbfa02d6ff29b512b371868861e2",
    "c32552bd3fd8bedb5a2073ed554c2db5e42fe56bf909d9e802d2baec0d7664c2",
    "c79412d9f867da383c13684ef5822d56d589fd4f0a7d19372f87912de82a3276",
    "e044d139036157437553af29b19e5243b75a7f40a9ea84a22ebb33421492bc6f",
    "e92fd48373a36772c76ec27666615939972af6078373d12d7fb0f3d28c1981d3"
  ],
  "workflow": "pr-sous-chef"
}

Generated by 👨🍳 PR Sous Chef · pi · routed: haiku55 xhigh · ~4 AIC · ⊞ 7K · ◷
Comment /souschef to run again

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@pelikhan

Copy link
Copy Markdown
Collaborator Author

@copilot fix ci failures

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@pelikhan
pelikhan merged commit 467c01c into main Nov 19, 2026
124 checks passed
@pelikhan
pelikhan deleted the pelikhan/safe-outputs-write-token-guards branch November 19, 2026 17:08

Copilot AI commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

[!WARNING]
Threat detection engine error
...

Merged main in 4673249 and replied to the review threads addressed by 237f6c0. Recompilation was blocked by npm registry DNS resolution.

@copilot fix ci failures

Fixed the failing tolowerequalfold check in 34f9346; the targeted test and analyzer pass. The final gate also reports separate existing custom-linter findings from 237f6c0.

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.

4 participants