circle-ir 3.51.0 → 3.52.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 (30) hide show
  1. package/dist/analysis/config-loader.d.ts.map +1 -1
  2. package/dist/analysis/config-loader.js +9 -19
  3. package/dist/analysis/config-loader.js.map +1 -1
  4. package/dist/analysis/passes/insecure-cookie-pass.d.ts +23 -23
  5. package/dist/analysis/passes/insecure-cookie-pass.d.ts.map +1 -1
  6. package/dist/analysis/passes/insecure-cookie-pass.js +169 -79
  7. package/dist/analysis/passes/insecure-cookie-pass.js.map +1 -1
  8. package/dist/analysis/passes/tls-verify-disabled-pass.d.ts +52 -0
  9. package/dist/analysis/passes/tls-verify-disabled-pass.d.ts.map +1 -0
  10. package/dist/analysis/passes/tls-verify-disabled-pass.js +247 -0
  11. package/dist/analysis/passes/tls-verify-disabled-pass.js.map +1 -0
  12. package/dist/analysis/passes/weak-crypto-pass.d.ts +49 -0
  13. package/dist/analysis/passes/weak-crypto-pass.d.ts.map +1 -0
  14. package/dist/analysis/passes/weak-crypto-pass.js +223 -0
  15. package/dist/analysis/passes/weak-crypto-pass.js.map +1 -0
  16. package/dist/analysis/passes/weak-hash-pass.d.ts +45 -0
  17. package/dist/analysis/passes/weak-hash-pass.d.ts.map +1 -0
  18. package/dist/analysis/passes/weak-hash-pass.js +150 -0
  19. package/dist/analysis/passes/weak-hash-pass.js.map +1 -0
  20. package/dist/analysis/passes/weak-random-pass.d.ts +53 -0
  21. package/dist/analysis/passes/weak-random-pass.d.ts.map +1 -0
  22. package/dist/analysis/passes/weak-random-pass.js +181 -0
  23. package/dist/analysis/passes/weak-random-pass.js.map +1 -0
  24. package/dist/analyzer.d.ts.map +1 -1
  25. package/dist/analyzer.js +12 -0
  26. package/dist/analyzer.js.map +1 -1
  27. package/dist/browser/circle-ir.js +747 -50
  28. package/dist/core/circle-ir-core.cjs +9 -19
  29. package/dist/core/circle-ir-core.js +9 -19
  30. package/package.json +1 -1
