5555// seen without the network. Resolve both from the same lookup when bumping
5656// (the `release` skill has the command).
5757//
58- // ⚠️ Local `./…` actions and reusable workflows are skipped, not traced: the
59- // remote `uses:` INSIDE one runs under its caller's credentials but is not
60- // associated with the caller here, and composite-action files are not read at
61- // all. None exists in this repo; adding the first one to a credentialed job
62- // means extending this guard to follow it, or it is a silent bypass.
58+ // ⚠️ Local `./…` actions and reusable workflows are REFUSED in a credentialed
59+ // job, not skipped. The remote `uses:` INSIDE one runs under its caller's
60+ // credentials, and this guard reads neither composite-action files nor called
61+ // workflows, so a local definition could carry a tag-pinned action past it.
62+ // None exists in this repo. Adding the first one to a credentialed job means
63+ // teaching this guard to follow it; until then it is a finding (the Inspector's
64+ // guard skips them with a warning, which leaves the bypass open).
6365
6466import { readdirSync , readFileSync } from "node:fs" ;
6567import path from "node:path" ;
@@ -77,7 +79,14 @@ const repoRoot = path.resolve(
7779// index included, still reads as a secret.
7880const DEFAULT_TOKEN =
7981 / \b s e c r e t s \s * (?: \. \s * G I T H U B _ T O K E N \b | \[ \s * ( [ ' " ] ) G I T H U B _ T O K E N \1\s * \] ) / g;
80- const EXPRESSION = / \$ \{ \{ ( [ \s \S ] * ?) \} \} / g;
82+ // Where the first expression in a string opens. Everything from there on is
83+ // searched, rather than each `${{ … }}` body: finding where an expression ENDS
84+ // needs a parser, since a quoted string inside one may itself contain ` }}`
85+ // (`${{ format('}}{0}', secrets.X) }}`), and a body cut short at that point
86+ // hides the secret after it. Searching the tail cannot be fooled that way. It
87+ // can over-count a string that mentions `secrets` in prose after an
88+ // expression, which errs toward requiring a pin.
89+ const EXPRESSION_OPEN = "${{" ;
8190
8291/** Does this `permissions:` value let the job mint a token or push a package? */
8392function mints ( permissions ) {
@@ -104,11 +113,13 @@ function handedSecret(job, inherited) {
104113 // `inherit` hands over every secret with no expression to scan. A mapping
105114 // is scanned below with everything else.
106115 if ( job . secrets === "inherit" ) return true ;
107- return stringsIn ( [ job , inherited ] ) . some ( ( text ) =>
108- [ ...text . matchAll ( EXPRESSION ) ] . some ( ( [ , body ] ) =>
109- / \b s e c r e t s \b / . test ( body . replace ( DEFAULT_TOKEN , "" ) ) ,
110- ) ,
111- ) ;
116+ return stringsIn ( [ job , inherited ] ) . some ( ( text ) => {
117+ const open = text . indexOf ( EXPRESSION_OPEN ) ;
118+ return (
119+ open !== - 1 &&
120+ / \b s e c r e t s \b / . test ( text . slice ( open ) . replace ( DEFAULT_TOKEN , "" ) )
121+ ) ;
122+ } ) ;
112123}
113124
114125const needsOf = ( job ) =>
@@ -206,8 +217,8 @@ export function credentialedJobs(yaml, file) {
206217/**
207218 * Every `uses:` in a credentialed job that is not a 40-hex SHA followed by a
208219 * `# vX.Y.Z` comment: each step's, and the job's own when it calls a reusable
209- * workflow, whose ref is just as mutable. Local (`./…`) actions and workflows
210- * are repository code, not a ref .
220+ * workflow, whose ref is just as mutable. A local (`./…`) action or workflow
221+ * is a finding too: what it runs is not read here (see the header) .
211222 *
212223 * A YAML alias anywhere in a credentialed job is itself a finding. Resolving it
213224 * here would accept a pin that a line-oriented reader (a reviewer, or a sweep
@@ -246,9 +257,8 @@ export function unpinnedRefs(yaml, file) {
246257 for ( const node of nodes ) {
247258 if ( ! isScalar ( node ) || typeof node . value !== "string" ) continue ;
248259 const uses = node . value ;
249- if ( uses . startsWith ( "./" ) ) continue ;
250- // A value with no `@ref` at all, or a container image, is not pinned
251- // either: `parseUses` returns null for both and `isPinned` rejects it.
260+ // A local definition, a value with no `@ref` at all, and a container
261+ // image are not pins either: `parseUses` returns null for all three.
252262 if ( parseUses ( uses ) === null || ! isPinned ( uses , node . comment ) )
253263 problems . push ( { job : name , uses } ) ;
254264 }
@@ -274,6 +284,8 @@ export function main(root = repoRoot) {
274284 "\n\nA job holding `id-token`/`packages: write`, a non-default secret, or building an" +
275285 "\nartifact such a job consumes runs only immutable refs. Pin each as" +
276286 "\n uses: owner/repo@<40-hex sha> # vX.Y.Z" +
287+ "\nA local `./…` action or workflow is refused there as well: this guard does not" +
288+ "\nread what it runs. Inline its steps, or extend the guard to follow it." +
277289 "\nresolving the SHA and the exact release from the same tag lookup. The comment" +
278290 "\nnames the release the SHA came from, for a reviewer and for the dependency sweep." ,
279291 ) ;
0 commit comments