burnoff 1.1.0 → 1.2.0

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.
Files changed (38) hide show
  1. package/.github/workflows/burnoff-pr-gate.yml +3 -3
  2. package/README.md +66 -78
  3. package/bin/burnoff.mjs +67 -23
  4. package/hooks/hook-io.mjs +19 -7
  5. package/hooks/post-tool-use.mjs +33 -26
  6. package/hooks/pre-tool-use.mjs +43 -41
  7. package/hooks/session-lifecycle.mjs +40 -0
  8. package/package.json +7 -5
  9. package/src/ci/ci-gate.mjs +22 -0
  10. package/src/ci/pr-cost.mjs +42 -10
  11. package/src/ci/team-digest.mjs +5 -3
  12. package/src/cli/audit.mjs +103 -18
  13. package/src/cli/doctor.mjs +209 -14
  14. package/src/cli/init.mjs +349 -96
  15. package/src/cli/startup-audit.mjs +500 -24
  16. package/src/clients/antigravity.mjs +285 -0
  17. package/src/clients/claude-code.mjs +180 -0
  18. package/src/clients/detect.mjs +64 -0
  19. package/src/config/loader.mjs +11 -4
  20. package/src/config/paths.mjs +62 -2
  21. package/src/config/policy.mjs +34 -5
  22. package/src/config/pricing.mjs +16 -5
  23. package/src/guards/loop-breaker.mjs +198 -13
  24. package/src/guards/post-tool-engine.mjs +289 -29
  25. package/src/guards/pre-tool-engine.mjs +336 -129
  26. package/src/guards/read-clamp.mjs +78 -18
  27. package/src/guards/session-hook.mjs +207 -0
  28. package/src/guards/shell-guard.mjs +583 -73
  29. package/src/ipc/daemon.mjs +50 -8
  30. package/src/ipc/fast-client.mjs +62 -5
  31. package/src/ipc/protocol.mjs +1 -1
  32. package/src/storage/antigravity-parser.mjs +258 -0
  33. package/src/storage/file-lock.mjs +13 -4
  34. package/src/storage/fts5-archive.mjs +4 -4
  35. package/src/storage/jsonl-parser.mjs +7 -1
  36. package/src/storage/ledger.mjs +10 -3
  37. package/src/storage/sqlite-client.mjs +4 -2
  38. package/hooks/hooks.json +0 -12
@@ -53,12 +53,79 @@ const SAFE_ENV_ALLOWLIST_REGEX =
53
53
 
54
54
  const SECRET_FILE_PATTERNS = [
55
55
  /(?:^|[\\/])\.env(?:\.[a-zA-Z0-9._-]+)?$/i,
56
- /\.(?:pem|key|p12|pfx)$/i,
56
+ /\.(?:pem|key|p12|pfx|crt)$/i,
57
57
  /(?:^|[\\/])id_(?:rsa|ed25519|ecdsa|dsa)(?:\.pub)?$/i,
58
58
  /(?:^|[\\/])\.(?:ssh|aws)[\\/]/i,
59
59
  /(?:^|[\\/])\.(?:npmrc|netrc|pypirc)$/i
60
60
  ];
61
61
 
