Skip to content

Commit 080a35a

Browse files
Copilotpelikhan
andauthored
fix: exempt secrets.GITHUB_TOKEN from steps validation and recompile workflows
GITHUB_TOKEN is GitHub's built-in runner token, not a user-defined secret. Exempt it from the steps/post-steps secrets validation so existing workflows using `GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}` in custom steps continue to compile. Add filterBuiltinTokens helper and update tests accordingly. Recompile all 184 workflow lock files with the updated binary. Agent-Logs-Url: https://github.com/github/gh-aw/sessions/a6405a5b-b8da-42ad-9724-cd95d533d211 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent 7dacab3 commit 080a35a

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

pkg/workflow/strict_mode_steps_validation.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ func (c *Compiler) validateStepsSectionSecrets(frontmatter map[string]any, secti
5353
secretRefs = append(secretRefs, refs...)
5454
}
5555

56+
// Filter out the built-in GITHUB_TOKEN: it is already present in every runner
57+
// environment and is not a user-defined secret that could be accidentally leaked.
58+
secretRefs = filterBuiltinTokens(secretRefs)
59+
5660
if len(secretRefs) == 0 {
5761
strictModeValidationLog.Printf("No secrets found in %s section", sectionName)
5862
return nil
@@ -117,3 +121,17 @@ func deduplicateStringSlice(in []string) []string {
117121
}
118122
return out
119123
}
124+
125+
// filterBuiltinTokens removes secret expressions that reference GitHub's built-in
126+
// GITHUB_TOKEN from the list. GITHUB_TOKEN is automatically provided by the runner
127+
// environment and is not a user-defined secret; it therefore does not represent an
128+
// accidental leak into the agent job.
129+
func filterBuiltinTokens(refs []string) []string {
130+
out := refs[:0:0]
131+
for _, ref := range refs {
132+
if !strings.Contains(ref, "secrets.GITHUB_TOKEN") {
133+
out = append(out, ref)
134+
}
135+
}
136+
return out
137+
}

pkg/workflow/strict_mode_steps_validation_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,22 @@ func TestValidateStepsSecrets(t *testing.T) {
3838
strictMode: true,
3939
expectError: false,
4040
},
41+
{
42+
name: "steps with GITHUB_TOKEN are allowed (built-in token is exempt)",
43+
frontmatter: map[string]any{
44+
"steps": []any{
45+
map[string]any{
46+
"name": "Use GH CLI",
47+
"env": map[string]any{
48+
"GH_TOKEN": "${{ secrets.GITHUB_TOKEN }}",
49+
},
50+
"run": "gh issue list",
51+
},
52+
},
53+
},
54+
strictMode: true,
55+
expectError: false,
56+
},
4157
{
4258
name: "post-steps without secrets is allowed",
4359
frontmatter: map[string]any{
@@ -89,7 +105,7 @@ func TestValidateStepsSecrets(t *testing.T) {
89105
map[string]any{
90106
"uses": "some/action@v1",
91107
"with": map[string]any{
92-
"token": "${{ secrets.GITHUB_TOKEN }}",
108+
"token": "${{ secrets.MY_API_TOKEN }}",
93109
},
94110
},
95111
},

0 commit comments

Comments
 (0)