@@ -59,11 +59,49 @@ function yamlMapping(line) {
5959 return {
6060 indent : match [ 1 ] . length ,
6161 key : match [ 3 ] ?? match [ 4 ] ,
62+ lineIndent : match [ 1 ] . length ,
6263 quoted : Boolean ( match [ 2 ] ) ,
6364 value : match [ 5 ] . replace ( / \s + # .* $ / , '' ) . trim ( ) ,
6465 }
6566}
6667
68+ function yamlSequenceMapping ( line ) {
69+ const match = line . match (
70+ / ^ ( \s * ) - \s + (?: ( [ " ' ] ) ( [ ^ " ' ] + ) \2| ( [ A - Z a - z _ ] [ A - Z a - z 0 - 9 _ - ] * ) ) \s * : ( .* ) $ / ,
71+ )
72+ if ( ! match ) return null
73+ return {
74+ indent : match [ 1 ] . length + 2 ,
75+ key : match [ 3 ] ?? match [ 4 ] ,
76+ lineIndent : match [ 1 ] . length ,
77+ quoted : Boolean ( match [ 2 ] ) ,
78+ value : match [ 5 ] . replace ( / \s + # .* $ / , '' ) . trim ( ) ,
79+ }
80+ }
81+
82+ function conservativeYamlBlock ( lines ) {
83+ let scalarParentIndent = null
84+ for ( const line of lines ) {
85+ const lineIndent = line . match ( / ^ \s * / ) ?. [ 0 ] . length ?? 0
86+ if ( scalarParentIndent !== null && lineIndent > scalarParentIndent ) continue
87+ scalarParentIndent = null
88+
89+ const mapping = yamlMapping ( line ) ?? yamlSequenceMapping ( line )
90+ if (
91+ ! mapping ||
92+ mapping . quoted ||
93+ / ^ [ { [ ] / . test ( mapping . value ) ||
94+ / ^ [ ! & * ] / . test ( mapping . value )
95+ ) {
96+ return false
97+ }
98+ if ( / ^ [ > | ] [ + - ] ? (?: [ 1 - 9 ] ) ? $ / . test ( mapping . value ) ) {
99+ scalarParentIndent = mapping . lineIndent
100+ }
101+ }
102+ return true
103+ }
104+
67105function historicalWorkflowIsLowPrivilege ( source ) {
68106 const lines = activeYamlLines ( source )
69107 if (
@@ -142,7 +180,9 @@ function historicalWorkflowIsLowPrivilege(source) {
142180
143181 const jobsEntries = topLevelMappings . filter ( ( { mapping } ) => mapping . key === 'jobs' )
144182 if ( jobsEntries . length !== 1 || jobsEntries [ 0 ] . mapping . value ) return false
145- const jobDeclarations = blockLines ( jobsEntries [ 0 ] ) . filter (
183+ const jobsBlock = blockLines ( jobsEntries [ 0 ] )
184+ if ( ! conservativeYamlBlock ( jobsBlock ) ) return false
185+ const jobDeclarations = jobsBlock . filter (
146186 ( line ) => ( line . match ( / ^ \s * / ) ?. [ 0 ] . length ?? 0 ) <= 2 ,
147187 )
148188 return (
0 commit comments