@code-sentinel-cli/code-sentinel-cli 4.0.1 → 4.0.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.
Files changed (31) hide show
  1. package/dist/bin.js +31883 -26866
  2. package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.prompt.md +47 -8
  3. package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.rule.yaml +1 -1
  4. package/dist/builtin-rules/ai/spring-boot/state-transition-guard-risk.prompt.md +128 -0
  5. package/dist/builtin-rules/ai/spring-boot/state-transition-guard-risk.rule.yaml +27 -0
  6. package/dist/builtin-rules/static/angular/sensitive-input-masking.rule.js +97 -0
  7. package/dist/builtin-rules/static/flutter/android-debug-certificate-risk.rule.js +140 -0
  8. package/dist/builtin-rules/static/flutter/android-minsdk-low.rule.js +108 -0
  9. package/dist/builtin-rules/static/general/dockerfile-dependency-confusion.rule.js +34 -0
  10. package/dist/builtin-rules/static/general/dockerfile-no-root-user.rule.js +37 -0
  11. package/dist/builtin-rules/static/general/html-password-autocomplete-off.rule.js +34 -0
  12. package/dist/builtin-rules/static/general/no-client-identity-header.rule.js +47 -0
  13. package/dist/builtin-rules/static/general/no-empty-encryption-key.rule.js +79 -0
  14. package/dist/builtin-rules/static/general/no-guessable-websql-database-name.rule.js +39 -0
  15. package/dist/builtin-rules/static/general/no-hardcoded-secret.rule.js +22 -3
  16. package/dist/builtin-rules/static/general/no-insecure-external-link.rule.js +52 -0
  17. package/dist/builtin-rules/static/general/no-insecure-password-submission.rule.js +75 -0
  18. package/dist/builtin-rules/static/general/no-reflective-access-override.rule.js +50 -0
  19. package/dist/builtin-rules/static/general/no-sensitive-string-materialization.rule.js +124 -0
  20. package/dist/builtin-rules/static/general/no-unsafe-html-sink.rule.js +65 -0
  21. package/dist/builtin-rules/static/general/sensitive-output-exposure.rule.js +30 -0
  22. package/dist/builtin-rules/static/spring-boot/mfa-enforcement-required.rule.js +110 -0
  23. package/dist/builtin-rules/static/spring-boot/no-cleartext-http-client.rule.js +53 -0
  24. package/dist/builtin-rules/static/spring-boot/no-devtools-in-production.rule.js +37 -0
  25. package/dist/builtin-rules/static/spring-boot/no-print-stack-trace.rule.js +71 -0
  26. package/dist/builtin-rules/static/spring-boot/no-sensitive-config-response.rule.js +53 -0
  27. package/dist/builtin-rules/static/spring-boot/no-weak-tls-protocol.rule.js +57 -0
  28. package/dist/builtin-rules/static/spring-boot/password-expiration-policy.rule.js +104 -0
  29. package/dist/index.js +31882 -26865
  30. package/node_modules/@code-sentinel/parsers/index.js +527 -6
  31. package/package.json +1 -1
