@@ -717,13 +717,16 @@ test('a sig, hmac or pass header name masks its value while assign, compass and
717717// #3278: the two things #3275 fixed stay fixed — a value under six characters is left alone rather
718718// than eating the words around it, and the mask still runs before the 300-character cut, so a literal
719719// inside the kept part is gone and only the tail past the cut is dropped.
720+ // #3281 test-quality item: the under-six value is pinned behind a credential-looking flag and is
721+ // exactly five characters, so deleting `value.length >= 6` in `capabilities.js` turns this test red
722+ // instead of passing because the flag name itself never matched a credential.
720723test ( 'an argv literal under six characters stays and an argv literal is masked before the three-hundred cut' , async t => {
721724 const state = team ( )
722725 state . capabilities = {
723726 items : {
724727 long : {
725728 name : 'long' , kind : 'mcp' , description : 'Local server' , transport : 'stdio' , command : 'node' ,
726- args : [ 'server.js' , '--pin ' , 'abcde' , '--api-key' , 'sk-live-abcdef123456' ] ,
729+ args : [ 'server.js' , '--api-key ' , 'abcde' , '--api-key' , 'sk-live-abcdef123456' ] ,
727730 env : { } , approved : true , createdBy : 'worker' , createdAt : 1 , updatedAt : 1 ,
728731 } ,
729732 } ,
@@ -732,13 +735,13 @@ test('an argv literal under six characters stays and an argv literal is masked b
732735 t . after ( ( ) => env . dispose ( ) )
733736 const { ctx, rt, mounts, skills } = env
734737 await rt . changeCapabilityAttachment ( 'attach' , { name : 'long' } , 'worker' )
735- const quoted = `server exited: --pin abcde ${ 'x' . repeat ( 170 ) } --api-key sk-live-abcdef123456 ${ 'z' . repeat ( 200 ) } `
738+ const quoted = `server exited: --api-key abcde ${ 'x' . repeat ( 170 ) } --api-key sk-live-abcdef123456 ${ 'z' . repeat ( 200 ) } `
736739 ctx . emit ( 'agent/created' , { agent : testAgent ( 'worker' , mounts , skills , { awaitMount : async ( ) => { throw new Error ( quoted ) } } ) } )
737740 await rt . scheduleCapabilitiesReconcile ( )
738741 const status = rt . capabilityStatusesView ( ) . worker . long
739742 assert . equal ( status . state , 'error' )
740743 assert . equal ( status . error . length , 300 , 'the stored reason is still cut at 300 characters' )
741- assert . equal ( status . error . startsWith ( 'server exited: --pin abcde ' ) , true , 'a five-character value is left alone' )
744+ assert . equal ( status . error . startsWith ( 'server exited: --api-key abcde ' ) , true , 'a five-character value behind a credential flag is left alone' )
742745 assert . equal ( status . error . includes ( '--api-key [hidden]' ) , true , 'the mask ran before the cut' )
743746 assert . equal ( status . error . includes ( 'sk-live-abcdef123456' ) , false )
744747} )
@@ -833,3 +836,92 @@ test('an http capability saved before this fix shows no header literal on any su
833836 assert . equal ( surfaces . listed . includes ( masked ) , true )
834837 assert . equal ( surfaces . prompt . includes ( masked ) , true )
835838} )
839+
840+ // #3281: a stdio entry can be saved from a pasted line, so `command` itself may hold a whole command
841+ // line (`node server.js --api-key …`). When it contains whitespace it is split into tokens and read
842+ // with the same rules as `args`, so the literal after a credential-looking flag is masked in the
843+ // stored reason. A command that is a single bare token stays unmasked: it cannot be told from a
844+ // program name, the same documented limit as a bare `args` token.
845+ test ( 'an error that quotes a stdio command line stored in `command` masks the credential literal' , async t => {
846+ const state = team ( )
847+ state . capabilities = {
848+ items : {
849+ inline : {
850+ name : 'inline' , kind : 'mcp' , description : 'Local server' , transport : 'stdio' ,
851+ command : 'node server.js --api-key sk-live-abcdef123456 --password=hunter2-secret -e SERVICE_TOKEN=tok-abcdef123' ,
852+ args : [ ] , env : { } , approved : true , createdBy : 'worker' , createdAt : 1 , updatedAt : 1 ,
853+ } ,
854+ } ,
855+ }
856+ const env = await setup ( { state } )
857+ t . after ( ( ) => env . dispose ( ) )
858+ const { ctx, rt, mounts, skills } = env
859+ await rt . changeCapabilityAttachment ( 'attach' , { name : 'inline' } , 'worker' )
860+ const quoted = 'spawn node server.js --api-key sk-live-abcdef123456 --password=hunter2-secret -e SERVICE_TOKEN=tok-abcdef123 ENOENT'
861+ ctx . emit ( 'agent/created' , { agent : testAgent ( 'worker' , mounts , skills , { awaitMount : async ( ) => { throw new Error ( quoted ) } } ) } )
862+ await rt . scheduleCapabilitiesReconcile ( )
863+ const status = rt . capabilityStatusesView ( ) . worker . inline
864+ assert . equal ( status . state , 'error' )
865+ assert . equal (
866+ status . error ,
867+ 'spawn node server.js --api-key [hidden] --password=[hidden] -e SERVICE_TOKEN=[hidden] ENOENT' ,
868+ 'the inline command line is read with the same flag, inline and assignment rules as args' ,
869+ )
870+ const stored = JSON . stringify ( rt . capabilityStatusesView ( ) )
871+ assert . equal ( stored . includes ( 'sk-live-abcdef123456' ) , false )
872+ assert . equal ( stored . includes ( 'hunter2-secret' ) , false )
873+ assert . equal ( stored . includes ( 'tok-abcdef123' ) , false )
874+ } )
875+
876+ // #3281: a generated credential can begin with `-`, and the token after a credential-looking flag is
877+ // that flag's value even then. The accepted cost is that `--api-key --verbose` stores `--api-key
878+ // [hidden]`; it is recorded in `docs/subsystems/core-host.md`, the fragment and the pull request body.
879+ test ( 'a dash-prefixed credential value after a credential flag is masked' , async t => {
880+ const state = team ( )
881+ state . capabilities = {
882+ items : {
883+ dash : {
884+ name : 'dash' , kind : 'mcp' , description : 'Local server' , transport : 'stdio' , command : 'node' ,
885+ args : [ 'server.js' , '--api-key' , '-s3cr3t-abcdef' , '--verbose' ] ,
886+ env : { } , approved : true , createdBy : 'worker' , createdAt : 1 , updatedAt : 1 ,
887+ } ,
888+ } ,
889+ }
890+ const env = await setup ( { state } )
891+ t . after ( ( ) => env . dispose ( ) )
892+ const { ctx, rt, mounts, skills } = env
893+ await rt . changeCapabilityAttachment ( 'attach' , { name : 'dash' } , 'worker' )
894+ const quoted = 'spawn node ENOENT: node server.js --api-key -s3cr3t-abcdef --verbose'
895+ ctx . emit ( 'agent/created' , { agent : testAgent ( 'worker' , mounts , skills , { awaitMount : async ( ) => { throw new Error ( quoted ) } } ) } )
896+ await rt . scheduleCapabilitiesReconcile ( )
897+ const status = rt . capabilityStatusesView ( ) . worker . dash
898+ assert . equal ( status . state , 'error' )
899+ assert . equal ( status . error , 'spawn node ENOENT: node server.js --api-key [hidden] --verbose' , 'a value beginning with - is still the flag value' )
900+ assert . equal ( JSON . stringify ( rt . capabilityStatusesView ( ) ) . includes ( 's3cr3t-abcdef' ) , false )
901+ } )
902+
903+ // #3281 accepted cost: a following flag is taken as the value and masked, so `--api-key --verbose`
904+ // reads `--api-key [hidden]`. The test pins the cost exactly; the doc, the fragment and the pull
905+ // request body say the same sentence.
906+ test ( 'a flag directly after a credential flag is masked as its value' , async t => {
907+ const state = team ( )
908+ state . capabilities = {
909+ items : {
910+ bare : {
911+ name : 'bare' , kind : 'mcp' , description : 'Local server' , transport : 'stdio' , command : 'node' ,
912+ args : [ 'server.js' , '--api-key' , '--verbose' ] ,
913+ env : { } , approved : true , createdBy : 'worker' , createdAt : 1 , updatedAt : 1 ,
914+ } ,
915+ } ,
916+ }
917+ const env = await setup ( { state } )
918+ t . after ( ( ) => env . dispose ( ) )
919+ const { ctx, rt, mounts, skills } = env
920+ await rt . changeCapabilityAttachment ( 'attach' , { name : 'bare' } , 'worker' )
921+ const quoted = 'server exited: node server.js --api-key --verbose'
922+ ctx . emit ( 'agent/created' , { agent : testAgent ( 'worker' , mounts , skills , { awaitMount : async ( ) => { throw new Error ( quoted ) } } ) } )
923+ await rt . scheduleCapabilitiesReconcile ( )
924+ const status = rt . capabilityStatusesView ( ) . worker . bare
925+ assert . equal ( status . state , 'error' )
926+ assert . equal ( status . error , 'server exited: node server.js --api-key [hidden]' , 'the accepted cost: a following flag is masked' )
927+ } )
0 commit comments