@@ -11532,26 +11532,16 @@ var DEFAULT_SINKS = [
11532
11532
  { method: "get", class: "WebClient", type: "ssrf", cwe: "CWE-918", severity: "high", arg_positions: [] },
11533
11533
  { method: "post", class: "WebClient", type: "ssrf", cwe: "CWE-918", severity: "high", arg_positions: [] },
11534
11534
  // =============================================================================
11535
- // Weak Cryptography Sinks (no taint flow required - presence alone is vulnerability)
11535
+ // Config / Absence Vulnerabilities (handled by dedicated pattern passes)
11536
11536
  // =============================================================================
11537
- // Weak Random (CWE-330) - java.util.Random is not cryptographically secure
11538
- { method: "Random", class: "constructor", type: "weak_random", cwe: "CWE-330", severity: "medium", arg_positions: [] },
11539
- { method: "nextInt", class: "Random", type: "weak_random", cwe: "CWE-330", severity: "medium", arg_positions: [] },
11540
- { method: "nextLong", class: "Random", type: "weak_random", cwe: "CWE-330", severity: "medium", arg_positions: [] },
11541
- { method: "nextFloat", class: "Random", type: "weak_random", cwe: "CWE-330", severity: "medium", arg_positions: [] },
11542
- { method: "nextDouble", class: "Random", type: "weak_random", cwe: "CWE-330", severity: "medium", arg_positions: [] },
11543
- { method: "nextBoolean", class: "Random", type: "weak_random", cwe: "CWE-330", severity: "medium", arg_positions: [] },
11544
- { method: "nextBytes", class: "Random", type: "weak_random", cwe: "CWE-330", severity: "medium", arg_positions: [] },
11545
- // Weak Hash (CWE-328) - MD5/SHA1 are cryptographically broken
11546
- // Note: Detection requires checking algorithm argument - handled in runner
11547
- { method: "getInstance", class: "MessageDigest", type: "weak_hash", cwe: "CWE-328", severity: "medium", arg_positions: [0] },
11548
- // Weak Crypto (CWE-327) - DES/RC4/Blowfish are weak ciphers
11549
- // Note: Detection requires checking algorithm argument - handled in runner
11550
- { method: "getInstance", class: "Cipher", type: "weak_crypto", cwe: "CWE-327", severity: "high", arg_positions: [0] },
11551
- { method: "getInstance", class: "KeyGenerator", type: "weak_crypto", cwe: "CWE-327", severity: "high", arg_positions: [0] },
11552
- // Insecure Cookie (CWE-614) - cookies without secure/httpOnly flags
11553
- // Note: Detection requires checking if setSecure(true)/setHttpOnly(true) called - handled in runner
11554
- { method: "Cookie", class: "constructor", type: "insecure_cookie", cwe: "CWE-614", severity: "medium", arg_positions: [] },
11537
+ // weak_random → WeakRandomPass (src/analysis/passes/weak-random-pass.ts)
11538
+ // weak_hash → WeakHashPass (src/analysis/passes/weak-hash-pass.ts)
11539
+ // weak_crypto → WeakCryptoPass (src/analysis/passes/weak-crypto-pass.ts)
11540
+ // insecure_cookie InsecureCookiePass (src/analysis/passes/insecure-cookie-pass.ts)
11541
+ // tls_verify_disabled TlsVerifyDisabledPass
11542
+ // These patterns are detected by call-site literal inspection, not taint flow,
11543
+ // so they are NOT registered here as sinks (they could never match a "tainted
11544
+ // value flowing into a sink" because the bad value is a hard-coded constant).
11555
11545
  // Trust Boundary (CWE-501) - using untrusted data as session attribute NAME
11556
11546
  // The vulnerability is attacker controlling which key to use, not the value
11557
11547
  { method: "setAttribute", class: "HttpSession", type: "trust_boundary", cwe: "CWE-501", severity: "medium", arg_positions: [0] },
@@ -27081,59 +27071,762 @@ var COOKIE_RESPONSE_RECEIVERS = /* @__PURE__ */ new Set([
27081
27071
  ]);
27082
27072
  var SECURE_TRUE_RE = /\bsecure\s*:\s*true\b/;
27083
27073
  var HTTPONLY_TRUE_RE = /\bhttpOnly\s*:\s*true\b/i;
27074
+ var PY_SET_COOKIE_RECEIVERS = /* @__PURE__ */ new Set([
27075
+ "response",
27076
+ "resp",
27077
+ "res"
27078
+ ]);
27079
+ var PY_SECURE_TRUE_RE = /\bsecure\s*=\s*True\b/;
27080
+ var PY_HTTPONLY_TRUE_RE = /\bhttponly\s*=\s*True\b/i;
27081
+ var JAVA_SET_SECURE_TRUE_RE = /\.setSecure\s*\(\s*true\s*\)/;
27082
+ var JAVA_SET_HTTPONLY_TRUE_RE = /\.setHttpOnly\s*\(\s*true\s*\)/;
27084
27083
  var InsecureCookiePass = class {
27085
27084
  name = "insecure-cookie";
27086
27085
  category = "security";
27087
27086
  run(ctx) {
27088
- const { graph, language } = ctx;
27089
- if (language !== "javascript" && language !== "typescript") {
27090
- return { insecureCookies: [] };
27091
- }
27087
+ const { graph, language, code } = ctx;
27092
27088
  const file = graph.ir.meta.file;
27093
27089
  const insecureCookies = [];
27090
+ if (language === "javascript" || language === "typescript") {
27091
+ for (const call of graph.ir.calls) {
27092
+ const det = this.detectJs(call);
27093
+ if (!det) continue;
27094
+ insecureCookies.push(det);
27095
+ this.emit(ctx, file, det, "js");
27096
+ }
27097
+ } else if (language === "python") {
27098
+ for (const call of graph.ir.calls) {
27099
+ const det = this.detectPython(call);
27100
+ if (!det) continue;
27101
+ insecureCookies.push(det);
27102
+ this.emit(ctx, file, det, "python");
27103
+ }
27104
+ } else if (language === "java") {
27105
+ const hasSetSecureTrue = JAVA_SET_SECURE_TRUE_RE.test(code);
27106
+ const hasSetHttpOnlyTrue = JAVA_SET_HTTPONLY_TRUE_RE.test(code);
27107
+ for (const call of graph.ir.calls) {
27108
+ const det = this.detectJavaCookieCtor(call, hasSetSecureTrue, hasSetHttpOnlyTrue);
27109
+ if (!det) continue;
27110
+ insecureCookies.push(det);
27111
+ this.emit(ctx, file, det, "java");
27112
+ }
27113
+ }
27114
+ return { insecureCookies };
27115
+ }
27116
+ // ---------------- JS / TS ----------------
27117
+ detectJs(call) {
27118
+ if (call.method_name !== "cookie") return null;
27119
+ const receiver = call.receiver ?? "";
27120
+ if (!COOKIE_RESPONSE_RECEIVERS.has(receiver)) return null;
27121
+ if (call.arguments.length < 2) return null;
27122
+ const opts = call.arguments.find((a) => a.position === 2);
27123
+ const optsExpr = (opts?.expression ?? "").trim();
27124
+ const optionsPresent = optsExpr.length > 0;
27125
+ const missingSecure = !SECURE_TRUE_RE.test(optsExpr);
27126
+ const missingHttpOnly = !HTTPONLY_TRUE_RE.test(optsExpr);
27127
+ if (!missingSecure && !missingHttpOnly) return null;
27128
+ return {
27129
+ line: call.location.line,
27130
+ receiver,
27131
+ missingSecure,
27132
+ missingHttpOnly,
27133
+ optionsPresent
27134
+ };
27135
+ }
27136
+ // ---------------- Python ----------------
27137
+ detectPython(call) {
27138
+ if (call.method_name !== "set_cookie") return null;
27139
+ const receiver = call.receiver ?? "";
27140
+ if (!PY_SET_COOKIE_RECEIVERS.has(receiver)) return null;
27141
+ const argsBlob = call.arguments.map((a) => a.expression ?? "").join(", ");
27142
+ const missingSecure = !PY_SECURE_TRUE_RE.test(argsBlob);
27143
+ const missingHttpOnly = !PY_HTTPONLY_TRUE_RE.test(argsBlob);
27144
+ if (!missingSecure && !missingHttpOnly) return null;
27145
+ return {
27146
+ line: call.location.line,
27147
+ receiver,
27148
+ missingSecure,
27149
+ missingHttpOnly,
27150
+ optionsPresent: call.arguments.length >= 2
27151
+ };
27152
+ }
27153
+ // ---------------- Java ----------------
27154
+ detectJavaCookieCtor(call, hasSetSecureTrue, hasSetHttpOnlyTrue) {
27155
+ if (call.method_name !== "Cookie") return null;
27156
+ const looksLikeCtor = call.is_constructor || !call.receiver && call.receiver_type === "Cookie" || (call.resolution?.target ?? "").endsWith(".<init>");
27157
+ if (!looksLikeCtor) return null;
27158
+ if (call.arguments.length < 2) return null;
27159
+ const missingSecure = !hasSetSecureTrue;
27160
+ const missingHttpOnly = !hasSetHttpOnlyTrue;
27161
+ if (!missingSecure && !missingHttpOnly) return null;
27162
+ return {
27163
+ line: call.location.line,
27164
+ receiver: "new Cookie",
27165
+ missingSecure,
27166
+ missingHttpOnly,
27167
+ optionsPresent: false
27168
+ };
27169
+ }
27170
+ emit(ctx, file, det, flavor) {
27171
+ const missing = [];
27172
+ if (det.missingSecure) missing.push(flavor === "js" ? "`secure: true`" : flavor === "python" ? "`secure=True`" : "`setSecure(true)`");
27173
+ if (det.missingHttpOnly) missing.push(flavor === "js" ? "`httpOnly: true`" : flavor === "python" ? "`httponly=True`" : "`setHttpOnly(true)`");
27174
+ const fix = flavor === "js" ? 'Pass `{ secure: true, httpOnly: true, sameSite: "lax" }` as the third argument to `res.cookie()`.' : flavor === "python" ? 'Pass `secure=True, httponly=True, samesite="Lax"` to `response.set_cookie(...)`.' : "After constructing the cookie, call `cookie.setSecure(true)` and `cookie.setHttpOnly(true)` before adding it to the response.";
27175
+ ctx.addFinding({
27176
+ id: `${this.name}-${file}-${det.line}`,
27177
+ pass: this.name,
27178
+ category: this.category,
27179
+ rule_id: this.name,
27180
+ cwe: "CWE-614",
27181
+ severity: "medium",
27182
+ level: "warning",
27183
+ message: `Cookie set without ${missing.join(" and ")} \u2014 vulnerable to cleartext transmission (CWE-614) and client-side JS access (CWE-1004).`,
27184
+ file,
27185
+ line: det.line,
27186
+ fix,
27187
+ evidence: {
27188
+ receiver: det.receiver,
27189
+ options_present: det.optionsPresent,
27190
+ missing_secure: det.missingSecure,
27191
+ missing_http_only: det.missingHttpOnly
27192
+ }
27193
+ });
27194
+ }
27195
+ };
27196
+
27197
+ // src/analysis/passes/weak-hash-pass.ts
27198
+ var WEAK_HASH_NAMES = /* @__PURE__ */ new Set([
27199
+ "md2",
27200
+ "md4",
27201
+ "md5",
27202
+ "sha-1",
27203
+ "sha1"
27204
+ ]);
27205
+ var COMMONS_DIGEST_METHODS = /* @__PURE__ */ new Set([
27206
+ "md2",
27207
+ "md2Hex",
27208
+ "md5",
27209
+ "md5Hex",
27210
+ "sha1",
27211
+ "sha1Hex",
27212
+ // Apache Commons also has the misnamed `sha(...)` which is SHA-1
27213
+ "sha",
27214
+ "shaHex"
27215
+ ]);
27216
+ var PY_HASHLIB_WEAK = /* @__PURE__ */ new Set(["md5", "sha1", "md4", "md2", "new"]);
27217
+ function stripQuotes4(s) {
27218
+ const trimmed = s.trim();
27219
+ if (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'") || trimmed.startsWith("`") && trimmed.endsWith("`")) {
27220
+ return trimmed.slice(1, -1);
27221
+ }
27222
+ return trimmed;
27223
+ }
27224
+ function literalAlgo(call, position) {
27225
+ const arg = call.arguments.find((a) => a.position === position);
27226
+ if (!arg) return null;
27227
+ const raw = arg.literal ?? arg.expression ?? "";
27228
+ const cleaned = stripQuotes4(raw).toLowerCase();
27229
+ return cleaned || null;
27230
+ }
27231
+ var WeakHashPass = class {
27232
+ name = "weak-hash";
27233
+ category = "security";
27234
+ run(ctx) {
27235
+ const { graph, language } = ctx;
27236
+ const file = graph.ir.meta.file;
27237
+ const findings = [];
27094
27238
  for (const call of graph.ir.calls) {
27095
- if (call.method_name !== "cookie") continue;
27096
- const receiver = call.receiver ?? "";
27097
- if (!COOKIE_RESPONSE_RECEIVERS.has(receiver)) continue;
27098
- if (call.arguments.length < 2) continue;
27099
- const opts = call.arguments.find((a) => a.position === 2);
27100
- const optsExpr = (opts?.expression ?? "").trim();
27101
- const optionsPresent = optsExpr.length > 0;
27102
- const missingSecure = !SECURE_TRUE_RE.test(optsExpr);
27103
- const missingHttpOnly = !HTTPONLY_TRUE_RE.test(optsExpr);
27104
- if (!missingSecure && !missingHttpOnly) continue;
27239
+ const detection = this.detect(call, language);
27240
+ if (!detection) continue;
27241
+ const { algorithm, api } = detection;
27105
27242
  const line = call.location.line;
27106
- insecureCookies.push({
27243
+ findings.push({ line, language, algorithm, api });
27244
+ ctx.addFinding({
27245
+ id: `${this.name}-${file}-${line}`,
27246
+ pass: this.name,
27247
+ category: this.category,
27248
+ rule_id: this.name,
27249
+ cwe: "CWE-328",
27250
+ severity: "medium",
27251
+ level: "warning",
27252
+ message: `Weak hash algorithm \`${algorithm.toUpperCase()}\` used via \`${api}\`. MD2/MD4/MD5/SHA-1 are cryptographically broken and must not be used for passwords, signatures, integrity checks, or anywhere collision resistance is required.`,
27253
+ file,
27107
27254
  line,
27108
- receiver,
27109
- missingSecure,
27110
- missingHttpOnly,
27111
- optionsPresent
27255
+ fix: "Use SHA-256 or stronger (SHA-384, SHA-512, SHA-3). For passwords, use a password-hashing function: bcrypt, scrypt, Argon2, or PBKDF2.",
27256
+ evidence: { algorithm, api, language }
27112
27257
  });
27113
- const missing = [];
27114
- if (missingSecure) missing.push("`secure: true`");
27115
- if (missingHttpOnly) missing.push("`httpOnly: true`");
27258
+ }
27259
+ return { findings };
27260
+ }
27261
+ detect(call, language) {
27262
+ const method = call.method_name;
27263
+ const receiver = call.receiver ?? "";
27264
+ if (language === "java") {
27265
+ if (method === "getInstance" && (receiver === "MessageDigest" || receiver.endsWith(".MessageDigest"))) {
27266
+ const algo = literalAlgo(call, 0);
27267
+ if (algo && WEAK_HASH_NAMES.has(algo)) {
27268
+ return { algorithm: algo, api: "MessageDigest.getInstance" };
27269
+ }
27270
+ }
27271
+ if (COMMONS_DIGEST_METHODS.has(method) && (receiver === "DigestUtils" || receiver.endsWith(".DigestUtils"))) {
27272
+ const algoFromMethod = method.toLowerCase().replace(/hex$/, "");
27273
+ const normalized = algoFromMethod === "sha" ? "sha1" : algoFromMethod;
27274
+ return { algorithm: normalized, api: `DigestUtils.${method}` };
27275
+ }
27276
+ return null;
27277
+ }
27278
+ if (language === "python") {
27279
+ if ((receiver === "hashlib" || receiver.endsWith(".hashlib")) && PY_HASHLIB_WEAK.has(method)) {
27280
+ if (method === "new") {
27281
+ const algo = literalAlgo(call, 0);
27282
+ if (algo && WEAK_HASH_NAMES.has(algo)) {
27283
+ return { algorithm: algo, api: "hashlib.new" };
27284
+ }
27285
+ return null;
27286
+ }
27287
+ return { algorithm: method, api: `hashlib.${method}` };
27288
+ }
27289
+ return null;
27290
+ }
27291
+ if (language === "javascript" || language === "typescript") {
27292
+ if ((method === "createHash" || method === "createHmac") && receiver === "crypto") {
27293
+ const algo = literalAlgo(call, 0);
27294
+ if (algo && WEAK_HASH_NAMES.has(algo)) {
27295
+ return { algorithm: algo, api: `crypto.${method}` };
27296
+ }
27297
+ }
27298
+ return null;
27299
+ }
27300
+ if (language === "go") {
27301
+ const isWeakPkg = receiver === "md5" || receiver === "sha1";
27302
+ if (isWeakPkg && (method === "New" || method === "Sum")) {
27303
+ return { algorithm: receiver, api: `${receiver}.${method}` };
27304
+ }
27305
+ return null;
27306
+ }
27307
+ return null;
27308
+ }
27309
+ };
27310
+
27311
+ // src/analysis/passes/weak-crypto-pass.ts
27312
+ var WEAK_CIPHER_BASES = /* @__PURE__ */ new Set([
27313
+ "des",
27314
+ "3des",
27315
+ "desede",
27316
+ "tripledes",
27317
+ "rc2",
27318
+ "rc4",
27319
+ "arc4",
27320
+ "blowfish",
27321
+ "bf",
27322
+ "idea",
27323
+ "seed",
27324
+ "cast5"
27325
+ ]);
27326
+ function classifyJavaCipherSpec(spec) {
27327
+ const parts2 = spec.split("/").map((p) => p.trim().toLowerCase());
27328
+ const base = parts2[0] ?? "";
27329
+ const mode = parts2[1] ?? "";
27330
+ const result = {};
27331
+ if (WEAK_CIPHER_BASES.has(base)) result.weakBase = base;
27332
+ if (mode === "ecb") result.ecb = true;
27333
+ if (parts2.length === 1 && base === "aes") result.ecb = true;
27334
+ return result;
27335
+ }
27336
+ function stripQuotes5(s) {
27337
+ const t = s.trim();
27338
+ if (t.startsWith('"') && t.endsWith('"') || t.startsWith("'") && t.endsWith("'") || t.startsWith("`") && t.endsWith("`")) {
27339
+ return t.slice(1, -1);
27340
+ }
27341
+ return t;
27342
+ }
27343
+ function literalAlgo2(call, position) {
27344
+ const arg = call.arguments.find((a) => a.position === position);
27345
+ if (!arg) return null;
27346
+ const raw = arg.literal ?? arg.expression ?? "";
27347
+ const cleaned = stripQuotes5(raw);
27348
+ return cleaned || null;
27349
+ }
27350
+ var WeakCryptoPass = class {
27351
+ name = "weak-crypto";
27352
+ category = "security";
27353
+ run(ctx) {
27354
+ const { graph, language } = ctx;
27355
+ const file = graph.ir.meta.file;
27356
+ const findings = [];
27357
+ for (const call of graph.ir.calls) {
27358
+ const detections = this.detect(call, language);
27359
+ for (const det of detections) {
27360
+ const line = call.location.line;
27361
+ findings.push({ line, language, ...det });
27362
+ const message = this.buildMessage(det);
27363
+ ctx.addFinding({
27364
+ id: `${this.name}-${file}-${line}-${det.issue}`,
27365
+ pass: this.name,
27366
+ category: this.category,
27367
+ rule_id: this.name,
27368
+ cwe: "CWE-327",
27369
+ severity: "high",
27370
+ level: "error",
27371
+ message,
27372
+ file,
27373
+ line,
27374
+ fix: "Use AES-GCM (authenticated) or ChaCha20-Poly1305. Avoid DES, 3DES, RC2, RC4, Blowfish, and ECB mode. For asymmetric encryption use RSA-OAEP with \u22652048-bit keys or modern curve-based schemes.",
27375
+ evidence: { ...det, language }
27376
+ });
27377
+ }
27378
+ }
27379
+ return { findings };
27380
+ }
27381
+ buildMessage(det) {
27382
+ switch (det.issue) {
27383
+ case "weak-cipher":
27384
+ return `Weak symmetric cipher \`${det.detail.toUpperCase()}\` used via \`${det.api}\`. DES, 3DES, RC2, RC4, Blowfish, and IDEA/SEED/CAST5 are deprecated and broken at modern key sizes.`;
27385
+ case "ecb-mode":
27386
+ return `ECB block-cipher mode used via \`${det.api}\` (\`${det.detail}\`). ECB leaks plaintext structure (identical blocks \u2192 identical ciphertext) and is not semantically secure.`;
27387
+ case "deprecated-api":
27388
+ return `Deprecated crypto API \`${det.api}\` used (no IV: \`${det.detail}\`). This API derives the key/IV from a password in an insecure way.`;
27389
+ default:
27390
+ return `Weak cryptography: ${det.detail} (${det.api})`;
27391
+ }
27392
+ }
27393
+ detect(call, language) {
27394
+ const method = call.method_name;
27395
+ const receiver = call.receiver ?? "";
27396
+ const out2 = [];
27397
+ if (language === "java") {
27398
+ const isCipherFactory = method === "getInstance" && (receiver === "Cipher" || receiver.endsWith(".Cipher") || receiver === "KeyGenerator" || receiver.endsWith(".KeyGenerator"));
27399
+ if (isCipherFactory) {
27400
+ const spec = literalAlgo2(call, 0);
27401
+ if (spec) {
27402
+ const { weakBase, ecb } = classifyJavaCipherSpec(spec);
27403
+ const api = `${receiver}.getInstance`;
27404
+ if (weakBase) out2.push({ issue: "weak-cipher", detail: weakBase, api });
27405
+ if (ecb) out2.push({ issue: "ecb-mode", detail: spec, api });
27406
+ }
27407
+ }
27408
+ return out2;
27409
+ }
27410
+ if (language === "python") {
27411
+ if (method === "new") {
27412
+ const rcvLower = receiver.toLowerCase();
27413
+ const lastSeg = rcvLower.split(".").pop() ?? rcvLower;
27414
+ if (WEAK_CIPHER_BASES.has(lastSeg)) {
27415
+ out2.push({ issue: "weak-cipher", detail: lastSeg, api: `${receiver}.new` });
27416
+ }
27417
+ if (lastSeg === "aes" || lastSeg.endsWith(".aes")) {
27418
+ const mode = call.arguments.find((a) => a.position === 1);
27419
+ const modeExpr = (mode?.expression ?? "").trim();
27420
+ if (/\bMODE_ECB\b/.test(modeExpr)) {
27421
+ out2.push({ issue: "ecb-mode", detail: "AES.MODE_ECB", api: `${receiver}.new` });
27422
+ }
27423
+ }
27424
+ }
27425
+ const isHazmatAlgos = receiver === "algorithms" || receiver.endsWith(".algorithms");
27426
+ if (isHazmatAlgos) {
27427
+ const m = method.toLowerCase();
27428
+ const normalized = m === "tripledes" ? "3des" : m;
27429
+ if (WEAK_CIPHER_BASES.has(normalized)) {
27430
+ out2.push({ issue: "weak-cipher", detail: normalized, api: `algorithms.${method}` });
27431
+ }
27432
+ }
27433
+ return out2;
27434
+ }
27435
+ if (language === "javascript" || language === "typescript") {
27436
+ if (method === "createCipher" && receiver === "crypto") {
27437
+ const algo = literalAlgo2(call, 0) ?? "<unknown>";
27438
+ out2.push({ issue: "deprecated-api", detail: algo, api: "crypto.createCipher" });
27439
+ }
27440
+ if (method === "createCipheriv" && receiver === "crypto") {
27441
+ const algo = literalAlgo2(call, 0);
27442
+ if (algo) {
27443
+ const lower = algo.toLowerCase();
27444
+ const parts2 = lower.split("-");
27445
+ const base = parts2[0];
27446
+ const mode = parts2[parts2.length - 1];
27447
+ let normalizedBase = base;
27448
+ if (base === "bf") normalizedBase = "blowfish";
27449
+ if (base === "desede" || base === "des-ede3" || base === "des3") normalizedBase = "3des";
27450
+ if (WEAK_CIPHER_BASES.has(normalizedBase)) {
27451
+ out2.push({ issue: "weak-cipher", detail: normalizedBase, api: "crypto.createCipheriv" });
27452
+ }
27453
+ if (mode === "ecb") {
27454
+ out2.push({ issue: "ecb-mode", detail: lower, api: "crypto.createCipheriv" });
27455
+ }
27456
+ }
27457
+ }
27458
+ return out2;
27459
+ }
27460
+ if (language === "go") {
27461
+ if (receiver === "des" && (method === "NewCipher" || method === "NewTripleDESCipher")) {
27462
+ const base = method === "NewTripleDESCipher" ? "3des" : "des";
27463
+ out2.push({ issue: "weak-cipher", detail: base, api: `des.${method}` });
27464
+ }
27465
+ if (receiver === "rc4" && method === "NewCipher") {
27466
+ out2.push({ issue: "weak-cipher", detail: "rc4", api: "rc4.NewCipher" });
27467
+ }
27468
+ if ((method === "NewECBEncrypter" || method === "NewECBDecrypter") && receiver === "cipher") {
27469
+ out2.push({ issue: "ecb-mode", detail: method, api: `cipher.${method}` });
27470
+ }
27471
+ return out2;
27472
+ }
27473
+ return out2;
27474
+ }
27475
+ };
27476
+
27477
+ // src/analysis/passes/weak-random-pass.ts
27478
+ var JAVA_RANDOM_METHODS = /* @__PURE__ */ new Set([
27479
+ "nextInt",
27480
+ "nextLong",
27481
+ "nextFloat",
27482
+ "nextDouble",
27483
+ "nextBoolean",
27484
+ "nextBytes",
27485
+ "nextGaussian",
27486
+ "ints",
27487
+ "longs",
27488
+ "doubles"
27489
+ ]);
27490
+ var PY_RANDOM_FUNCS = /* @__PURE__ */ new Set([
27491
+ "random",
27492
+ "randint",
27493
+ "choice",
27494
+ "uniform",
27495
+ "shuffle",
27496
+ "getrandbits",
27497
+ "sample",
27498
+ "choices",
27499
+ "randrange",
27500
+ "seed",
27501
+ "gauss",
27502
+ "normalvariate",
27503
+ "expovariate",
27504
+ "paretovariate",
27505
+ "weibullvariate",
27506
+ "triangular",
27507
+ "lognormvariate",
27508
+ "vonmisesvariate",
27509
+ "betavariate",
27510
+ "gammavariate"
27511
+ ]);
27512
+ var GO_RAND_FUNCS = /* @__PURE__ */ new Set([
27513
+ "Int",
27514
+ "Intn",
27515
+ "Int31",
27516
+ "Int31n",
27517
+ "Int63",
27518
+ "Int63n",
27519
+ "Float32",
27520
+ "Float64",
27521
+ "NormFloat64",
27522
+ "ExpFloat64",
27523
+ "Perm",
27524
+ "Shuffle",
27525
+ "Read",
27526
+ "Uint32",
27527
+ "Uint64",
27528
+ "Seed",
27529
+ "New",
27530
+ "NewSource"
27531
+ ]);
27532
+ var WeakRandomPass = class {
27533
+ name = "weak-random";
27534
+ category = "security";
27535
+ run(ctx) {
27536
+ const { graph, language } = ctx;
27537
+ const file = graph.ir.meta.file;
27538
+ const findings = [];
27539
+ for (const call of graph.ir.calls) {
27540
+ const api = this.detect(call, language, ctx);
27541
+ if (!api) continue;
27542
+ const line = call.location.line;
27543
+ findings.push({ line, language, api });
27116
27544
  ctx.addFinding({
27117
27545
  id: `${this.name}-${file}-${line}`,
27118
27546
  pass: this.name,
27119
27547
  category: this.category,
27120
27548
  rule_id: this.name,
27121
- cwe: "CWE-614",
27549
+ cwe: "CWE-330",
27122
27550
  severity: "medium",
27123
27551
  level: "warning",
27124
- message: `Cookie set without ${missing.join(" and ")} \u2014 vulnerable to cleartext transmission (CWE-614) and client-side JS access (CWE-1004).`,
27552
+ message: `Non-cryptographic random generator \`${api}\` used. The output of this PRNG is predictable and must not be used for security-sensitive values (tokens, session IDs, keys, salts, password reset codes, OTPs).`,
27125
27553
  file,
27126
27554
  line,
27127
- fix: 'Pass `{ secure: true, httpOnly: true, sameSite: "lax" }` as the third argument to `res.cookie()`.',
27128
- evidence: {
27129
- receiver,
27130
- options_present: optionsPresent,
27131
- missing_secure: missingSecure,
27132
- missing_http_only: missingHttpOnly
27555
+ fix: this.fixFor(language),
27556
+ evidence: { api, language }
27557
+ });
27558
+ }
27559
+ return { findings };
27560
+ }
27561
+ fixFor(language) {
27562
+ switch (language) {
27563
+ case "java":
27564
+ return "Use `java.security.SecureRandom`. Example: `SecureRandom sr = new SecureRandom(); byte[] b = new byte[32]; sr.nextBytes(b);`";
27565
+ case "python":
27566
+ return "Use the `secrets` module (`secrets.token_bytes`, `secrets.token_hex`, `secrets.choice`, `secrets.randbelow`).";
27567
+ case "javascript":
27568
+ case "typescript":
27569
+ return "Use `crypto.randomBytes(n)` (Node.js) or `crypto.getRandomValues(typedArray)` (browser).";
27570
+ case "go":
27571
+ return "Use `crypto/rand` instead of `math/rand`. Example: `b := make([]byte, 32); _, _ = rand.Read(b)` (where `rand` is `crypto/rand`).";
27572
+ default:
27573
+ return "Use a cryptographically secure random generator from your standard library.";
27574
+ }
27575
+ }
27576
+ detect(call, language, ctx) {
27577
+ const method = call.method_name;
27578
+ const receiver = call.receiver ?? "";
27579
+ if (language === "java") {
27580
+ if (call.is_constructor) {
27581
+ const ctor = method;
27582
+ if (ctor === "Random") return "new Random";
27583
+ if (ctor === "SplittableRandom") return "new SplittableRandom";
27584
+ }
27585
+ if (method === "random" && (receiver === "Math" || receiver.endsWith(".Math"))) {
27586
+ return "Math.random";
27587
+ }
27588
+ if (JAVA_RANDOM_METHODS.has(method)) {
27589
+ const rt = call.receiver_type ?? "";
27590
+ if (rt === "Random" || rt === "SplittableRandom" || rt === "ThreadLocalRandom") {
27591
+ return `${rt}.${method}`;
27592
+ }
27593
+ }
27594
+ if (JAVA_RANDOM_METHODS.has(method) && /ThreadLocalRandom\.current\(\)/.test(receiver)) {
27595
+ return `ThreadLocalRandom.current.${method}`;
27596
+ }
27597
+ return null;
27598
+ }
27599
+ if (language === "python") {
27600
+ if ((receiver === "random" || receiver.endsWith(".random")) && PY_RANDOM_FUNCS.has(method)) {
27601
+ return `random.${method}`;
27602
+ }
27603
+ return null;
27604
+ }
27605
+ if (language === "javascript" || language === "typescript") {
27606
+ if (method === "random" && (receiver === "Math" || receiver.endsWith(".Math"))) {
27607
+ return "Math.random";
27608
+ }
27609
+ return null;
27610
+ }
27611
+ if (language === "go") {
27612
+ if (receiver === "rand" && GO_RAND_FUNCS.has(method)) {
27613
+ if (this.goMathRandIsActive(ctx)) {
27614
+ return `rand.${method}`;
27133
27615
  }
27616
+ }
27617
+ return null;
27618
+ }
27619
+ return null;
27620
+ }
27621
+ /**
27622
+ * Returns true when `math/rand` is the active `rand` identifier in this
27623
+ * file (i.e. `math/rand` imported unaliased; `crypto/rand` is either not
27624
+ * imported or imported under an alias).
27625
+ */
27626
+ goMathRandIsActive(ctx) {
27627
+ const imports = ctx.graph.ir.imports ?? [];
27628
+ let mathRandUnaliased = false;
27629
+ let cryptoRandUnaliased = false;
27630
+ for (const imp of imports) {
27631
+ const pkg = imp.from_package ?? imp.imported_name;
27632
+ const alias = imp.alias;
27633
+ if (pkg === "math/rand" && (!alias || alias === "rand")) {
27634
+ mathRandUnaliased = true;
27635
+ }
27636
+ if (pkg === "crypto/rand" && (!alias || alias === "rand")) {
27637
+ cryptoRandUnaliased = true;
27638
+ }
27639
+ }
27640
+ return mathRandUnaliased && !cryptoRandUnaliased;
27641
+ }
27642
+ };
27643
+
27644
+ // src/analysis/passes/tls-verify-disabled-pass.ts
27645
+ var PY_HTTP_METHODS = /* @__PURE__ */ new Set([
27646
+ "get",
27647
+ "post",
27648
+ "put",
27649
+ "delete",
27650
+ "patch",
27651
+ "head",
27652
+ "options",
27653
+ "request",
27654
+ "send"
27655
+ ]);
27656
+ var PY_HTTP_RECEIVERS = /* @__PURE__ */ new Set([
27657
+ "requests",
27658
+ "httpx"
27659
+ ]);
27660
+ var VERIFY_FALSE_RE = /\bverify\s*=\s*False\b/;
27661
+ var REJECT_UNAUTHORIZED_FALSE_RE = /\brejectUnauthorized\s*:\s*false\b/;
27662
+ var INSECURE_SKIP_VERIFY_TRUE_RE = /\bInsecureSkipVerify\s*:\s*true\b/;
27663
+ var HOSTNAME_LAMBDA_TRUE_RE = /\(\s*\w+\s*,\s*\w+\s*\)\s*->\s*true\b/;
27664
+ var ALLOW_ALL_HOSTNAME_VERIFIERS = /* @__PURE__ */ new Set([
27665
+ "NoopHostnameVerifier.INSTANCE",
27666
+ "new AllowAllHostnameVerifier()",
27667
+ "new NoopHostnameVerifier()"
27668
+ ]);
27669
+ var TlsVerifyDisabledPass = class {
27670
+ name = "tls-verify-disabled";
27671
+ category = "security";
27672
+ run(ctx) {
27673
+ const { graph, language, code } = ctx;
27674
+ const file = graph.ir.meta.file;
27675
+ const findings = [];
27676
+ for (const call of graph.ir.calls) {
27677
+ const det = this.detectCall(call, language);
27678
+ if (!det) continue;
27679
+ const line = call.location.line;
27680
+ findings.push({ line, language, ...det });
27681
+ ctx.addFinding({
27682
+ id: `${this.name}-${file}-${line}-${det.pattern}`,
27683
+ pass: this.name,
27684
+ category: this.category,
27685
+ rule_id: this.name,
27686
+ cwe: "CWE-295",
27687
+ severity: "high",
27688
+ level: "error",
27689
+ message: `TLS certificate verification disabled via \`${det.pattern}\` in \`${det.api}\`. The connection becomes vulnerable to active man-in-the-middle attacks \u2014 any attacker on the network path can present a forged certificate.`,
27690
+ file,
27691
+ line,
27692
+ fix: this.fixFor(language, det.pattern),
27693
+ evidence: { ...det, language }
27134
27694
  });
27135
27695
  }
27136
- return { insecureCookies };
27696
+ for (const extra of this.detectSourceText(code, language)) {
27697
+ const dupKey = `${extra.line}-${extra.pattern}`;
27698
+ if (findings.some((f) => `${f.line}-${f.pattern}` === dupKey)) continue;
27699
+ findings.push({ ...extra, language });
27700
+ ctx.addFinding({
27701
+ id: `${this.name}-${file}-${extra.line}-${extra.pattern}`,
27702
+ pass: this.name,
27703
+ category: this.category,
27704
+ rule_id: this.name,
27705
+ cwe: "CWE-295",
27706
+ severity: "high",
27707
+ level: "error",
27708
+ message: `TLS certificate verification disabled via \`${extra.pattern}\` (${extra.api}). Vulnerable to active man-in-the-middle.`,
27709
+ file,
27710
+ line: extra.line,
27711
+ fix: this.fixFor(language, extra.pattern),
27712
+ evidence: { ...extra, language }
27713
+ });
27714
+ }
27715
+ return { findings };
27716
+ }
27717
+ detectCall(call, language) {
27718
+ const method = call.method_name;
27719
+ const receiver = call.receiver ?? "";
27720
+ if (language === "python") {
27721
+ if (PY_HTTP_RECEIVERS.has(receiver) && PY_HTTP_METHODS.has(method)) {
27722
+ for (const arg of call.arguments) {
27723
+ const expr = (arg.expression ?? "").trim();
27724
+ if (VERIFY_FALSE_RE.test(expr)) {
27725
+ return { pattern: "verify=False", api: `${receiver}.${method}` };
27726
+ }
27727
+ }
27728
+ }
27729
+ if (method === "_create_unverified_context" && receiver === "ssl") {
27730
+ return { pattern: "ssl._create_unverified_context", api: "ssl._create_unverified_context()" };
27731
+ }
27732
+ if (receiver === "httpx" && method === "Client") {
27733
+ for (const arg of call.arguments) {
27734
+ if (VERIFY_FALSE_RE.test(arg.expression ?? "")) {
27735
+ return { pattern: "verify=False", api: "httpx.Client" };
27736
+ }
27737
+ }
27738
+ }
27739
+ return null;
27740
+ }
27741
+ if (language === "javascript" || language === "typescript") {
27742
+ const lastSeg = method.includes(".") ? method.split(".").pop() ?? "" : method;
27743
+ const arglooks = method === "request" || method === "get" || method === "post" || method === "create" || method === "Agent" || method === "fetch" || lastSeg === "Agent" || lastSeg === "request" || lastSeg === "create";
27744
+ if (arglooks) {
27745
+ for (const arg of call.arguments) {
27746
+ if (REJECT_UNAUTHORIZED_FALSE_RE.test(arg.expression ?? "")) {
27747
+ return { pattern: "rejectUnauthorized: false", api: `${receiver || "(global)"}.${method}` };
27748
+ }
27749
+ }
27750
+ }
27751
+ return null;
27752
+ }
27753
+ if (language === "java") {
27754
+ if (method === "setHostnameVerifier") {
27755
+ const arg = call.arguments.find((a) => a.position === 0);
27756
+ const expr = (arg?.expression ?? "").trim();
27757
+ if (HOSTNAME_LAMBDA_TRUE_RE.test(expr)) {
27758
+ return { pattern: "(h,s) -> true", api: "setHostnameVerifier" };
27759
+ }
27760
+ for (const v of ALLOW_ALL_HOSTNAME_VERIFIERS) {
27761
+ if (expr === v || expr.replace(/\s+/g, "") === v.replace(/\s+/g, "")) {
27762
+ return { pattern: v, api: "setHostnameVerifier" };
27763
+ }
27764
+ }
27765
+ }
27766
+ return null;
27767
+ }
27768
+ return null;
27769
+ }
27770
+ detectSourceText(code, language) {
27771
+ const out2 = [];
27772
+ const lines = code.split("\n");
27773
+ if (language === "go") {
27774
+ for (let i2 = 0; i2 < lines.length; i2++) {
27775
+ if (INSECURE_SKIP_VERIFY_TRUE_RE.test(lines[i2])) {
27776
+ out2.push({
27777
+ line: i2 + 1,
27778
+ pattern: "InsecureSkipVerify: true",
27779
+ api: "tls.Config"
27780
+ });
27781
+ }
27782
+ }
27783
+ }
27784
+ if (language === "python") {
27785
+ for (let i2 = 0; i2 < lines.length; i2++) {
27786
+ const l = lines[i2];
27787
+ if (/ssl\._create_default_https_context\s*=\s*ssl\._create_unverified_context/.test(l)) {
27788
+ out2.push({
27789
+ line: i2 + 1,
27790
+ pattern: "ssl._create_default_https_context = _create_unverified_context",
27791
+ api: "ssl module override"
27792
+ });
27793
+ }
27794
+ }
27795
+ }
27796
+ if (language === "javascript" || language === "typescript") {
27797
+ for (let i2 = 0; i2 < lines.length; i2++) {
27798
+ const l = lines[i2];
27799
+ if (/process\.env\.NODE_TLS_REJECT_UNAUTHORIZED\s*=\s*['"]0['"]/.test(l)) {
27800
+ out2.push({
27801
+ line: i2 + 1,
27802
+ pattern: "NODE_TLS_REJECT_UNAUTHORIZED=0",
27803
+ api: "process.env"
27804
+ });
27805
+ }
27806
+ }
27807
+ }
27808
+ return out2;
27809
+ }
27810
+ fixFor(language, pattern) {
27811
+ if (pattern.includes("InsecureSkipVerify")) {
27812
+ return "Remove `InsecureSkipVerify: true` \u2014 let Go verify the cert. If you need to trust a private CA, set `RootCAs` to a `*x509.CertPool` containing that CA.";
27813
+ }
27814
+ if (pattern.includes("verify=False")) {
27815
+ return "Remove `verify=False`. To trust a private CA, pass `verify='/path/to/ca.pem'`.";
27816
+ }
27817
+ if (pattern.includes("rejectUnauthorized")) {
27818
+ return "Remove `rejectUnauthorized: false`. To trust a private CA, set the `ca` option to the CA cert(s). Never disable TLS verification globally.";
27819
+ }
27820
+ if (pattern.includes("NODE_TLS_REJECT_UNAUTHORIZED")) {
27821
+ return "Remove the `NODE_TLS_REJECT_UNAUTHORIZED=0` assignment \u2014 it globally disables TLS verification for every outbound HTTPS request.";
27822
+ }
27823
+ if (language === "java") {
27824
+ return "Do not use an always-true HostnameVerifier or AllowAllHostnameVerifier. Use the JVM's default verifier; for self-signed certs add the cert to a custom TrustManager that validates the chain.";
27825
+ }
27826
+ if (pattern.includes("ssl._create_unverified_context")) {
27827
+ return "Do not use `_create_unverified_context()`. Use `ssl.create_default_context()`.";
27828
+ }
27829
+ return "Restore TLS certificate and hostname verification.";
27137
27830
  }
27138
27831
  };
27139
27832
 
@@ -28034,6 +28727,10 @@ async function analyze(code, filePath, language, options = {}) {
28034
28727
  if (!disabledPasses.has("security-headers")) pipeline.add(new SecurityHeadersPass(passOpts.securityHeaders));
28035
28728
  if (!disabledPasses.has("spring4shell")) pipeline.add(new Spring4ShellPass());
28036
28729
  if (!disabledPasses.has("insecure-cookie")) pipeline.add(new InsecureCookiePass());
28730
+ if (!disabledPasses.has("weak-hash")) pipeline.add(new WeakHashPass());
28731
+ if (!disabledPasses.has("weak-crypto")) pipeline.add(new WeakCryptoPass());
28732
+ if (!disabledPasses.has("weak-random")) pipeline.add(new WeakRandomPass());
28733
+ if (!disabledPasses.has("tls-verify-disabled")) pipeline.add(new TlsVerifyDisabledPass());
28037
28734
  const { results, findings } = pipeline.run(graph, code, language, config);
28038
28735
  const sinkFilter = results.get("sink-filter");
28039
28736
  const interProc = results.get("interprocedural");