@@ -243,16 +243,12 @@ module.exports = {
243243 packageResolver = _ . get ( this , 'options.script.packageResolver' ) ,
244244
245245 vaultSecrets = payload . context . vaultSecrets ,
246- allowVaultAccess = _ . get ( vaultSecrets , '_.allowScriptAccess' ) ,
246+ // Do not assign any initial value here as it will be used
247+ // to determine if the vault access check was done or not
248+ hasVaultAccess ,
247249
248250 events ;
249251
250- // Explicitly enable tracking for vault secrets here as this will
251- // not be sent to sandbox who otherwise takes care of mutation tracking
252- if ( allowVaultAccess ) {
253- vaultSecrets . enableTracking ( { autoCompact : true } ) ;
254- }
255-
256252 // @todo : find a better place to code this so that event is not aware of such options
257253 if ( abortOnFailure ) {
258254 abortOnError = true ;
@@ -398,19 +394,34 @@ module.exports = {
398394 }
399395 } . bind ( this ) ) ;
400396
401- this . host . on ( EXECUTION_VAULT_BASE + executionId , function ( id , cmd , ...args ) {
397+ this . host . on ( EXECUTION_VAULT_BASE + executionId , async function ( id , cmd , ...args ) {
398+ if ( hasVaultAccess === undefined ) {
399+ try {
400+ // eslint-disable-next-line require-atomic-updates
401+ hasVaultAccess = Boolean ( await vaultSecrets ?. _ ?. allowScriptAccess ( item . id ) ) ;
402+ }
403+ catch ( _ ) {
404+ // eslint-disable-next-line require-atomic-updates
405+ hasVaultAccess = false ;
406+ }
407+ }
408+
402409 // Ensure error is string
403410 // TODO identify why error objects are not being serialized correctly
404411 const dispatch = ( e , r ) => { this . host . dispatch ( EXECUTION_VAULT_BASE + executionId , id , e , r ) ; } ;
405412
406- if ( ! allowVaultAccess ) {
413+ if ( ! hasVaultAccess ) {
407414 return dispatch ( 'Vault access denied' ) ;
408415 }
409416
410417 if ( ! [ 'get' , 'set' , 'unset' ] . includes ( cmd ) ) {
411418 return dispatch ( `Invalid vault command: ${ cmd } ` ) ;
412419 }
413420
421+ // Explicitly enable tracking for vault secrets here as this will
422+ // not be sent to sandbox who otherwise takes care of mutation tracking
423+ vaultSecrets . enableTracking ( { autoCompact : true } ) ;
424+
414425 dispatch ( null , vaultSecrets [ cmd ] ( ...args ) ) ;
415426 } . bind ( this ) ) ;
416427
@@ -556,7 +567,7 @@ module.exports = {
556567 result && result . request && ( result . request = new sdk . Request ( result . request ) ) ;
557568
558569 // vault secrets are not sent to sandbox, thus using the scope from run context.
559- if ( allowVaultAccess && vaultSecrets ) {
570+ if ( hasVaultAccess && vaultSecrets ) {
560571 result . vaultSecrets = vaultSecrets ;
561572
562573 // Prevent mutations from being carry-forwarded to subsequent events
0 commit comments