@@ -398,6 +398,11 @@ export async function runEnforcePrTarget(
398398 const outputs : { name : string ; value : unknown } [ ] = [ ] ;
399399 const states = new Map < string , unknown > ( ) ;
400400 const failOn = new Set ( options . failOn ?? [ ] ) ;
401+ if ( options . failPermissionLookup ) {
402+ // Route through `record` so the call appears in the recording even when it
403+ // rejects (same semantics as `failOn`).
404+ failOn . add ( "repos.getCollaboratorPermissionLevel" ) ;
405+ }
401406 const failStatus = options . failStatus ?? 500 ;
402407
403408 const pr = {
@@ -452,19 +457,21 @@ export async function runEnforcePrTarget(
452457
453458 const nodeRequire = createRequire ( path . join ( process . cwd ( ) , "package.json" ) ) ;
454459 const scriptsRoot = path . resolve ( process . cwd ( ) , ".github" , "scripts" ) ;
460+ /** Bare modules the workflow script may load (see enforce-pr-target.yml). */
461+ const ALLOWED_MODULES = new Set ( [ "path" , "node:path" ] ) ;
455462
456463 function scopedRequire ( id : string ) {
457464 calls . push ( { method : "require" , args : [ id ] } ) ;
458- const isRelative = id . startsWith ( "." ) || id . startsWith ( "/" ) || path . isAbsolute ( id ) ;
459- if ( ! isRelative ) {
465+ const isPathLike = id . startsWith ( "." ) || path . isAbsolute ( id ) ;
466+ if ( ! isPathLike ) {
467+ if ( ! ALLOWED_MODULES . has ( id ) ) {
468+ throw new Error ( `the script must not require ${ id } ` ) ;
469+ }
460470 return nodeRequire ( id ) ;
461471 }
462- const resolved = path . isAbsolute ( id ) ? id : path . resolve ( process . cwd ( ) , id ) ;
472+ const resolved = path . isAbsolute ( id ) ? path . resolve ( id ) : path . resolve ( process . cwd ( ) , id ) ;
463473 if ( ! resolved . startsWith ( scriptsRoot + path . sep ) && resolved !== scriptsRoot ) {
464- const norm = resolved . replace ( / \\ / g, "/" ) ;
465- if ( ! norm . includes ( "/.github/scripts/" ) ) {
466- throw new Error ( `the script must not require ${ id } ` ) ;
467- }
474+ throw new Error ( `the script must not require ${ id } ` ) ;
468475 }
469476 return nodeRequire ( resolved ) ;
470477 }
@@ -494,14 +501,10 @@ export async function runEnforcePrTarget(
494501 updateComment : ( args : unknown ) => respond ( "issues.updateComment" , args , { id : 7 } ) ,
495502 } ,
496503 repos : {
497- getCollaboratorPermissionLevel : ( args : unknown ) => {
498- if ( options . failPermissionLookup ) {
499- return Promise . reject ( octokitError ( "repos.getCollaboratorPermissionLevel" , failStatus ) ) ;
500- }
501- return respond ( "repos.getCollaboratorPermissionLevel" , args , {
504+ getCollaboratorPermissionLevel : ( args : unknown ) =>
505+ respond ( "repos.getCollaboratorPermissionLevel" , args , {
502506 permission : options . authorPermission ?? "read" ,
503- } ) ;
504- } ,
507+ } ) ,
505508 compareCommitsWithBasehead : ( args : unknown ) => {
506509 const basehead = String ( ( args as { basehead ?: string } ) ?. basehead ?? "" ) ;
507510 return respond ( "repos.compareCommitsWithBasehead" , args , compareResult ( basehead ) ) ;
0 commit comments