62
+ const SECRET_READ_EXFIL_BINS = new Set([
63
+ 'cat',
64
+ 'head',
65
+ 'tail',
66
+ 'less',
67
+ 'more',
68
+ 'bat',
69
+ 'nl',
70
+ 'tac',
71
+ 'od',
72
+ 'xxd',
73
+ 'hexdump',
74
+ 'strings',
75
+ 'base64',
76
+ 'grep',
77
+ 'egrep',
78
+ 'fgrep',
79
+ 'rg',
80
+ 'ag',
81
+ 'awk',
82
+ 'sed',
83
+ 'cut',
84
+ 'sort',
85
+ 'uniq',
86
+ 'wc',
87
+ 'diff',
88
+ 'tr',
89
+ 'tee',
90
+ 'get-content',
91
+ 'gc',
92
+ 'type',
93
+ 'select-string',
94
+ 'curl',
95
+ 'wget',
96
+ 'scp',
97
+ 'rsync',
98
+ 'sftp',
99
+ 'ftp',
100
+ 'nc',
101
+ 'ncat',
102
+ 'socat',
103
+ 'source',
104
+ '.',
105
+ 'node',
106
+ 'python',
107
+ 'python3',
108
+ 'perl',
109
+ 'ruby',
110
+ 'bash',
111
+ 'sh',
112
+ 'zsh',
113
+ 'pwsh',
114
+ 'powershell'
115
+ ]);
116
+
117
+ const COPY_MOVE_BINS = new Set([
118
+ 'cp',
119
+ 'mv',
120
+ 'install',
121
+ 'copy-item',
122
+ 'move-item',
123
+ 'cpi',
124
+ 'mi'
125
+ ]);
126
+
127
+ const BENIGN_GIT_SUBCOMMANDS = new Set(['status', 'diff', 'log', 'branch']);
128
+
62
129
  const PROTECTED_EDIT_PATTERNS = [
63
130
  /(?:^|[\\/])migrations[\\/]/i,
64
131
  /(?:^|[\\/])prisma[\\/]migrations[\\/]/i,
@@ -142,6 +209,34 @@ export function tokenizeShellSegment(commandSegment = '', options = {}) {
142
209
  return tokens;
143
210
  }
144
211
 
212
+ function scanBalancedParens(str = '', openParenIdx = 0) {
213
+ let depth = 1;
214
+ let j = openParenIdx + 1;
215
+ let innerQuote = null;
216
+ while (j < str.length && depth > 0) {
217
+ const c = str[j];
218
+ if (innerQuote === "'") {
219
+ if (c === "'") innerQuote = null;
220
+ } else if (innerQuote === '"') {
221
+ if (c === '\\' && j + 1 < str.length) {
222
+ j += 1;
223
+ } else if (c === '"') {
224
+ innerQuote = null;
225
+ }
226
+ } else if (c === "'" || c === '"') {
227
+ innerQuote = c;
228
+ } else if (c === '(') {
229
+ depth += 1;
230
+ } else if (c === ')') {
231
+ depth -= 1;
232
+ if (depth === 0) break;
233
+ }
234
+ j += 1;
235
+ }
236
+ if (depth !== 0) return null;
237
+ return { inner: str.slice(openParenIdx + 1, j).trim(), closeIdx: j };
238
+ }
239
+
145
240
  function extractCommandSubstitutions(commandLine = '', options = {}) {
146
241
  const extracted = [];
147
242
  const str = String(commandLine || '');
@@ -172,32 +267,19 @@ function extractCommandSubstitutions(commandLine = '', options = {}) {
172
267
  }
173
268
 
174
269
  if (ch === '$' && str[i + 1] === '(') {
175
- let depth = 1;
176
- let j = i + 2;
177
- let innerQuote = null;
178
- while (j < str.length && depth > 0) {
179
- const c = str[j];
180
- if (innerQuote === "'") {
181
- if (c === "'") innerQuote = null;
182
- } else if (innerQuote === '"') {
183
- if (c === '\\' && j + 1 < str.length) {
184
- j += 1;
185
- } else if (c === '"') {
186
- innerQuote = null;
187
- }
188
- } else if (c === "'" || c === '"') {
189
- innerQuote = c;
190
- } else if (c === '(') {
191
- depth += 1;
192
- } else if (c === ')') {
193
- depth -= 1;
194
- if (depth === 0) break;
195
- }
196
- j += 1;
270
+ const paren = scanBalancedParens(str, i + 1);
271
+ if (paren) {
272
+ if (paren.inner) extracted.push(paren.inner);
273
+ i = paren.closeIdx;
197
274
  }
198
- if (depth === 0) {
199
- const inner = str.slice(i + 2, j).trim();
200
- if (inner) extracted.push(inner);
275
+ continue;
276
+ }
277
+
278
+ if (!quoteChar && !isPowerShell && (ch === '<' || ch === '>') && str[i + 1] === '(') {
279
+ const paren = scanBalancedParens(str, i + 1);
280
+ if (paren) {
281
+ if (paren.inner) extracted.push(paren.inner);
282
+ i = paren.closeIdx;
201
283
  }
202
284
  continue;
203
285
  }
@@ -690,9 +772,9 @@ function isProtectedRecursiveDeleteTarget(rawArg = '') {
690
772
  return {
691
773
  detectorId: 'DET-01',
692
774
  triggered: true,
693
- decision: 'deny',
775
+ decision: isStrictAutoMode ? 'deny' : 'ask',
694
776
  subType: 'TEST_FILE_DELETION',
695
- reason: `[Burnoff DET-01 Test Integrity Lock] Deleting test file "${deletedTestTarget}" via shell without explicit user instruction is forbidden.`
777
+ reason: `[Burnoff DET-01 Test Integrity Lock] Deleting test file "${deletedTestTarget}" via shell without explicit user instruction requires confirmation.`
696
778
  };
697
779
  }
698
780
  }
@@ -721,9 +803,9 @@ function isProtectedRecursiveDeleteTarget(rawArg = '') {
721
803
  return {
722
804
  detectorId: 'DET-01',
723
805
  triggered: true,
724
- decision: 'deny',
806
+ decision: isStrictAutoMode ? 'deny' : 'ask',
725
807
  subType: 'TEST_FILE_DELETION',
726
- reason: `[Burnoff DET-01 Test Integrity Lock] Deleting test file "${deletedTestTarget}" via shell without explicit user instruction is forbidden.`
808
+ reason: `[Burnoff DET-01 Test Integrity Lock] Deleting test file "${deletedTestTarget}" via shell without explicit user instruction requires confirmation.`
727
809
  };
728
810
  }
729
811
  }
@@ -791,6 +873,21 @@ function isProtectedRecursiveDeleteTarget(rawArg = '') {
791
873
 
792
874
  const subArgs = rawTokens.slice(idx);
793
875
 
876
+ if (subcommand === 'rm' && !userExplicitTestIntent) {
877
+ const deletedTestTarget = subArgs.find(
878
+ (a) => !a.startsWith('-') && isProtectedTestFileToken(a)
879
+ );
880
+ if (deletedTestTarget) {
881
+ return {
882
+ detectorId: 'DET-01',
883
+ triggered: true,
884
+ decision: isStrictAutoMode ? 'deny' : 'ask',
885
+ subType: 'TEST_FILE_DELETION',
886
+ reason: `[Burnoff DET-01 Test Integrity Lock] Deleting test file "${deletedTestTarget}" via "git rm" without explicit user instruction requires confirmation.`
887
+ };
888
+ }
889
+ }
890
+
794
891
  if (subcommand === 'config') {
795
892
  let isReadOnlyQuery = false;
796
893
  const positional = [];
@@ -1064,64 +1161,477 @@ function isProtectedRecursiveDeleteTarget(rawArg = '') {
1064
1161
  return { detectorId: 'DET-01', triggered: false, decision: 'allow', reason: null };
1065
1162
  }
1066
1163
 
1164
+ function normalizeSecretCandidate(rawPath = '') {
1165
+ return String(rawPath || '').trim().replace(/^['"]|['"]$/g, '').replace(/\\/g, '/').replace(/^\.\//, '');
1166
+ }
1167
+
1168
+ function secretGlobToRegExp(pattern = '') {
1169
+ let out = '^';
1170
+ for (let i = 0; i < pattern.length; i += 1) {
1171
+ const ch = pattern[i];
1172
+ if (ch === '*') {
1173
+ if (pattern[i + 1] === '*') {
1174
+ out += '.*';
1175
+ i += 1;
1176
+ if (pattern[i + 1] === '/') i += 1;
1177
+ } else {
1178
+ out += '[^/]*';
1179
+ }
1180
+ } else if (ch === '?') {
1181
+ out += '[^/]';
1182
+ } else if ('.+^${}()|[]\\'.includes(ch)) {
1183
+ out += `\\${ch}`;
1184
+ } else {
1185
+ out += ch;
1186
+ }
1187
+ }
1188
+ out += '$';
1189
+ return new RegExp(out, 'i');
1190
+ }
1191
+
1192
+ function matchesSecretAllowList(rawTarget = '', secretAllow = []) {
1193
+ if (!Array.isArray(secretAllow) || secretAllow.length === 0) return false;
1194
+ const norm = normalizeSecretCandidate(rawTarget);
1195
+ if (!norm) return false;
1196
+ const baseName = norm.split('/').pop() || norm;
1197
+
1198
+ for (const rawPat of secretAllow) {
1199
+ const pat = normalizeSecretCandidate(rawPat);
1200
+ if (!pat) continue;
1201
+ const normLower = norm.toLowerCase();
1202
+ const patLower = pat.toLowerCase();
1203
+ if (normLower === patLower) return true;
1204
+ if (normLower.endsWith(`/${patLower}`)) return true;
1205
+ if (!pat.includes('/') && baseName.toLowerCase() === patLower) return true;
1206
+ const re = secretGlobToRegExp(pat);
1207
+ if (re.test(norm) || (!pat.includes('/') && re.test(baseName))) {
1208
+ return true;
1209
+ }
1210
+ }
1211
+ return false;
1212
+ }
1213
+
1214
+ const GLOB_META_REGEX = /[*?[]/;
1215
+ const CANONICAL_SECRET_GLOB_SAMPLES = [
1216
+ '.env',
1217
+ '.env.local',
1218
+ '.env.production',
1219
+ 'server.key',
1220
+ 'private.pem',
1221
+ 'cert.p12',
1222
+ 'cert.pfx',
1223
+ 'id_rsa',
1224
+ 'id_ed25519',
1225
+ 'id_ecdsa',
1226
+ 'id_dsa',
1227
+ '.npmrc',
1228
+ '.netrc',
1229
+ '.pypirc',
1230
+ '.ssh/id_rsa',
1231
+ '.ssh/config',
1232
+ '.aws/credentials'
1233
+ ];
1234
+ const BENIGN_GLOB_SAMPLES = [
1235
+ 'index.js',
1236
+ 'app.ts',
1237
+ 'README.md',
1238
+ 'package.json',
1239
+ 'notes.txt',
1240
+ '.gitignore',
1241
+ '.eslintrc',
1242
+ '.editorconfig'
1243
+ ];
1244
+
1245
+ function shellGlobToRegExp(pattern = '') {
1246
+ let out = '^';
1247
+ for (let i = 0; i < pattern.length; i += 1) {
1248
+ const ch = pattern[i];
1249
+ if (ch === '*') {
1250
+ if (pattern[i + 1] === '*') {
1251
+ out += '.*';
1252
+ i += 1;
1253
+ if (pattern[i + 1] === '/') i += 1;
1254
+ } else {
1255
+ out += '[^/]*';
1256
+ }
1257
+ } else if (ch === '?') {
1258
+ out += '[^/]';
1259
+ } else if (ch === '[') {
1260
+ const closeIdx = pattern.indexOf(']', i + 1);
1261
+ if (closeIdx !== -1) {
1262
+ const body = pattern.slice(i + 1, closeIdx);
1263
+ const negated = body.startsWith('!') ? `^${body.slice(1)}` : body;
1264
+ out += `[${negated}]`;
1265
+ i = closeIdx;
1266
+ } else {
1267
+ out += '\\[';
1268
+ }
1269
+ } else if ('.+^${}()|\\'.includes(ch)) {
1270
+ out += `\\${ch}`;
1271
+ } else {
1272
+ out += ch;
1273
+ }
1274
+ }
1275
+ out += '$';
1276
+ return new RegExp(out, 'i');
1277
+ }
1278
+
1279
+ function isSecretGlobPattern(normTarget = '', secretAllow = []) {
1280
+ const norm = normalizeSecretCandidate(normTarget);
1281
+ if (!norm || !GLOB_META_REGEX.test(norm)) return false;
1282
+ if (/^(?:\*+|\*\.\*|\.\*|\.\/\*|\*\*\/\*|\?+)$/.test(norm)) return false;
1283
+ if (SAFE_ENV_ALLOWLIST_REGEX.test(norm)) return false;
1284
+ if (matchesSecretAllowList(norm, secretAllow)) return false;
1285
+
1286
+ const hasSlash = norm.includes('/');
1287
+ const basePat = hasSlash ? norm.split('/').pop() : norm;
1288
+ let re;
1289
+ try {
1290
+ re = shellGlobToRegExp(hasSlash ? norm : basePat);
1291
+ } catch (err) {
1292
+ void err; // ignore: malformed bracket glob does not crash guard
1293
+ return false;
1294
+ }
1295
+
1296
+ for (const benign of BENIGN_GLOB_SAMPLES) {
1297
+ if (re.test(benign)) return false;
1298
+ }
1299
+
1300
+ for (const sample of CANONICAL_SECRET_GLOB_SAMPLES) {
1301
+ if (matchesSecretAllowList(sample, secretAllow)) continue;
1302
+ const targetSample = hasSlash ? sample : sample.split('/').pop();
1303
+ if (re.test(targetSample)) return true;
1304
+ }
1305
+ return false;
1306
+ }
1307
+
1308
+ function isConfidentalSecretPath(normTarget = '', secretAllow = []) {
1309
+ const norm = String(normTarget || '').trim().replace(/\\/g, '/');
1310
+ if (!norm) return false;
1311
+ if (SAFE_ENV_ALLOWLIST_REGEX.test(norm)) return false;
1312
+ if (matchesSecretAllowList(norm, secretAllow)) return false;
1313
+ if (SECRET_FILE_PATTERNS.some((pattern) => pattern.test(norm))) return true;
1314
+ return isSecretGlobPattern(norm, secretAllow);
1315
+ }
1316
+
1317
+ function isNonPrivateCertPath(normTarget = '') {
1318
+ const norm = String(normTarget || '').trim().replace(/\\/g, '/');
1319
+ if (GLOB_META_REGEX.test(norm)) return false;
1320
+ if (!/\.(?:pem|crt)$/i.test(norm)) return false;
1321
+ if (/(?:^|[\\/])\.(?:ssh|aws)[\\/]/i.test(norm)) return false;
1322
+ return !/(?:key|private)/i.test(norm);
1323
+ }
1324
+
1325
+ function pickStricterVerdict(best, candidate) {
1326
+ if (!candidate || !candidate.triggered) return best;
1327
+ if (!best || !best.triggered) return candidate;
1328
+ if (best.decision === 'deny') return best;
1329
+ if (candidate.decision === 'deny') return candidate;
1330
+ return best;
1331
+ }
1332
+
1333
+ const INLINE_EVAL_BIN_FLAGS = new Map([
1334
+ ['node', new Set(['-e', '--eval', '-p', '--print'])],
1335
+ ['deno', new Set(['-e', '--eval', '-p', '--print'])],
1336
+ ['bun', new Set(['-e', '--eval', '-p', '--print'])],
1337
+ ['python', new Set(['-c'])],
1338
+ ['python3', new Set(['-c'])],
1339
+ ['py', new Set(['-c'])],
1340
+ ['perl', new Set(['-e', '-E'])],
1341
+ ['ruby', new Set(['-e'])],
1342
+ ['php', new Set(['-r'])]
1343
+ ]);
1344
+
1345
+ function extractInlineScriptPayloads(bin, rawTokens = [], binIdx = 0) {
1346
+ const flags = INLINE_EVAL_BIN_FLAGS.get(bin);
1347
+ if (!flags) return [];
1348
+ const payloads = [];
1349
+ for (let i = binIdx + 1; i < rawTokens.length; i += 1) {
1350
+ const tok = String(rawTokens[i] || '');
1351
+ if (flags.has(tok) && i + 1 < rawTokens.length) {
1352
+ payloads.push(String(rawTokens[i + 1] || ''));
1353
+ i += 1;
1354
+ continue;
1355
+ }
1356
+ const eqIdx = tok.indexOf('=');
1357
+ if (eqIdx > 0 && flags.has(tok.slice(0, eqIdx))) {
1358
+ payloads.push(tok.slice(eqIdx + 1));
1359
+ }
1360
+ }
1361
+ return payloads;
1362
+ }
1363
+
1364
+ function extractInlineScriptCandidates(scriptText = '') {
1365
+ let normalized = String(scriptText || '');
1366
+ for (let pass = 0; pass < 4; pass += 1) {
1367
+ const next = normalized.replace(
1368
+ /(['"`])((?:\\.|(?!\1)[^\\])*)\1\s*\+\s*(['"`])((?:\\.|(?!\3)[^\\])*)\3/g,
1369
+ (_, _q1, left, _q2, right) => JSON.stringify(`${left}${right}`)
1370
+ );
1371
+ if (next === normalized) break;
1372
+ normalized = next;
1373
+ }
1374
+
1375
+ const out = [];
1376
+ const litRe = /'((?:\\.|[^'\\])*)'|"((?:\\.|[^"\\])*)"|`((?:\\.|[^`\\])*)`/g;
1377
+ let m;
1378
+ while ((m = litRe.exec(normalized)) !== null) {
1379
+ const val = (m[1] ?? m[2] ?? m[3] ?? '').trim();
1380
+ if (!val) continue;
1381
+ out.push(val);
1382
+ for (const part of val.split(/\s+/)) {
1383
+ const trimmed = part.replace(/^[,;()<>]+|[,;()<>]+$/g, '').trim();
1384
+ if (trimmed && trimmed !== val) out.push(trimmed);
1385
+ }
1386
+ }
1387
+ return out;
1388
+ }
1389
+
1390
+ function extractRedirectTokenTarget(rawTok = '') {
1391
+ const s = String(rawTok || '').trim();
1392
+ if (!s) return null;
1393
+ if (/^(?:&>>?|(?:\d*)>>?|\d*>\|)$/.test(s)) {
1394
+ return { kind: 'output_op' };
1395
+ }
1396
+ const outMatch = s.match(/^(?:&>>?|(?:\d*)>>?|\d*>\|)(.+)$/);
1397
+ if (outMatch && !outMatch[1].startsWith('&')) {
1398
+ return { kind: 'output_inline', target: outMatch[1].trim() };
1399
+ }
1400
+ if (/^<<<?$/.test(s)) {
1401
+ return { kind: 'heredoc_op' };
1402
+ }
1403
+ if (s === '<' || /^0<$/.test(s)) {
1404
+ return { kind: 'stdin_op' };
1405
+ }
1406
+ if (/^<<[^<]/.test(s)) {
1407
+ return { kind: 'heredoc_inline' };
1408
+ }
1409
+ const inMatch = s.match(/^(?:0?<)(.+)$/);
1410
+ if (inMatch && !inMatch[1].startsWith('<') && !inMatch[1].startsWith('&')) {
1411
+ return { kind: 'stdin_inline', target: inMatch[1].trim() };
1412
+ }
1413
+ return null;
1414
+ }
1415
+
1067
1416
  /**
1068
1417
  * DET-02: Secret & Credential Boundary.
1069
- * Blocks access to `.env*`, `*.pem`, `~/.ssh/*`, `~/.aws/*` while explicitly allowlisting
1070
- * `.env.example`, `.env.sample`, `.env.template`, `.env.defaults`, `.env.schema`.
1418
+ * Distinguishes direct credential reads/exfiltration (`deny`) from write/creation/argument usage
1419
+ * (`ask` in default `guard` mode, `deny` in `strict`/`auto`), treats non-private `.pem`/`.crt`
1420
+ * files as `ask`, and honors `guards.secretAllow` while allowlisting `.env.example` / `.env.sample`.
1071
1421
  */
1072
- export function evaluateDet02SecretBoundary(params = {}) {
1073
- const candidates = [];
1074
- if (params.filePath) candidates.push(String(params.filePath));
1075
- if (params.path) candidates.push(String(params.path));
1076
-
1077
- if (params.command && SHELL_TOOL_REGEX.test(String(params.toolName || 'Bash'))) {
1078
- const isPowerShell = detectPowerShellSyntax(params.toolName, params.command);
1079
- const segments = splitCommandSegments(String(params.command), { isPowerShell });
1080
- const benignGitSubs = new Set(['status', 'diff', 'log', 'branch']);
1422
+ export function evaluateDet02SecretBoundary(params = {}, _depth = 0) {
1423
+ if (_depth > 4) {
1424
+ return { detectorId: 'DET-02', triggered: false, decision: 'allow', reason: null };
1425
+ }
1426
+
1427
+ const toolName = String(params.toolName || 'Bash');
1428
+ const rawMode = String(params.mode ?? params.flightMode ?? 'guard').trim().toUpperCase();
1429
+ const isStrictAutoMode = rawMode === 'STRICT' || rawMode === 'AUTO' || rawMode === 'AUTO_PILOT';
1430
+ const gatedAskDecision = isStrictAutoMode ? 'deny' : 'ask';
1431
+ const secretAllow = Array.isArray(params.secretAllow) ? params.secretAllow : [];
1432
+
1433
+ let best = { detectorId: 'DET-02', triggered: false, decision: 'allow', reason: null };
1434
+
1435
+ const makeVerdict = (decision, normPath, modeHint = '') => ({
1436
+ detectorId: 'DET-02',
1437
+ triggered: true,
1438
+ decision,
1439
+ targetPath: normPath,
1440
+ reason:
1441
+ decision === 'ask'
1442
+ ? `[Burnoff DET-02 Secret & Credential Boundary] ${modeHint || 'Operation involving'} "${normPath}" requires confirmation.`
1443
+ : `[Burnoff DET-02 Secret & Credential Boundary] Access to sensitive credential path "${normPath}" is blocked. (.env.example / .env.sample are permitted.)`
1444
+ });
1445
+
1446
+ // 1. Direct file tool target (`Read`, `Grep`, `Glob`, `Edit`, `Write`, etc.)
1447
+ for (const rawField of [params.filePath, params.path]) {
1448
+ const norm = String(rawField || '').trim().replace(/\\/g, '/');
1449
+ if (!norm || !isConfidentalSecretPath(norm, secretAllow)) continue;
1450
+ if (EDIT_WRITE_TOOL_REGEX.test(toolName) || isNonPrivateCertPath(norm)) {
1451
+ best = pickStricterVerdict(best, makeVerdict(gatedAskDecision, norm, `${toolName} targeting`));
1452
+ } else {
1453
+ best = pickStricterVerdict(best, makeVerdict('deny', norm));
1454
+ }
1455
+ }
1456
+
1457
+ // 2. Shell command evaluation
1458
+ if (params.command && SHELL_TOOL_REGEX.test(toolName)) {
1459
+ const command = String(params.command);
1460
+ const isPowerShell = detectPowerShellSyntax(toolName, command);
1461
+
1462
+ for (const subCmd of extractCommandSubstitutions(command, { isPowerShell })) {
1463
+ const subVerdict = evaluateDet02SecretBoundary(
1464
+ {
1465
+ toolName: isPowerShell ? 'PowerShell' : toolName,
1466
+ command: subCmd,
1467
+ mode: params.mode,
1468
+ flightMode: params.flightMode,
1469
+ secretAllow
1470
+ },
1471
+ _depth + 1
1472
+ );
1473
+ best = pickStricterVerdict(best, subVerdict);
1474
+ }
1475
+
1476
+ const segments = splitCommandSegments(command, { isPowerShell });
1081
1477
  for (const seg of segments) {
1082
- const tokens = tokenizeShellSegment(seg, { isPowerShell });
1083
- if (tokens.length === 0) continue;
1084
- const bin = String(tokens[0] || '').split(/[\\/]/).pop().toLowerCase();
1085
- if (bin === 'echo' || bin === 'printf' || bin === 'write-output' || bin === 'write-host') {
1086
- continue;
1478
+ const rawTokens = tokenizeShellSegment(seg, { isPowerShell });
1479
+ if (rawTokens.length === 0) continue;
1480
+
1481
+ let binIdx = 0;
1482
+ while (binIdx < rawTokens.length && (rawTokens[binIdx] === '&' || splitEnvKeyValToken(rawTokens[binIdx]))) {
1483
+ binIdx += 1;
1087
1484
  }
1088
- if ((bin === 'git' || bin === 'git.exe') && benignGitSubs.has(String(tokens[1] || '').toLowerCase())) {
1089
- continue;
1485
+ if (binIdx >= rawTokens.length) continue;
1486
+
1487
+ let bin = String(rawTokens[binIdx] || '').split(/[\\/]/).pop().toLowerCase().replace(/\.exe$/i, '');
1488
+ if (bin === 'env' || bin === 'sudo' || bin === 'command') {
1489
+ let k = binIdx + 1;
1490
+ while (k < rawTokens.length && (rawTokens[k].startsWith('-') || splitEnvKeyValToken(rawTokens[k]))) {
1491
+ k += 1;
1492
+ }
1493
+ if (k < rawTokens.length) {
1494
+ binIdx = k;
1495
+ bin = String(rawTokens[binIdx] || '').split(/[\\/]/).pop().toLowerCase().replace(/\.exe$/i, '');
1496
+ }
1497
+ }
1498
+
1499
+ if (['bash', 'sh', 'zsh', 'dash'].includes(bin)) {
1500
+ const cPos = rawTokens.findIndex((t, ti) => ti > binIdx && (t === '-c' || /^-[a-zA-Z]*c$/.test(t)));
1501
+ if (cPos !== -1 && rawTokens[cPos + 1]) {
1502
+ best = pickStricterVerdict(
1503
+ best,
1504
+ evaluateDet02SecretBoundary(
1505
+ {
1506
+ toolName: 'Bash',
1507
+ command: rawTokens[cPos + 1],
1508
+ mode: params.mode,
1509
+ flightMode: params.flightMode,
1510
+ secretAllow
1511
+ },
1512
+ _depth + 1
1513
+ )
1514
+ );
1515
+ }
1516
+ } else if (bin === 'powershell' || bin === 'pwsh') {
1517
+ const cPos = rawTokens.findIndex(
1518
+ (t, ti) => ti > binIdx && /^(?:-c|-command)$/i.test(String(t || ''))
1519
+ );
1520
+ if (cPos !== -1 && rawTokens[cPos + 1]) {
1521
+ best = pickStricterVerdict(
1522
+ best,
1523
+ evaluateDet02SecretBoundary(
1524
+ {
1525
+ toolName: 'PowerShell',
1526
+ command: rawTokens[cPos + 1],
1527
+ mode: params.mode,
1528
+ flightMode: params.flightMode,
1529
+ secretAllow
1530
+ },
1531
+ _depth + 1
1532
+ )
1533
+ );
1534
+ }
1090
1535
  }
1091
- for (const tok of tokens) {
1092
- const cleaned = String(tok || '').replace(/^[<>&]+/, '').trim();
1093
- if (!cleaned) continue;
1094
- candidates.push(cleaned);
1095
- if (cleaned.startsWith('-') && cleaned.includes('=')) {
1096
- const val = cleaned.slice(cleaned.indexOf('=') + 1).trim();
1097
- if (val) candidates.push(val);
1536
+
1537
+ for (const scriptBody of extractInlineScriptPayloads(bin, rawTokens, binIdx)) {
1538
+ for (const cand of extractInlineScriptCandidates(scriptBody)) {
1539
+ const norm = cand.replace(/\\/g, '/');
1540
+ if (!norm || !isConfidentalSecretPath(norm, secretAllow)) continue;
1541
+ const decision = isNonPrivateCertPath(norm) ? gatedAskDecision : 'deny';
1542
+ best = pickStricterVerdict(best, makeVerdict(decision, norm, `Inline ${bin} script referencing`));
1098
1543
  }
1099
1544
  }
1100
- }
1101
- }
1102
1545
 
1103
- for (const rawTarget of candidates) {
1104
- const norm = String(rawTarget || '').trim().replace(/\\/g, '/');
1105
- if (!norm) continue;
1546
+ const isOutputBinOnly = bin === 'echo' || bin === 'printf' || bin === 'write-output' || bin === 'write-host';
1547
+ const isBenignGit = bin === 'git' && BENIGN_GIT_SUBCOMMANDS.has(String(rawTokens[binIdx + 1] || '').toLowerCase());
1548
+ const isReadExfilBin = SECRET_READ_EXFIL_BINS.has(bin);
1549
+ const isCopyMoveBin = COPY_MOVE_BINS.has(bin);
1106
1550
 
1107
- if (SAFE_ENV_ALLOWLIST_REGEX.test(norm)) {
1108
- continue;
1109
- }
1551
+ const candidates = [];
1552
+ const positionalArgs = [];
1553
+ let pendingRedirect = null;
1110
1554
 
1111
- for (const pattern of SECRET_FILE_PATTERNS) {
1112
- if (pattern.test(norm)) {
1113
- return {
1114
- detectorId: 'DET-02',
1115
- triggered: true,
1116
- decision: 'deny',
1117
- targetPath: norm,
1118
- reason: `[Burnoff DET-02 Secret & Credential Boundary] Access to sensitive credential path "${norm}" is blocked. (.env.example / .env.sample are permitted.)`
1119
- };
1555
+ for (let tIdx = binIdx + 1; tIdx < rawTokens.length; tIdx += 1) {
1556
+ const tok = String(rawTokens[tIdx] || '').trim();
1557
+ if (!tok) continue;
1558
+
1559
+ if (pendingRedirect === 'output') {
1560
+ pendingRedirect = null;
1561
+ candidates.push({ raw: tok.replace(/^[<>&]+/, ''), role: 'output_redirect' });
1562
+ continue;
1563
+ }
1564
+ if (pendingRedirect === 'stdin') {
1565
+ pendingRedirect = null;
1566
+ candidates.push({ raw: tok.replace(/^[<>&]+/, ''), role: 'stdin_redirect' });
1567
+ continue;
1568
+ }
1569
+ if (pendingRedirect === 'heredoc') {
1570
+ pendingRedirect = null;
1571
+ continue;
1572
+ }
1573
+
1574
+ const redir = extractRedirectTokenTarget(tok);
1575
+ if (redir) {
1576
+ if (redir.kind === 'output_op') pendingRedirect = 'output';
1577
+ else if (redir.kind === 'output_inline') candidates.push({ raw: redir.target, role: 'output_redirect' });
1578
+ else if (redir.kind === 'stdin_op') pendingRedirect = 'stdin';
1579
+ else if (redir.kind === 'stdin_inline') candidates.push({ raw: redir.target, role: 'stdin_redirect' });
1580
+ else if (redir.kind === 'heredoc_op') pendingRedirect = 'heredoc';
1581
+ continue;
1582
+ }
1583
+
1584
+ if (isOutputBinOnly || isBenignGit) {
1585
+ continue;
1586
+ }
1587
+
1588
+ const isOption = tok.startsWith('-');
1589
+ if (isOption && tok.includes('=')) {
1590
+ const val = tok.slice(tok.indexOf('=') + 1).trim();
1591
+ if (val) candidates.push({ raw: val, role: 'flag_val' });
1592
+ } else if (!isOption) {
1593
+ const posIdx = positionalArgs.length;
1594
+ positionalArgs.push(tok);
1595
+ candidates.push({ raw: tok, role: 'arg', posIdx });
1596
+ }
1597
+ }
1598
+
1599
+ for (const item of candidates) {
1600
+ const norm = String(item.raw || '').trim().replace(/\\/g, '/');
1601
+ if (!norm || !isConfidentalSecretPath(norm, secretAllow)) continue;
1602
+
1603
+ if (item.role === 'output_redirect') {
1604
+ best = pickStricterVerdict(best, makeVerdict(gatedAskDecision, norm, 'Output redirection to'));
1605
+ continue;
1606
+ }
1607
+ if (isNonPrivateCertPath(norm)) {
1608
+ best = pickStricterVerdict(best, makeVerdict(gatedAskDecision, norm, 'Certificate operation referencing'));
1609
+ continue;
1610
+ }
1611
+ if (item.role === 'stdin_redirect') {
1612
+ best = pickStricterVerdict(best, makeVerdict('deny', norm));
1613
+ continue;
1614
+ }
1615
+ if (isCopyMoveBin && item.role === 'arg') {
1616
+ const isFinalDestArg = positionalArgs.length >= 2 && item.posIdx === positionalArgs.length - 1;
1617
+ best = pickStricterVerdict(
1618
+ best,
1619
+ isFinalDestArg
1620
+ ? makeVerdict(gatedAskDecision, norm, `${bin} destination targeting`)
1621
+ : makeVerdict('deny', norm)
1622
+ );
1623
+ continue;
1624
+ }
1625
+ if (isReadExfilBin) {
1626
+ best = pickStricterVerdict(best, makeVerdict('deny', norm));
1627
+ } else {
1628
+ best = pickStricterVerdict(best, makeVerdict(gatedAskDecision, norm, `${bin || 'Command'} argument referencing`));
1629
+ }
1120
1630
  }
1121
1631
  }
1122
1632
  }
1123
1633
 
1124
- return { detectorId: 'DET-02', triggered: false, decision: 'allow', reason: null };
1634
+ return best;
1125
1635
  }
1126
1636
 
1127
1637
  /**