burnoff 1.0.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 (41) hide show
  1. package/.github/workflows/burnoff-pr-gate.yml +75 -0
  2. package/README.md +94 -20
  3. package/bin/burnoff.mjs +129 -30
  4. package/hooks/hook-io.mjs +27 -18
  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 +8 -5
  9. package/src/ci/ci-gate.mjs +84 -9
  10. package/src/ci/pr-cost.mjs +207 -22
  11. package/src/ci/team-digest.mjs +6 -4
  12. package/src/cli/audit.mjs +177 -23
  13. package/src/cli/doctor.mjs +230 -25
  14. package/src/cli/init.mjs +415 -75
  15. package/src/cli/startup-audit.mjs +2824 -0
  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/catalog.json +188 -45
  20. package/src/config/loader.mjs +96 -13
  21. package/src/config/paths.mjs +92 -2
  22. package/src/config/policy.mjs +103 -17
  23. package/src/config/pricing.mjs +1033 -0
  24. package/src/config/uncached-attribution.mjs +719 -0
  25. package/src/guards/loop-breaker.mjs +267 -24
  26. package/src/guards/post-tool-engine.mjs +316 -35
  27. package/src/guards/pre-tool-engine.mjs +389 -130
  28. package/src/guards/read-clamp.mjs +149 -75
  29. package/src/guards/session-hook.mjs +207 -0
  30. package/src/guards/shell-guard.mjs +610 -74
  31. package/src/ipc/daemon.mjs +50 -8
  32. package/src/ipc/fast-client.mjs +62 -5
  33. package/src/ipc/protocol.mjs +1 -1
  34. package/src/storage/antigravity-parser.mjs +258 -0
  35. package/src/storage/atomic-io.mjs +2 -2
  36. package/src/storage/file-lock.mjs +66 -13
  37. package/src/storage/fts5-archive.mjs +31 -16
  38. package/src/storage/jsonl-parser.mjs +209 -20
  39. package/src/storage/ledger.mjs +15 -10
  40. package/src/storage/sqlite-client.mjs +35 -11
  41. 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
  }
@@ -644,6 +726,26 @@ export function evaluateDet01GitAndShellSafety(params = {}, _depth = 0) {
644
726
  continue;
645
727
  }
646
728
 
