@@ -698,7 +698,9 @@ describe("exec approvals shell analysis", () => {
698698 } ,
699699 ) ;
700700
701- it ( "fails allowlist analysis for shell line continuations" , ( ) => {
701+ it ( "fails allowlist analysis when a spliced line continuation produces an unsafe construct" , ( ) => {
702+ // After splicing `\<newline>`, this becomes `echo "ok $(id -u)"` which
703+ // the parser rejects as an unsupported shell substitution.
702704 const result = evaluateShellAllowlist ( {
703705 command : 'echo "ok $\\\n(id -u)"' ,
704706 allowlist : [ { pattern : "/usr/bin/echo" } ] ,
@@ -709,6 +711,50 @@ describe("exec approvals shell analysis", () => {
709711 expect ( result . allowlistSatisfied ) . toBe ( false ) ;
710712 } ) ;
711713
714+ it ( "satisfies allowlist for safe backslash-newline line continuations" , ( ) => {
715+ const result = evaluateShellAllowlist ( {
716+ command : "/usr/bin/git \\\n commit \\\n -m 'msg'" ,
717+ allowlist : [ { pattern : "/usr/bin/git" } ] ,
718+ safeBins : new Set ( ) ,
719+ cwd : "/tmp" ,
720+ } ) ;
721+ expect ( result . analysisOk ) . toBe ( true ) ;
722+ expect ( result . allowlistSatisfied ) . toBe ( true ) ;
723+ } ) ;
724+
725+ it ( "does not splice backslash-newline inside single quotes" , ( ) => {
726+ const result = evaluateShellAllowlist ( {
727+ command : "/usr/bin/git commit -m 'fix: foo\\\nbar'" ,
728+ allowlist : [ { pattern : "/usr/bin/git" } ] ,
729+ safeBins : new Set ( ) ,
730+ cwd : "/tmp" ,
731+ } ) ;
732+ expect ( result . analysisOk ) . toBe ( true ) ;
733+ expect ( result . allowlistSatisfied ) . toBe ( true ) ;
734+ } ) ;
735+
736+ it ( "marks analysisOk true but allowlistSatisfied false for unapproved binary after splicing" , ( ) => {
737+ const result = evaluateShellAllowlist ( {
738+ command : "/usr/bin/curl \\\n https://example.com" ,
739+ allowlist : [ ] ,
740+ safeBins : new Set ( ) ,
741+ cwd : "/tmp" ,
742+ } ) ;
743+ expect ( result . analysisOk ) . toBe ( true ) ;
744+ expect ( result . allowlistSatisfied ) . toBe ( false ) ;
745+ } ) ;
746+
747+ it ( "evaluates chain operators exposed by line continuation splicing" , ( ) => {
748+ const result = evaluateShellAllowlist ( {
749+ command : "/usr/bin/echo ok \\\n&& /usr/bin/rm -rf /" ,
750+ allowlist : [ { pattern : "/usr/bin/echo" } ] ,
751+ safeBins : new Set ( ) ,
752+ cwd : "/tmp" ,
753+ } ) ;
754+ expect ( result . analysisOk ) . toBe ( true ) ;
755+ expect ( result . allowlistSatisfied ) . toBe ( false ) ;
756+ } ) ;
757+
712758 it ( "satisfies allowlist when bare * wildcard is present" , ( ) => {
713759 const dir = makeTempDir ( ) ;
714760 const binPath = path . join ( dir , "mybin" ) ;
0 commit comments