@@ -1,13 +1,534 @@
1
- export const asTreeSitterTree = (parsed) => {
2
- if (parsed.layer !== 'syntactic') {
1
+ // src/security/insecure-transport-scan.ts
2
+ var isExcludedHost = (hostWithPort) => {
3
+ const h = hostWithPort.replace(/:\d+$/, "").toLowerCase();
4
+ if (h === "localhost" || h === "0.0.0.0" || h === "::1") return true;
5
+ if (/^127\.\d+\.\d+\.\d+$/.test(h)) return true;
6
+ if (h.startsWith("schemas.") || h.startsWith("schema.")) return true;
7
+ return /(?:^|\.)(?:w3\.org|example\.(?:com|org|net)|java\.sun\.com|xml\.org|purl\.org|springframework\.org|slf4j\.org|jboss\.org)$/.test(
8
+ h
9
+ );
10
+ };
11
+
12
+ // src/security/devtools-scan.ts
13
+ var BUILD_FILE_RE = /(?:^|[/\\])(?:pom\.xml|build\.gradle|build\.gradle\.kts)$/i;
14
+ var auditPomXmlDevTools = (content, filePath) => {
15
+ if (!content.includes("spring-boot-devtools")) {
16
+ return null;
17
+ }
18
+ const depBlockRegex = /<dependency\b[\s\S]*?<\/dependency>/gi;
19
+ let match = depBlockRegex.exec(content);
20
+ while (match !== null) {
21
+ const block = match[0];
22
+ if (block.includes("spring-boot-devtools")) {
23
+ const hasOptional = /<optional\s*>\s*true\s*<\/optional>/i.test(block);
24
+ const isTestScope = /<scope\s*>\s*test\s*<\/scope>/i.test(block);
25
+ const before = content.slice(0, match.index);
26
+ const line = before.split("\n").length;
27
+ if (!hasOptional && !isTestScope) {
28
+ return {
29
+ file: filePath,
30
+ line,
31
+ isVulnerable: true,
32
+ reason: "Dependency 'spring-boot-devtools' khai b\xE1o thi\u1EBFu '<optional>true</optional>' trong pom.xml \u2014 nguy c\u01A1 b\u1ECB \u0111\xF3ng g\xF3i v\xE0o b\u1EA3n production (CWE-489)."
33
+ };
34
+ }
35
+ }
36
+ match = depBlockRegex.exec(content);
37
+ }
38
+ return null;
39
+ };
40
+ var auditGradleDevTools = (content, filePath) => {
41
+ if (!content.includes("spring-boot-devtools")) {
42
+ return null;
43
+ }
44
+ const cleaned = content.replace(/\/\/[^\n]*/g, (m) => " ".repeat(m.length)).replace(/\/\*[\s\S]*?\*\//g, (m) => " ".repeat(m.length));
45
+ const gradleDepRe = /\b(implementation|compileOnly|api|runtimeOnly|compile|developmentOnly)\s*(?:\(?\s*["'][^"']*spring-boot-devtools[^"']*["']\s*\)?)/gi;
46
+ let match = gradleDepRe.exec(cleaned);
47
+ while (match !== null) {
48
+ const config = match[1] ?? "";
49
+ if (!/\bdevelopmentOnly\b/i.test(config)) {
50
+ const before = content.slice(0, match.index);
51
+ const line = before.split("\n").length;
52
+ return {
53
+ file: filePath,
54
+ line,
55
+ isVulnerable: true,
56
+ reason: "Dependency 'spring-boot-devtools' \u0111\u01B0\u1EE3c khai b\xE1o b\u1EB1ng c\u1EA5u h\xECnh kh\xF4ng an to\xE0n (thay v\xEC 'developmentOnly') trong Gradle \u2014 nguy c\u01A1 b\u1ECB \u0111\xF3ng g\xF3i v\xE0o b\u1EA3n production (CWE-489)."
57
+ };
58
+ }
59
+ match = gradleDepRe.exec(cleaned);
60
+ }
61
+ return null;
62
+ };
63
+ var auditBuildFile = (content, filePath) => {
64
+ const lowerPath = filePath.toLowerCase();
65
+ if (lowerPath.endsWith("pom.xml")) {
66
+ return auditPomXmlDevTools(content, filePath);
67
+ }
68
+ if (lowerPath.endsWith("build.gradle") || lowerPath.endsWith("build.gradle.kts")) {
69
+ return auditGradleDevTools(content, filePath);
70
+ }
71
+ return null;
72
+ };
73
+
74
+ // src/security/java-comment-mask.ts
75
+ var maskJavaComments = (content) => {
76
+ if (!content.includes("//") && !content.includes("/*")) return content;
77
+ const out = content.split("");
78
+ const n = content.length;
79
+ let state = "code";
80
+ let i = 0;
81
+ while (i < n) {
82
+ const c = content[i];
83
+ const next = content[i + 1];
84
+ if (state === "code") {
85
+ if (c === "/" && next === "/") {
86
+ out[i] = " ";
87
+ out[i + 1] = " ";
88
+ state = "line-comment";
89
+ i += 2;
90
+ } else if (c === "/" && next === "*") {
91
+ out[i] = " ";
92
+ out[i + 1] = " ";
93
+ state = "block-comment";
94
+ i += 2;
95
+ } else {
96
+ if (c === '"') state = "string";
97
+ else if (c === "'") state = "char";
98
+ i += 1;
99
+ }
100
+ continue;
101
+ }
102
+ if (state === "line-comment") {
103
+ if (c === "\n") state = "code";
104
+ else out[i] = " ";
105
+ i += 1;
106
+ continue;
107
+ }
108
+ if (state === "block-comment") {
109
+ if (c === "*" && next === "/") {
110
+ out[i] = " ";
111
+ out[i + 1] = " ";
112
+ state = "code";
113
+ i += 2;
114
+ } else {
115
+ if (c !== "\n") out[i] = " ";
116
+ i += 1;
117
+ }
118
+ continue;
119
+ }
120
+ if (c === "\\") {
121
+ i += 2;
122
+ continue;
123
+ }
124
+ if (c === "\n") {
125
+ state = "code";
126
+ i += 1;
127
+ continue;
128
+ }
129
+ if (state === "string" && c === '"' || state === "char" && c === "'") state = "code";
130
+ i += 1;
131
+ }
132
+ return out.join("");
133
+ };
134
+ var maskedCorpusCache = /* @__PURE__ */ new WeakMap();
135
+ var maskJavaFiles = (files) => {
136
+ const cached = maskedCorpusCache.get(files);
137
+ if (cached) return cached;
138
+ const masked = files.map(
139
+ (f) => f.path.endsWith(".java") ? { ...f, content: maskJavaComments(f.content) } : f
140
+ );
141
+ maskedCorpusCache.set(files, masked);
142
+ return masked;
143
+ };
144
+
145
+ // src/security/dockerfile-scan.ts
146
+ var DOCKERFILE_RE = /(?:^|[/\\])(?:Dockerfile(?:\.[A-Za-z0-9_.-]+)?|[^/\\]*\.dockerfile)$/i;
147
+ var isLoopback = (host) => {
148
+ const h = host.toLowerCase();
149
+ return h === "localhost" || h === "127.0.0.1" || h === "0.0.0.0" || h === "::1";
150
+ };
151
+ var auditDockerfileDependencyConfusion = (content, filePath) => {
152
+ const lines = content.split("\n");
153
+ const hits = [];
154
+ for (let i = 0; i < lines.length; i++) {
155
+ const rawLine = lines[i] ?? "";
156
+ const trimmed = rawLine.trim();
157
+ if (!trimmed || trimmed.startsWith("#")) continue;
158
+ if (/pip(?:\d+)?\s+install\b.*--extra-index-url/i.test(trimmed)) {
159
+ hits.push({
160
+ file: filePath,
161
+ line: i + 1,
162
+ reason: "Dockerfile s\u1EED d\u1EE5ng `pip install --extra-index-url` g\xE2y nguy c\u01A1 Dependency Confusion (pip \u01B0u ti\xEAn package tr\xF9ng t\xEAn c\xF3 version cao h\u01A1n tr\xEAn PyPI c\xF4ng khai) \u2014 CWE-427."
163
+ });
164
+ continue;
165
+ }
166
+ const trustedMatch = trimmed.match(/pip(?:\d+)?\s+install\b.*--trusted-host\s+([^\s\\]+)/i);
167
+ if (trustedMatch) {
168
+ const host = trustedMatch[1]?.trim() ?? "";
169
+ if (host && !isLoopback(host)) {
170
+ hits.push({
171
+ file: filePath,
172
+ line: i + 1,
173
+ reason: `Dockerfile s\u1EED d\u1EE5ng \`--trusted-host ${host}\` b\u1ECF qua x\xE1c th\u1EF1c SSL/TLS cho kho th\u01B0 vi\u1EC7n \u2014 CWE-829.`
174
+ });
175
+ continue;
176
+ }
177
+ }
178
+ if (/pip(?:\d+)?\s+install\b.*--index-url\s+http:\/\//i.test(trimmed) || /(?:npm|yarn)\s+config\s+set\s+registry\s+http:\/\//i.test(trimmed)) {
179
+ hits.push({
180
+ file: filePath,
181
+ line: i + 1,
182
+ reason: "Dockerfile c\u1EA5u h\xECnh kho th\u01B0 vi\u1EC7n (registry) qua giao th\u1EE9c HTTP kh\xF4ng m\xE3 h\xF3a (cleartext) \u2014 CWE-319."
183
+ });
184
+ }
185
+ }
186
+ return hits;
187
+ };
188
+ var auditDockerfileContent = (content, filePath) => {
189
+ const lines = content.split("\n");
190
+ const stages = [];
191
+ let currentStage = null;
192
+ for (let i = 0; i < lines.length; i++) {
193
+ const rawLine = lines[i] ?? "";
194
+ const trimmed = rawLine.trim();
195
+ if (!trimmed || trimmed.startsWith("#")) continue;
196
+ const fromMatch = trimmed.match(/^FROM\s+(\S+)/i);
197
+ if (fromMatch) {
198
+ currentStage = {
199
+ fromLine: i + 1,
200
+ baseImage: fromMatch[1] ?? ""
201
+ };
202
+ stages.push(currentStage);
203
+ continue;
204
+ }
205
+ const userMatch = trimmed.match(/^USER\s+(\S+)/i);
206
+ if (userMatch && currentStage) {
207
+ currentStage.lastUser = {
208
+ name: userMatch[1] ?? "",
209
+ line: i + 1
210
+ };
211
+ }
212
+ }
213
+ const finalStage = stages[stages.length - 1];
214
+ if (!finalStage) {
215
+ return {
216
+ file: filePath,
217
+ isRoot: true,
218
+ line: 1,
219
+ reason: "Dockerfile kh\xF4ng ch\u1EE9a ch\u1EC9 th\u1ECB FROM h\u1EE3p l\u1EC7"
220
+ };
221
+ }
222
+ if (!finalStage.lastUser) {
223
+ return {
224
+ file: filePath,
225
+ isRoot: true,
226
+ line: finalStage.fromLine,
227
+ reason: `Dockerfile (stage '${finalStage.baseImage}') kh\xF4ng khai b\xE1o ch\u1EC9 th\u1ECB USER non-root \u2192 container s\u1EBD m\u1EB7c \u0111\u1ECBnh ch\u1EA1y v\u1EDBi quy\u1EC1n root (UID 0).`
228
+ };
229
+ }
230
+ const userName = finalStage.lastUser.name.toLowerCase();
231
+ if (userName === "root" || userName === "0" || userName === "0:0" || userName === "root:root") {
232
+ return {
233
+ file: filePath,
234
+ isRoot: true,
235
+ line: finalStage.lastUser.line,
236
+ user: finalStage.lastUser.name,
237
+ reason: `Dockerfile khai b\xE1o USER l\xE0 '${finalStage.lastUser.name}' (quy\u1EC1n root/UID 0) \u2192 vi ph\u1EA1m nguy\xEAn t\u1EAFc \u0111\u1EB7c quy\u1EC1n t\u1ED1i thi\u1EC3u (CWE-250).`
238
+ };
239
+ }
240
+ return {
241
+ file: filePath,
242
+ isRoot: false,
243
+ line: finalStage.lastUser.line,
244
+ user: finalStage.lastUser.name,
245
+ reason: `Dockerfile c\u1EA5u h\xECnh USER non-root h\u1EE3p l\u1EC7: '${finalStage.lastUser.name}'.`
246
+ };
247
+ };
248
+
249
+ // src/security/password-autocomplete-scan.ts
250
+ var HTML_TEMPLATE_FILE_RE = /(?:^|[/\\])[^/\\]+\.(?:html|xhtml|jsp|ftl)$/i;
251
+ var SECURE_AUTOCOMPLETE_VALUES = /* @__PURE__ */ new Set([
252
+ "off",
253
+ "new-password",
254
+ "current-password",
255
+ "one-time-code"
256
+ ]);
257
+ var auditPasswordAutocompleteContent = (content, filePath) => {
258
+ const findings = [];
259
+ const cleaned = content.replace(/<!--[\s\S]*?-->/g, (m) => " ".repeat(m.length));
260
+ const inputRegex = /<input\b([^>]*?)>/gi;
261
+ let match = inputRegex.exec(cleaned);
262
+ while (match !== null) {
263
+ const attrsString = match[1] ?? "";
264
+ const isPasswordInput = /(?:^|\s)type\s*=\s*["']password["']/i.test(attrsString) || /(?:^|\s)\[type\]\s*=\s*["'](?:'password'|"password")["']/i.test(attrsString);
265
+ if (isPasswordInput) {
266
+ const autocompleteMatch = attrsString.match(/\bautocomplete\s*=\s*["']([^"']+)["']/i);
267
+ const autocompleteVal = autocompleteMatch ? autocompleteMatch[1]?.toLowerCase().trim() ?? "" : "";
268
+ const isSecure = SECURE_AUTOCOMPLETE_VALUES.has(autocompleteVal);
269
+ if (!isSecure) {
270
+ const before = content.slice(0, match.index);
271
+ const line = before.split("\n").length;
272
+ const snippet = match[0].slice(0, 100);
273
+ findings.push({
274
+ file: filePath,
275
+ line,
276
+ snippet,
277
+ reason: autocompleteMatch ? `Tr\u01B0\u1EDDng password ch\u1EC9 \u0111\u1ECBnh 'autocomplete="${autocompleteVal}"' kh\xF4ng an to\xE0n. C\u1EA7n c\u1EA5u h\xECnh 'autocomplete="off"' ho\u1EB7c 'new-password' (CWE-522).` : `Tr\u01B0\u1EDDng password thi\u1EBFu thu\u1ED9c t\xEDnh 'autocomplete="off"' ho\u1EB7c 'new-password' (CWE-522).`
278
+ });
279
+ }
280
+ }
281
+ match = inputRegex.exec(content);
282
+ }
283
+ return findings;
284
+ };
285
+
286
+ // src/security/js-comment-mask.ts
287
+ var REGEX_PRECEDING_KEYWORDS = /* @__PURE__ */ new Set([
288
+ "return",
289
+ "typeof",
290
+ "instanceof",
291
+ "in",
292
+ "of",
293
+ "new",
294
+ "delete",
295
+ "void",
296
+ "throw",
297
+ "case",
298
+ "do",
299
+ "else",
300
+ "yield",
301
+ "await"
302
+ ]);
303
+ var isIdentChar = (c) => /[A-Za-z0-9_$]/.test(c);
304
+ var regexAllowedAt = (content, index) => {
305
+ let i = index - 1;
306
+ while (i >= 0 && /\s/.test(content[i] ?? "")) i -= 1;
307
+ if (i < 0) return true;
308
+ const prev = content[i] ?? "";
309
+ if (prev === ")" || prev === "]") return false;
310
+ if (!isIdentChar(prev)) return true;
311
+ let start = i;
312
+ while (start >= 0 && isIdentChar(content[start] ?? "")) start -= 1;
313
+ const word = content.slice(start + 1, i + 1);
314
+ if (/^[0-9]/.test(word)) return false;
315
+ return REGEX_PRECEDING_KEYWORDS.has(word);
316
+ };
317
+ var maskJsComments = (content) => {
318
+ if (!content.includes("//") && !content.includes("/*")) return content;
319
+ const out = content.split("");
320
+ const n = content.length;
321
+ const templateStack = [];
322
+ let braceDepth = 0;
323
+ let inCharClass = false;
324
+ let state = "code";
325
+ let i = 0;
326
+ const blank = (at) => {
327
+ if (content[at] !== "\n") out[at] = " ";
328
+ };
329
+ while (i < n) {
330
+ const c = content[i] ?? "";
331
+ const next = content[i + 1] ?? "";
332
+ if (state === "code") {
333
+ if (c === "/" && next === "/") {
334
+ blank(i);
335
+ blank(i + 1);
336
+ state = "line";
337
+ i += 2;
338
+ } else if (c === "/" && next === "*") {
339
+ blank(i);
340
+ blank(i + 1);
341
+ state = "block";
342
+ i += 2;
343
+ } else if (c === "/" && regexAllowedAt(content, i)) {
344
+ state = "regex";
345
+ inCharClass = false;
346
+ i += 1;
347
+ } else if (c === "'") {
348
+ state = "single";
349
+ i += 1;
350
+ } else if (c === '"') {
351
+ state = "double";
352
+ i += 1;
353
+ } else if (c === "`") {
354
+ state = "template";
355
+ i += 1;
356
+ } else if (c === "{") {
357
+ braceDepth += 1;
358
+ i += 1;
359
+ } else if (c === "}") {
360
+ braceDepth -= 1;
361
+ const top = templateStack[templateStack.length - 1];
362
+ if (top !== void 0 && braceDepth === top) {
363
+ templateStack.pop();
364
+ state = "template";
365
+ }
366
+ i += 1;
367
+ } else {
368
+ i += 1;
369
+ }
370
+ continue;
371
+ }
372
+ if (state === "line") {
373
+ if (c === "\n") state = "code";
374
+ else blank(i);
375
+ i += 1;
376
+ continue;
377
+ }
378
+ if (state === "block") {
379
+ if (c === "*" && next === "/") {
380
+ blank(i);
381
+ blank(i + 1);
382
+ state = "code";
383
+ i += 2;
384
+ } else {
385
+ blank(i);
386
+ i += 1;
387
+ }
388
+ continue;
389
+ }
390
+ if (state === "template") {
391
+ if (c === "\\") {
392
+ i += 2;
393
+ continue;
394
+ }
395
+ if (c === "$" && next === "{") {
396
+ templateStack.push(braceDepth);
397
+ braceDepth += 1;
398
+ state = "code";
399
+ i += 2;
400
+ continue;
401
+ }
402
+ if (c === "`") state = "code";
403
+ i += 1;
404
+ continue;
405
+ }
406
+ if (state === "regex") {
407
+ if (c === "\\") {
408
+ i += 2;
409
+ continue;
410
+ }
411
+ if (c === "[") inCharClass = true;
412
+ else if (c === "]") inCharClass = false;
413
+ else if (c === "/" && !inCharClass) state = "code";
414
+ else if (c === "\n") state = "code";
415
+ i += 1;
416
+ continue;
417
+ }
418
+ if (c === "\\") {
419
+ i += 2;
420
+ continue;
421
+ }
422
+ if (c === "\n") {
423
+ state = "code";
424
+ i += 1;
425
+ continue;
426
+ }
427
+ if (state === "single" && c === "'" || state === "double" && c === '"') state = "code";
428
+ i += 1;
429
+ }
430
+ return out.join("");
431
+ };
432
+
433
+ // src/security/sensitive-logging-scan.ts
434
+ var MAX_EVIDENCE = 50;
435
+ var lineOf = (content, index) => {
436
+ let line = 1;
437
+ for (let i = 0; i < index && i < content.length; i++) {
438
+ if (content[i] === "\n") line++;
439
+ }
440
+ return line;
441
+ };
442
+ var JAVA_LOG_CALL_RE = /\b(?:log|logger)\s*\.\s*(?:trace|debug|info|warn|error)\s*\(([^;]{0,500}?)\)\s*;/gi;
443
+ var JAVA_CONSOLE_CALL_RE = /\bSystem\s*\.\s*(?:out|err)\s*\.\s*(?:print|println|printf)\s*\(([^;]{0,500}?)\)\s*;?/g;
444
+ var JS_CONSOLE_CALL_RE = /\bconsole\s*\.\s*(?:log|info|debug|warn|error)\s*\(([^;]{0,500}?)\)\s*;?/gi;
445
+ var stripStringLiterals = (s) => s.replace(/"(?:[^"\\]|\\.)*"/g, "");
446
+ var SECRET_RE = /\b\w*(?:password|passwd|pwd|secret|apikey|api_key|credential|privatekey|jwt|otp|pin|token|authorization|accesskey)\w*\b/gi;
447
+ var PII_RE = /\b(?:cvv|cvc|cvv2|ssn|socialsecurity|cccd|socccd|cmnd|socmnd|cmt|creditcard|cardnumber|cardno|sothe|sotaikhoan|stk|taikhoannganhang|passport|passportno|nationalid|sohochieu|geolocation|latitude|longitude|coordinates)\b/gi;
448
+ var PROTECTED_TAIL_RE = /(?:hash|hashed|encoded|encrypted|digest|salt|policy|type|name|length|format|masked|redacted|id)$/i;
449
+ var findSensitiveToken = (code) => {
450
+ for (const m of code.matchAll(SECRET_RE)) {
451
+ const token = m[0];
452
+ if (PROTECTED_TAIL_RE.test(token)) continue;
453
+ return { token, confidence: 75 };
454
+ }
455
+ for (const m of code.matchAll(PII_RE)) {
456
+ return { token: m[0], confidence: 70 };
457
+ }
458
+ return null;
459
+ };
460
+ var collectSensitiveContainers = (content) => {
461
+ const containers = /* @__PURE__ */ new Map();
462
+ const writeRe = /\b([A-Za-z_$][\w$]*)\s*\.\s*(?:put|set[A-Za-z_$][\w$]*)\s*\(([^;\n]{0,500})\)\s*;/g;
463
+ for (const m of content.matchAll(writeRe)) {
464
+ const receiver = m[1];
465
+ const args = m[2] ?? "";
466
+ if (!receiver) continue;
467
+ const valueArg = args.includes(",") ? args.slice(args.lastIndexOf(",") + 1) : args;
468
+ const found = findSensitiveToken(stripStringLiterals(valueArg));
469
+ if (found) containers.set(receiver, found);
470
+ }
471
+ return containers;
472
+ };
473
+ var findSensitiveArgument = (args, containers) => {
474
+ const code = stripStringLiterals(args);
475
+ const direct = findSensitiveToken(code);
476
+ if (direct) return direct;
477
+ for (const [container, value] of containers) {
478
+ if (new RegExp(`\\b${container}\\b`).test(code)) return value;
479
+ }
480
+ return null;
481
+ };
482
+ var findSensitiveOutput = (files) => {
483
+ const hits = [];
484
+ for (const original of files) {
485
+ if (!["java", "typescript", "javascript"].includes(original.language)) continue;
486
+ const f = original.language === "java" ? maskJavaFiles([original])[0] ?? original : original;
487
+ const containers = collectSensitiveContainers(f.content);
488
+ const patterns = f.language === "java" ? [
489
+ { re: JAVA_LOG_CALL_RE, sink: "java-logger" },
490
+ { re: JAVA_CONSOLE_CALL_RE, sink: "java-console" }
491
+ ] : [{ re: JS_CONSOLE_CALL_RE, sink: "js-console" }];
492
+ for (const { re, sink } of patterns) {
493
+ re.lastIndex = 0;
494
+ for (const m of f.content.matchAll(re)) {
495
+ const found = findSensitiveArgument(m[1] ?? "", containers);
496
+ if (!found) continue;
497
+ hits.push({
498
+ file: f.path,
499
+ line: lineOf(f.content, m.index ?? 0),
500
+ note: `Ghi GI\xC1 TR\u1ECA nh\u1EA1y c\u1EA3m "${found.token}" ra ${sink === "js-console" ? "browser console" : "log/console"} (CWE-532) \u2014 d\u1EEF li\u1EC7u b\xED m\u1EADt/nh\u1EA1y c\u1EA3m c\xF3 th\u1EC3 b\u1ECB ng\u01B0\u1EDDi v\u1EADn h\xE0nh, tr\xECnh duy\u1EC7t ho\u1EB7c attacker \u0111\u1ECDc. B\u1ECF kh\u1ECFi output ho\u1EB7c mask; verify \u0111\xE2y l\xE0 gi\xE1 tr\u1ECB th\u1EADt ch\u1EE9 kh\xF4ng ph\u1EA3i hash/\u0111\xE3 che.`,
501
+ confidence: found.confidence,
502
+ sink
503
+ });
504
+ }
505
+ }
506
+ }
507
+ const seen = /* @__PURE__ */ new Set();
508
+ return hits.sort((a, b) => a.file === b.file ? a.line - b.line : a.file < b.file ? -1 : 1).filter((h) => {
509
+ const key = `${h.file}:${h.line}:${h.note}`;
510
+ if (seen.has(key)) return false;
511
+ seen.add(key);
512
+ return true;
513
+ }).slice(0, MAX_EVIDENCE);
514
+ };
515
+
516
+ // src/rules-runtime.ts
517
+ var asTreeSitterTree = (parsed) => {
518
+ if (parsed.layer !== "syntactic") {
3
519
  throw new Error(`asTreeSitterTree called on layer '${parsed.layer}' - expected 'syntactic'`);
4
520
  }
5
521
  return parsed.ast;
6
522
  };
7
-
8
- export const asTsMorphSourceFile = (parsed) => {
9
- if (parsed.layer !== 'semantic-ts') {
10
- throw new Error(`asTsMorphSourceFile called on layer '${parsed.layer}' - expected 'semantic-ts'`);
523
+ var asTsMorphSourceFile = (parsed) => {
524
+ if (parsed.layer !== "semantic-ts") {
525
+ throw new Error(
526
+ `asTsMorphSourceFile called on layer '${parsed.layer}' - expected 'semantic-ts'`
527
+ );
11
528
  }
12
529
  return parsed.ast;
13
530
  };
531
+
532
+ export { BUILD_FILE_RE as DEVTOOLS_BUILD_FILE_RE, DOCKERFILE_RE, HTML_TEMPLATE_FILE_RE, asTreeSitterTree, asTsMorphSourceFile, auditBuildFile, auditDockerfileContent, auditDockerfileDependencyConfusion, auditPasswordAutocompleteContent, findSensitiveOutput, isExcludedHost, maskJavaFiles, maskJsComments };
533
+ //# sourceMappingURL=rules-runtime.js.map
534
+ //# sourceMappingURL=rules-runtime.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-sentinel-cli/code-sentinel-cli",
3
- "version": "4.0.1",
3
+ "version": "4.0.3",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "AI-assisted code review CLI for Angular, Spring Boot, and Flutter projects.",