@@ -67,7 +67,13 @@ function requireArg(args, name) {
6767 return value ;
6868}
6969
70- export function sanitizedEnvironment ( extra = { } ) {
70+ export function sanitizedEnvironment ( extra = { } , { allowGitHubToken = false } = { } ) {
71+ if ( 'SQUAD_GH_AW_E2E_TOKEN' in extra ) {
72+ throw new Error ( 'SQUAD_GH_AW_E2E_TOKEN must never be passed to a child process.' ) ;
73+ }
74+ if ( 'GH_TOKEN' in extra && ! allowGitHubToken ) {
75+ throw new Error ( 'GH_TOKEN requires an explicitly privileged or source-read child process.' ) ;
76+ }
7177 const env = Object . fromEntries (
7278 SAFE_CHILD_ENV . filter ( ( key ) => process . env [ key ] !== undefined )
7379 . map ( ( key ) => [ key , process . env [ key ] ] ) ,
@@ -79,7 +85,7 @@ export function runChild(command, args, options = {}) {
7985 const result = spawnSync ( command , args , {
8086 cwd : options . cwd ,
8187 encoding : 'utf8' ,
82- env : sanitizedEnvironment ( options . env ) ,
88+ env : sanitizedEnvironment ( options . env , { allowGitHubToken : options . allowGitHubToken === true } ) ,
8389 stdio : options . capture === false ? 'inherit' : 'pipe' ,
8490 timeout : options . timeout ?? 120_000 ,
8591 } ) ;
@@ -95,7 +101,11 @@ export function runChild(command, args, options = {}) {
95101function privileged ( command , args , options = { } ) {
96102 const token = process . env . GH_TOKEN ;
97103 if ( ! token ) throw new Error ( 'GH_TOKEN is required for the trusted hosted journey.' ) ;
98- return runChild ( command , args , { ...options , env : { ...options . env , GH_TOKEN : token } } ) ;
104+ return runChild ( command , args , {
105+ ...options ,
106+ allowGitHubToken : true ,
107+ env : { ...options . env , GH_TOKEN : token } ,
108+ } ) ;
99109}
100110
101111function ghJson ( args , options = { } ) {
@@ -106,7 +116,7 @@ function ghJson(args, options = {}) {
106116function sourceGhJson ( args ) {
107117 const token = process . env . SOURCE_READ_TOKEN ?? process . env . GH_TOKEN ;
108118 if ( ! token ) throw new Error ( 'A source repository read token is required.' ) ;
109- const output = runChild ( 'gh' , args , { env : { GH_TOKEN : token } } ) ;
119+ const output = runChild ( 'gh' , args , { allowGitHubToken : true , env : { GH_TOKEN : token } } ) ;
110120 return output ? JSON . parse ( output ) : null ;
111121}
112122
@@ -339,10 +349,14 @@ function hosted(args, repositoryRoot) {
339349
340350 const sourceReadToken = process . env . SOURCE_READ_TOKEN ;
341351 if ( ! sourceReadToken ) throw new Error ( 'SOURCE_READ_TOKEN is required for immutable package retrieval.' ) ;
352+ if ( sourceReadToken === process . env . GH_TOKEN ) {
353+ throw new Error ( 'SOURCE_READ_TOKEN must not reuse the mutation-capable GH_TOKEN.' ) ;
354+ }
342355 runChild ( 'gh' , [ 'aw' , 'add' , `${ PACKAGE_NAME } @${ sourceSha } ` ] , {
343356 cwd : checkout ,
344357 capture : false ,
345358 timeout : 600_000 ,
359+ allowGitHubToken : true ,
346360 env : { GH_TOKEN : sourceReadToken } ,
347361 } ) ;
348362 runChild ( 'node' , [ '.github/workflows/shared/squad-install-verifier.mjs' , '--materialize-runtime' ] , {
0 commit comments