@yeison.restrepo.r/code-conductor 1.31.1 → 1.31.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -155,6 +155,7 @@ function g3JoinContinuations(input) {
|
|
|
155
155
|
// unclosed quote). "glob" reports whether an unquoted glob character appears, and
|
|
156
156
|
// treats malformed input as a glob, which is the authority's fail-closed choice.
|
|
157
157
|
function g3Scan(mode, input) {
|
|
158
|
+
const emit = mode === 'strip' || mode === 'mask';
|
|
158
159
|
let state = 'UNQUOTED';
|
|
159
160
|
let result = '';
|
|
160
161
|
let i = 0;
|
|
@@ -163,43 +164,47 @@ function g3Scan(mode, input) {
|
|
|
163
164
|
const ch = input[i];
|
|
164
165
|
const two = input.slice(i, i + 2);
|
|
165
166
|
if (state === 'UNQUOTED') {
|
|
166
|
-
if (two === "$'") { if (
|
|
167
|
-
else if (two === '$"') { if (
|
|
168
|
-
else if (ch === '\\') { if (
|
|
169
|
-
else if (ch === "'") { if (
|
|
170
|
-
else if (ch === '"') { if (
|
|
167
|
+
if (two === "$'") { if (emit) result += two; i += 2; state = 'ANSI_C_QUOTED'; }
|
|
168
|
+
else if (two === '$"') { if (emit) result += two; i += 2; state = 'LOCALE_QUOTED'; }
|
|
169
|
+
else if (ch === '\\') { if (emit) result += input.slice(i, i + 2); i += 2; }
|
|
170
|
+
else if (ch === "'") { if (emit) result += ch; i += 1; state = 'SINGLE_QUOTED'; }
|
|
171
|
+
else if (ch === '"') { if (emit) result += ch; i += 1; state = 'DOUBLE_QUOTED'; }
|
|
171
172
|
else if (ch === '#' && mode === 'strip') { while (i < len && input[i] !== '\n') i += 1; }
|
|
172
173
|
else {
|
|
173
174
|
if (mode === 'glob' && (ch === '*' || ch === '?' || ch === '{' || ch === '[')) return { glob: true };
|
|
174
|
-
if (
|
|
175
|
+
if (emit) result += ch;
|
|
175
176
|
i += 1;
|
|
176
177
|
}
|
|
177
178
|
} else if (state === 'SINGLE_QUOTED') {
|
|
178
179
|
// Backslash is literal here and ANY quote exits: there is no escape mechanism.
|
|
179
180
|
if (mode === 'strip') result += ch;
|
|
181
|
+
else if (mode === 'mask') result += ch === "'" ? ch : 'x';
|
|
180
182
|
if (ch === "'") state = 'UNQUOTED';
|
|
181
183
|
i += 1;
|
|
182
184
|
} else if (state === 'DOUBLE_QUOTED' || state === 'LOCALE_QUOTED') {
|
|
183
|
-
if (ch === '\\') { if (mode === 'strip') result += input.slice(i, i + 2); i += 2; }
|
|
184
|
-
else if (ch === '"') { if (
|
|
185
|
-
else { if (mode === 'strip') result += ch; i += 1; }
|
|
185
|
+
if (ch === '\\') { if (mode === 'strip') result += input.slice(i, i + 2); else if (mode === 'mask') result += 'xx'; i += 2; }
|
|
186
|
+
else if (ch === '"') { if (emit) result += ch; i += 1; state = 'UNQUOTED'; }
|
|
187
|
+
else { if (mode === 'strip') result += ch; else if (mode === 'mask') result += 'x'; i += 1; }
|
|
186
188
|
} else {
|
|
187
|
-
if (ch === '\\') { if (mode === 'strip') result += input.slice(i, i + 2); i += 2; }
|
|
188
|
-
else if (ch === "'") { if (
|
|
189
|
-
else { if (mode === 'strip') result += ch; i += 1; }
|
|
189
|
+
if (ch === '\\') { if (mode === 'strip') result += input.slice(i, i + 2); else if (mode === 'mask') result += 'xx'; i += 2; }
|
|
190
|
+
else if (ch === "'") { if (emit) result += ch; i += 1; state = 'UNQUOTED'; }
|
|
191
|
+
else { if (mode === 'strip') result += ch; else if (mode === 'mask') result += 'x'; i += 1; }
|
|
190
192
|
}
|
|
191
193
|
}
|
|
192
|
-
if (state !== 'UNQUOTED') return
|
|
193
|
-
return
|
|
194
|
+
if (state !== 'UNQUOTED') return emit ? { result, malformed: true } : { glob: true };
|
|
195
|
+
return emit ? { result, malformed: false } : { glob: false };
|
|
194
196
|
}
|
|
195
197
|
|
|
196
198
|
// Each check returns true when it FIRES (the authority's shell functions returned 1).
|
|
197
199
|
//
|
|
198
|
-
//
|
|
199
|
-
//
|
|
200
|
-
//
|
|
201
|
-
//
|
|
202
|
-
//
|
|
200
|
+
// The walk's contract, corrected in both subjects under [BUG-041]: `after` is the
|
|
201
|
+
// text that FOLLOWS the match, sliced from `m.index + m[0].length`. The original form
|
|
202
|
+
// sliced by the match LENGTH from position 0, so for a match at index N it shaved N
|
|
203
|
+
// bytes of real command off the front and re-scanned, walking leftward until the cut
|
|
204
|
+
// landed inside a quoted region; g3Scan's fail-closed clause then reported a glob that
|
|
205
|
+
// was never in the command. It cost 24 of the 47 denials measured in one session. The
|
|
206
|
+
// authority carries the same correction, recorded as its third sanctioned exception,
|
|
207
|
+
// so the corpus still arbitrates both subjects rather than one.
|
|
203
208
|
|
|
204
209
|
function g3P1FindDepth(s) {
|
|
205
210
|
if (!reFind.test(s)) return false;
|
|
@@ -241,7 +246,7 @@ function g3GlobWalk(s, re) {
|
|
|
241
246
|
for (;;) {
|
|
242
247
|
const m = re.exec(rest);
|
|
243
248
|
if (!m) return false;
|
|
244
|
-
const after = rest.slice(m[0].length);
|
|
249
|
+
const after = rest.slice(m.index + m[0].length);
|
|
245
250
|
if (g3Scan('glob', after).glob) return true;
|
|
246
251
|
rest = after;
|
|
247
252
|
if (rest === '') return false;
|
|
@@ -448,9 +453,18 @@ function guard3BashScan(input) {
|
|
|
448
453
|
}
|
|
449
454
|
// Real newlines become semicolons so a multi-line script reads as a command
|
|
450
455
|
// sequence to every position-anchored pattern above.
|
|
451
|
-
|
|
456
|
+
//
|
|
457
|
+
// The mask is built from the STRIPPED string and BEFORE the newline join, so a
|
|
458
|
+
// newline inside a quoted region can never become a command-position anchor.
|
|
459
|
+
// Exactly two checks read quoted content BY DESIGN: P6 reads the grep pattern and
|
|
460
|
+
// P12 reads the alias value. Everything else reads code and gets the mask. The
|
|
461
|
+
// allowlist reads the unmasked string. [BUG-043].
|
|
462
|
+
const chomped = g3Chomp(scan.result);
|
|
463
|
+
const pre = chomped.split('\n').join(';');
|
|
464
|
+
const masked = g3Scan('mask', chomped).result.split('\n').join(';');
|
|
465
|
+
const UNMASKED_CHECKS = new Set(['P6', 'P12']);
|
|
452
466
|
const ids = [];
|
|
453
|
-
for (const { id, check } of G3_CHECKS) if (check(pre)) ids.push(id);
|
|
467
|
+
for (const { id, check } of G3_CHECKS) if (check(UNMASKED_CHECKS.has(id) ? pre : masked)) ids.push(id);
|
|
454
468
|
if (ids.length === 0) return null;
|
|
455
469
|
if (g3AllowlistCovers(pre, g3ReadAllowlist())) return null;
|
|
456
470
|
return g3Blocked(`The command triggered a mass content-dump pattern. Pattern ids: ${ids.join(' ')}.`);
|