@@ -48,6 +48,7 @@ type PullRequestEventTransition struct {
4848type SafeUpdateOptions struct {
4949 Manifest * GHAWManifest
5050 SecretNames []string
51+ DynamicSecretReferences []string
5152 ActionRefs []string
5253 CurrentRedirect string
5354 PullRequestTransition PullRequestEventTransition
@@ -84,12 +85,13 @@ func EnforceSafeUpdate(options SafeUpdateOptions) error {
8485 }
8586
8687 secretViolations := collectSecretViolations (options .Manifest , options .SecretNames )
88+ dynamicSecretViolations := collectDynamicSecretViolations (options .Manifest , options .DynamicSecretReferences )
8789 addedActions , removedActions := collectActionViolations (options .Manifest , options .ActionRefs )
8890 addedRedirect , removedRedirect := collectRedirectViolations (options .Manifest , options .CurrentRedirect )
8991 memoryValidationScriptChanges := collectMemoryValidationScriptChanges (options .Manifest , options .MemoryValidationScripts )
9092 pullRequestTargetEscalation := hasPullRequestTargetEscalation (options .PullRequestTransition .OldHasPullRequest , options .PullRequestTransition .OldHasPullRequestTarget , options .PullRequestTransition .CurrentHasPullRequest , options .PullRequestTransition .CurrentHasPullRequestTarget )
9193
92- if len (secretViolations ) == 0 && len (addedActions ) == 0 && len (removedActions ) == 0 && addedRedirect == "" && removedRedirect == "" && len (memoryValidationScriptChanges ) == 0 && ! pullRequestTargetEscalation {
94+ if len (secretViolations ) == 0 && len (dynamicSecretViolations ) == 0 && len ( addedActions ) == 0 && len (removedActions ) == 0 && addedRedirect == "" && removedRedirect == "" && len (memoryValidationScriptChanges ) == 0 && ! pullRequestTargetEscalation {
9395 safeUpdateLog .Printf ("Safe update check passed (%d secret(s), %d action(s) verified)" ,
9496 len (options .SecretNames ), len (options .ActionRefs ))
9597 return nil
@@ -121,7 +123,7 @@ func EnforceSafeUpdate(options SafeUpdateOptions) error {
121123 safeUpdateLog .Print ("Safe update violation: pull_request event converted to pull_request_target" )
122124 }
123125
124- return buildSafeUpdateError (secretViolations , addedActions , removedActions , addedRedirect , removedRedirect , pullRequestTargetEscalation , memoryValidationScriptChanges )
126+ return buildSafeUpdateError (secretViolations , addedActions , removedActions , addedRedirect , removedRedirect , pullRequestTargetEscalation , memoryValidationScriptChanges , dynamicSecretViolations )
125127}
126128
127129func hasPullRequestTargetEscalation (oldHasPullRequest bool , oldHasPullRequestTarget bool , currentHasPullRequest bool , currentHasPullRequestTarget bool ) bool {
@@ -193,6 +195,20 @@ func collectSecretViolations(manifest *GHAWManifest, secretNames []string) []str
193195 return violations
194196}
195197
198+ func collectDynamicSecretViolations (manifest * GHAWManifest , references []string ) []string {
199+ known := make (map [string ]struct {}, len (manifest .DynamicSecretReferences ))
200+ for _ , reference := range manifest .DynamicSecretReferences {
201+ known [reference ] = struct {}{}
202+ }
203+ var violations []string
204+ for _ , reference := range normalizeDynamicSecretReferences (references ) {
205+ if ! setutil .Contains (known , reference ) {
206+ violations = append (violations , reference )
207+ }
208+ }
209+ return violations
210+ }
211+
196212// githubActionsOrg is the owner whose actions are always trusted and never flagged
197213// as unapproved additions, regardless of what was recorded in the manifest.
198214const githubActionsOrg = "actions"
@@ -328,14 +344,22 @@ func collectMemoryValidationScriptChanges(manifest *GHAWManifest, current []GHAW
328344
329345// buildSafeUpdateError creates a clear, structured error message that names the
330346// offending secrets, actions, and redirects and tells the user how to remediate.
331- func buildSafeUpdateError (secretViolations , addedActions , removedActions []string , addedRedirect , removedRedirect string , hasPullRequestTargetEscalation bool , memoryValidationScriptChanges []string ) error {
347+ func buildSafeUpdateError (secretViolations , addedActions , removedActions []string , addedRedirect , removedRedirect string , hasPullRequestTargetEscalation bool , memoryValidationScriptChanges []string , dynamicSecretViolations ... [] string ) error {
332348 var sb strings.Builder
333349 sb .WriteString ("safe update mode detected unapproved changes\n " )
350+ var computedSecretViolations []string
351+ if len (dynamicSecretViolations ) > 0 {
352+ computedSecretViolations = dynamicSecretViolations [0 ]
353+ }
334354
335355 if len (secretViolations ) > 0 {
336356 sb .WriteString ("\n New restricted secret(s):\n - " )
337357 sb .WriteString (strings .Join (secretViolations , "\n - " ))
338358 }
359+ if len (computedSecretViolations ) > 0 {
360+ sb .WriteString ("\n New computed secret selector(s) (SHA-256):\n - " )
361+ sb .WriteString (strings .Join (computedSecretViolations , "\n - " ))
362+ }
339363 if len (addedActions ) > 0 {
340364 sb .WriteString ("\n New unapproved action(s):\n - " )
341365 sb .WriteString (strings .Join (addedActions , "\n - " ))
0 commit comments