729
+ function isExplicitTempTarget(normArg = '') {
730
+ return /^(?:\/tmp(?:\/|$)|\/var\/folders(?:\/|$)|\$tmpdir(?:\/|$)|\$\{tmpdir\}(?:\/|$)|\$\{?env:(?:temp|tmp)\}?[\\/]|(?:[a-z]:)?[\\/]?(?:temp|tmp)(?:\/|$))/i.test(
731
+ String(normArg || '').replace(/\\/g, '/')
732
+ );
733
+ }
734
+
735
+ function isProtectedRecursiveDeleteTarget(rawArg = '') {
736
+ const norm = String(rawArg || '').trim().replace(/^["']|["']$/g, '').replace(/\\/g, '/');
737
+ if (!norm || norm.startsWith('-')) return false;
738
+ if (isExplicitTempTarget(norm)) return false;
739
+ if (/^(?:\/+|\/\*|\~|\$HOME|\$\{HOME\}|\$env:USERPROFILE|[A-Za-z]:\/?)$/i.test(norm)) {
740
+ return true;
741
+ }
742
+ const stripped = norm.replace(/\/+$/, '').replace(/^\.\//, '');
743
+ if (norm === '.' || norm === './' || stripped === '' || stripped === '*') {
744
+ return true;
745
+ }
746
+ return /^(?:src|test|tests|__tests__)(?:\/\*|\/)?$/i.test(stripped);
747
+ }
748
+
647
749
  if (bin === 'rm' || bin === 'rm.exe' || bin === 'unlink' || bin === 'unlink.exe') {
648
750
  const rmArgs = rawTokens.slice(idx + 1);
649
751
  const hasRecursive = rmArgs.some(
@@ -652,16 +754,14 @@ export function evaluateDet01GitAndShellSafety(params = {}, _depth = 0) {
652
754
  const hasForce = rmArgs.some(
653
755
  (a) => a === '--force' || (/^-[a-zA-Z]+$/.test(a) && /f/.test(a))
654
756
  );
655
- const targetsRootOrHome = rmArgs.some((a) =>
656
- /^(?:\/+|\/\*|\~|\$HOME|\$\{HOME\}|[A-Za-z]:[\\/]?)$/i.test(a)
657
- );
757
+ const targetsRootOrHome = rmArgs.some((a) => isProtectedRecursiveDeleteTarget(a));
658
758
  if (hasRecursive && hasForce && targetsRootOrHome) {
659
759
  return {
660
760
  detectorId: 'DET-01',
661
761
  triggered: true,
662
762
  decision: 'deny',
663
763
  subType: 'DESTRUCTIVE_FS_WIPE',
664
- reason: '[Burnoff DET-01 Destructive Shell Blocked] Recursive root/home deletion is forbidden.'
764
+ reason: '[Burnoff DET-01 Destructive Shell Blocked] Recursive root/home/repo/src/test deletion is forbidden.'
665
765
  };
666
766
  }
667
767
  if (!userExplicitTestIntent) {
@@ -672,9 +772,9 @@ export function evaluateDet01GitAndShellSafety(params = {}, _depth = 0) {
672
772
  return {
673
773
  detectorId: 'DET-01',
674
774
  triggered: true,
675
- decision: 'deny',
775
+ decision: isStrictAutoMode ? 'deny' : 'ask',
676
776
  subType: 'TEST_FILE_DELETION',
677
- 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.`
678
778
  };
679
779
  }
680
780
  }
@@ -685,16 +785,14 @@ export function evaluateDet01GitAndShellSafety(params = {}, _depth = 0) {
685
785
  const psArgs = rawTokens.slice(idx + 1);
686
786
  const hasRecurse = psArgs.some((a) => /^-r(?:ecurse)?$/i.test(a));
687
787
  const hasForce = psArgs.some((a) => /^-f(?:orce)?$/i.test(a));
688
- const targetsRootOrHome = psArgs.some((a) =>
689
- /^(?:[A-Za-z]:[\\/]?|\/+|\~|\$HOME|\$env:USERPROFILE)$/i.test(a)
690
- );
788
+ const targetsRootOrHome = psArgs.some((a) => isProtectedRecursiveDeleteTarget(a));
691
789
  if (hasRecurse && hasForce && targetsRootOrHome) {
692
790
  return {
693
791
  detectorId: 'DET-01',
694
792
  triggered: true,
695
793
  decision: 'deny',
696
794
  subType: 'DESTRUCTIVE_FS_WIPE',
697
- reason: '[Burnoff DET-01 Destructive Shell Blocked] Recursive root/home deletion is forbidden.'
795
+ reason: '[Burnoff DET-01 Destructive Shell Blocked] Recursive root/home/repo/src/test deletion is forbidden.'
698
796
  };
699
797
  }
700
798
  if (!userExplicitTestIntent) {
@@ -705,9 +803,9 @@ export function evaluateDet01GitAndShellSafety(params = {}, _depth = 0) {
705
803
  return {
706
804
  detectorId: 'DET-01',
707
805
  triggered: true,
708
- decision: 'deny',
806
+ decision: isStrictAutoMode ? 'deny' : 'ask',
709
807
  subType: 'TEST_FILE_DELETION',
710
- 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.`
711
809
  };
712
810
  }
713
811
  }
@@ -775,6 +873,21 @@ export function evaluateDet01GitAndShellSafety(params = {}, _depth = 0) {
775
873
 
776
874
  const subArgs = rawTokens.slice(idx);
777
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
+
778
891
  if (subcommand === 'config') {
779
892
  let isReadOnlyQuery = false;
780
893
  const positional = [];
@@ -1048,54 +1161,477 @@ export function evaluateDet01GitAndShellSafety(params = {}, _depth = 0) {
1048
1161
  return { detectorId: 'DET-01', triggered: false, decision: 'allow', reason: null };
1049
1162
  }
1050
1163
 
1051
- /**
1052
- * DET-02: Secret & Credential Boundary.
1053
- * Blocks access to `.env*`, `*.pem`, `~/.ssh/*`, `~/.aws/*` while explicitly allowlisting
1054
- * `.env.example`, `.env.sample`, `.env.template`, `.env.defaults`, `.env.schema`.
1055
- */
1056
- export function evaluateDet02SecretBoundary(params = {}) {
1057
- const candidates = [];
1058
- if (params.filePath) candidates.push(String(params.filePath));
1059
- if (params.path) candidates.push(String(params.path));
1060
-
1061
- if (params.command && SHELL_TOOL_REGEX.test(String(params.toolName || 'Bash'))) {
1062
- const tokens = tokenizeShellSegment(String(params.command));
1063
- for (const tok of tokens) {
1064
- if (
1065
- tok.includes('.env') ||
1066
- tok.includes('.pem') ||
1067
- tok.includes('.ssh') ||
1068
- tok.includes('.aws') ||
1069
- tok.includes('id_rsa') ||
1070
- tok.includes('id_ed25519')
1071
- ) {
1072
- candidates.push(tok);
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 += '[^/]*';
1073
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;
1074
1273
  }
1075
1274
  }
1275
+ out += '$';
1276
+ return new RegExp(out, 'i');
1277
+ }
1076
1278
 
1077
- for (const rawTarget of candidates) {
1078
- const norm = String(rawTarget || '').trim().replace(/\\/g, '/');
1079
- if (!norm) continue;
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
+ }
1080
1307
 
1081
- if (SAFE_ENV_ALLOWLIST_REGEX.test(norm)) {
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;
1082
1354
  continue;
1083
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
+ }
1084
1363
 
1085
- for (const pattern of SECRET_FILE_PATTERNS) {
1086
- if (pattern.test(norm)) {
1087
- return {
1088
- detectorId: 'DET-02',
1089
- triggered: true,
1090
- decision: 'deny',
1091
- targetPath: norm,
1092
- reason: `[Burnoff DET-02 Secret & Credential Boundary] Access to sensitive credential path "${norm}" is blocked. (.env.example / .env.sample are permitted.)`
1093
- };
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
+
1416
+ /**
1417
+ * DET-02: Secret & Credential Boundary.
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`.
1421
+ */
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 });
1477
+ for (const seg of segments) {
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;
1484
+ }
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
+ }
1535
+ }
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`));
1543
+ }
1544
+ }
1545
+
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);
1550
+
1551
+ const candidates = [];
1552
+ const positionalArgs = [];
1553
+ let pendingRedirect = null;
1554
+
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
+ }
1094
1630
  }
1095
1631
  }
1096
1632
  }
1097
1633
 
1098
- return { detectorId: 'DET-02', triggered: false, decision: 'allow', reason: null };
1634
+ return best;
1099
1635
  }
1100
1636
 
1101
1637
  /**