Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/content/docs/reference/workflow-linters.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Threat IDs refer to the [Compiler Threat Detection Specification](https://github
| `workflow-run-scope` | `CTR-021` | AW, Actions | `workflow_run` selects workflows and has a positive branch scope, not only wildcard, negated, or empty filters. |
| `dangerous-triggers` | `CTR-008`, `CTR-039` | AW, Actions | Target-trigger warnings and comment-trigger warnings correlated with actor admission and GitHub integrity filtering, including AW commands. Trusted roles, approved/merged filtering without lockdown override, or explicit GitHub disablement suppress the comment finding; literal AW target-risk acknowledgment suppresses only the target warning. |
| `secret-leak` | `CTR-017` | AW, Actions | Symbolic secrets do not reach modeled disclosure sinks. AW-only checks report missing generated execution coverage. |
| `overprovisioned-secrets` | — | AW, Actions | Whole-context secrets expressions, including `toJSON(secrets)` and wildcard projections, are rejected under strict AW policy. Selecting one secret with a literal or dynamic index is not whole-context exposure; nested selector expressions are still checked. This distinction does not establish selector trust or authorize disclosure. Remote `secrets: inherit` is rejected under strict AW policy; local inheritance warns. Actions-only and non-strict findings warn. |
| `otlp-secret-leak` | `CTR-017` | AW, Actions | Secret-tainted expressions are not exported through OTLP span or resource attributes. Hard-coded credentials and runtime values are not detected. |
| `permission-scope` | `CTR-001` | AW, Actions | Permissions avoid blanket `write-all`; OIDC does not use invalid `id-token: read`. Scoped writes and `id-token: write` are not violations. |
| `version-check` | `CTR-018` | AW | Authored source does not disable `check-for-updates`. |
Expand Down
36 changes: 21 additions & 15 deletions pkg/workflow/lint/overprovisioned_secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,7 @@ func overprovisionedSecretsDiagnostics(ctx context.Context, input Input) ([]Diag
}

blocks, err := aw.ExecutionBlocks(ctx, input.Document)
failures := []error{err}
// engine.env and sandbox.agent.env are copied into the agent execution step
// environment but are not execution blocks.
if input.Document != nil {
if engine, ok := input.Document.Frontmatter["engine"].(map[string]any); ok {
failures = append(failures, walkExpressionScalars(ctx, engine["env"], "engine.env", visit))
}
if sandbox, ok := input.Document.Frontmatter["sandbox"].(map[string]any); ok {
if agent, ok := sandbox["agent"].(map[string]any); ok {
failures = append(failures, walkExpressionScalars(ctx, agent["env"], "sandbox.agent.env", visit))
}
}
}
failures := []error{err, walkOverprovisionedSecretsEnv(ctx, input.Document, visit)}
for _, block := range blocks {
if secrets, ok := block.Fields["secrets"].(string); ok && strings.EqualFold(strings.TrimSpace(secrets), "inherit") {
if uses, ok := block.Fields["uses"].(string); ok {
Expand All @@ -124,6 +112,23 @@ func overprovisionedSecretsDiagnostics(ctx context.Context, input Input) ([]Diag
return diagnostics, errors.Join(failures...)
}

func walkOverprovisionedSecretsEnv(ctx context.Context, document *aw.Document, visit func(string, string) error) error {
// engine.env and sandbox.agent.env are copied into the agent execution step
// environment but are not execution blocks.
var failures []error
if document != nil {
if engine, ok := document.Frontmatter["engine"].(map[string]any); ok {
failures = append(failures, walkExpressionScalars(ctx, engine["env"], "engine.env", visit))
}
if sandbox, ok := document.Frontmatter["sandbox"].(map[string]any); ok {
if agent, ok := sandbox["agent"].(map[string]any); ok {
failures = append(failures, walkExpressionScalars(ctx, agent["env"], "sandbox.agent.env", visit))
}
}
}
return errors.Join(failures...)
}

// isCompilerCallWorkflowFallback reports whether job has the exact shape of a
// compiler-generated call-workflow fan-out job: call-<worker> needing
// safe_outputs, gated on call_workflow_name, and calling the local worker file.
Expand Down Expand Up @@ -174,7 +179,8 @@ func inheritDiagnostic(path, uses string) Diagnostic {
}

// materializesSecretsContext reports whether node evaluates the secrets
// context as a whole: any reference other than secrets.NAME or secrets['NAME'].
// context as a whole rather than selecting one property. Dynamic indexes select
// one secret too, but their expressions are still visited for whole-context use.
func materializesSecretsContext(node actionlint.ExprNode) bool {
found := false
actionlint.VisitExprNode(node, func(child, parent actionlint.ExprNode, entering bool) {
Expand All @@ -191,7 +197,7 @@ func materializesSecretsContext(node actionlint.ExprNode) bool {
return
}
case *actionlint.IndexAccessNode:
if _, literal := parent.Index.(*actionlint.StringNode); literal && parent.Operand == child {
if parent.Operand == child {

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.

Computed selectors are now fingerprinted for safe-update checks, redacted, and bounded by explicit workflow_call secret names. Added generated-workflow regression coverage in db5c641e.

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.

Computed secret references are now included in step secret classification, so env bindings are rejected when the step writes to GITHUB_ENV; added a regression in db5c641e.

return
}
}
Expand Down
75 changes: 68 additions & 7 deletions pkg/workflow/lint/overprovisioned_secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ func TestOverprovisionedSecretsActions(t *testing.T) {
want: map[string]Severity{"jobs.call.secrets.all": Error},
},
{
name: "dynamic index and whole context in run",
name: "dynamic index selects one secret while whole context in run is blocked",
source: contractJob + " steps:\n - with: {value: '${{ " + "secrets" + "[inputs.name] }}'}\n uses: actions/github-script@v8\n - run: |\n echo start\n echo '${{ toJson(" + "secrets" + ") }}' | jq length\n",
want: map[string]Severity{"jobs.check.steps[0].with.value": Error, "jobs.check.steps[1].run": Error},
want: map[string]Severity{"jobs.check.steps[1].run": Error},
},
{
name: "literal index and dereference are safe",
Expand Down Expand Up @@ -145,14 +145,75 @@ func TestOverprovisionedSecretsAuthored(t *testing.T) {
got[diagnostic.Path] = diagnostic.Severity
}
assert.Equal(t, map[string]Severity{
"jobs.remote.secrets": Error,
"jobs.local.secrets": Warning,
"steps[0].env.ALL": Error,
"engine.env.ALL": Error,
"sandbox.agent.env.PICK": Error,
"jobs.remote.secrets": Error,
"jobs.local.secrets": Warning,
"steps[0].env.ALL": Error,
"engine.env.ALL": Error,

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.

[/tdd] This removes the only assertion covering whole-context exposure under sandbox.agent.env. The input still uses PICK as a dynamic index, which is now correctly allowed, so nothing exercises the sandbox branch of walkOverprovisionedSecretsEnv. Dropping that branch would still pass CI.

💡 Suggested test

Add a whole-context entry such as ALL: '${{ toJSON(secrets) }}' under sandbox.agent.env in the input, and expect sandbox.agent.env.ALL to be Error in the map. Keep PICK as the dynamic-index case that should pass.

@copilot please address this.

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.

Added the sandbox whole-context regression assertion in 3c4e3c96.

}, got)
}

func TestOverprovisionedSecretsSelectors(t *testing.T) {
t.Parallel()
tests := []struct {
name string
expression string
blocked bool
}{
{
name: "repository mapping selects one secret",
expression: "vars.GH_AW_GITHUB_AUTH_MODE == 'pat' && secrets[fromJSON(vars.GH_AW_GITHUB_READ_PAT_REPOSITORIES || '{}')[github.repository]] || ''",
},
{
name: "serialization of a selected secret",
expression: "toJSON(secrets[inputs.name])",
},
{
name: "literal wildcard name selects one secret",
expression: "secrets['*']",
},
{
name: "whole context inside selector",
expression: "secrets[fromJSON(toJSON(secrets))[github.repository]]",
blocked: true,
},
{
name: "whole context used as selector",
expression: "secrets[secrets]",
blocked: true,
},
{
name: "wildcard projection",
expression: "toJSON(secrets.*)",
blocked: true,
},
{
name: "whole context alongside selection",
expression: "format('{0}{1}', secrets[inputs.name], toJSON(secrets))",
blocked: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
field := " env:\n TOKEN: ${{ " + tt.expression + " }}\n"
workflow, err := actions.Parse([]byte(contractJob + field + contractSafeSteps))
require.NoError(t, err)
document, err := aw.Parse("---\non: issues\njobs:\n check:\n runs-on: ubuntu-latest\n" + field + contractSafeSteps + "---\nPrompt.\n")
require.NoError(t, err)
for _, input := range []Input{{Workflow: workflow, Document: document}, {Document: document}} {
diagnostics := runOverprovisionedSecrets(t, input)
if tt.blocked {
require.Len(t, diagnostics, 1)
assert.Equal(t, Error, diagnostics[0].Severity)
assert.Equal(t, "jobs.check.env.TOKEN", diagnostics[0].Path)
} else {
assert.Empty(t, diagnostics)
}
}
})
}
}

func TestOverprovisionedSecretsCancellation(t *testing.T) {
t.Parallel()
workflow, err := actions.Parse([]byte(contractJob + contractSafeSteps))
Expand Down
Loading