codelaw-rules-security-js 0.3.0__py3-none-any.whl

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 (148) hide show
  1. codelaw_rules_security_js/LICENSE +23 -0
  2. codelaw_rules_security_js/NOTICE +22 -0
  3. codelaw_rules_security_js/README.md +183 -0
  4. codelaw_rules_security_js/codelaw-pack.toml +6 -0
  5. codelaw_rules_security_js/corpus.toml +70 -0
  6. codelaw_rules_security_js/data/sources/browser.json +24 -0
  7. codelaw_rules_security_js/data/sources/express.json +28 -0
  8. codelaw_rules_security_js/data/sources/koa.json +18 -0
  9. codelaw_rules_security_js/data/sources/llm.json +14 -0
  10. codelaw_rules_security_js/data/sources/nextjs.json +13 -0
  11. codelaw_rules_security_js/presets/sec-js/recommended.toml +58 -0
  12. codelaw_rules_security_js/presets/sec-js/strict.toml +15 -0
  13. codelaw_rules_security_js/rules/sec-js/angularjs-sce-disabled.cases.md +129 -0
  14. codelaw_rules_security_js/rules/sec-js/angularjs-sce-disabled.md +132 -0
  15. codelaw_rules_security_js/rules/sec-js/cookie-flags.cases.md +41 -0
  16. codelaw_rules_security_js/rules/sec-js/cookie-flags.md +117 -0
  17. codelaw_rules_security_js/rules/sec-js/express-hardening.cases.md +12 -0
  18. codelaw_rules_security_js/rules/sec-js/express-hardening.md +135 -0
  19. codelaw_rules_security_js/rules/sec-js/express-session-secret.cases.md +21 -0
  20. codelaw_rules_security_js/rules/sec-js/express-session-secret.md +101 -0
  21. codelaw_rules_security_js/rules/sec-js/graphql-hardening.cases.md +21 -0
  22. codelaw_rules_security_js/rules/sec-js/graphql-hardening.md +116 -0
  23. codelaw_rules_security_js/rules/sec-js/helmet-config.cases.md +21 -0
  24. codelaw_rules_security_js/rules/sec-js/helmet-config.md +88 -0
  25. codelaw_rules_security_js/rules/sec-js/jwt-verify.cases.md +41 -0
  26. codelaw_rules_security_js/rules/sec-js/jwt-verify.md +107 -0
  27. codelaw_rules_security_js/rules/sec-js/missing-rate-limit.cases.md +22 -0
  28. codelaw_rules_security_js/rules/sec-js/missing-rate-limit.md +119 -0
  29. codelaw_rules_security_js/rules/sec-js/no-archive-slip.cases.md +11 -0
  30. codelaw_rules_security_js/rules/sec-js/no-archive-slip.md +119 -0
  31. codelaw_rules_security_js/rules/sec-js/no-bad-tag-filter.cases.md +11 -0
  32. codelaw_rules_security_js/rules/sec-js/no-bad-tag-filter.md +85 -0
  33. codelaw_rules_security_js/rules/sec-js/no-biased-random.cases.md +21 -0
  34. codelaw_rules_security_js/rules/sec-js/no-biased-random.md +115 -0
  35. codelaw_rules_security_js/rules/sec-js/no-bidi-characters.cases.md +21 -0
  36. codelaw_rules_security_js/rules/sec-js/no-bidi-characters.md +123 -0
  37. codelaw_rules_security_js/rules/sec-js/no-child-process-shell.cases.md +71 -0
  38. codelaw_rules_security_js/rules/sec-js/no-child-process-shell.md +141 -0
  39. codelaw_rules_security_js/rules/sec-js/no-cleartext-http.cases.md +41 -0
  40. codelaw_rules_security_js/rules/sec-js/no-cleartext-http.md +147 -0
  41. codelaw_rules_security_js/rules/sec-js/no-cors-wildcard-credentials.cases.md +21 -0
  42. codelaw_rules_security_js/rules/sec-js/no-cors-wildcard-credentials.md +92 -0
  43. codelaw_rules_security_js/rules/sec-js/no-csrf-before-method-override.cases.md +12 -0
  44. codelaw_rules_security_js/rules/sec-js/no-csrf-before-method-override.md +128 -0
  45. codelaw_rules_security_js/rules/sec-js/no-dangerously-set-inner-html.cases.md +141 -0
  46. codelaw_rules_security_js/rules/sec-js/no-dangerously-set-inner-html.md +107 -0
  47. codelaw_rules_security_js/rules/sec-js/no-document-cookie-token.cases.md +21 -0
  48. codelaw_rules_security_js/rules/sec-js/no-document-cookie-token.md +89 -0
  49. codelaw_rules_security_js/rules/sec-js/no-dynamic-script-src.cases.md +31 -0
  50. codelaw_rules_security_js/rules/sec-js/no-dynamic-script-src.md +100 -0
  51. codelaw_rules_security_js/rules/sec-js/no-electron-insecure.cases.md +41 -0
  52. codelaw_rules_security_js/rules/sec-js/no-electron-insecure.md +134 -0
  53. codelaw_rules_security_js/rules/sec-js/no-eval.cases.md +52 -0
  54. codelaw_rules_security_js/rules/sec-js/no-eval.md +102 -0
  55. codelaw_rules_security_js/rules/sec-js/no-format-string.cases.md +11 -0
  56. codelaw_rules_security_js/rules/sec-js/no-format-string.md +115 -0
  57. codelaw_rules_security_js/rules/sec-js/no-hardcoded-crypto-key.cases.md +41 -0
  58. codelaw_rules_security_js/rules/sec-js/no-hardcoded-crypto-key.md +96 -0
  59. codelaw_rules_security_js/rules/sec-js/no-hardcoded-secret.cases.md +61 -0
  60. codelaw_rules_security_js/rules/sec-js/no-hardcoded-secret.md +112 -0
  61. codelaw_rules_security_js/rules/sec-js/no-header-injection.cases.md +21 -0
  62. codelaw_rules_security_js/rules/sec-js/no-header-injection.md +95 -0
  63. codelaw_rules_security_js/rules/sec-js/no-incomplete-sanitization.cases.md +41 -0
  64. codelaw_rules_security_js/rules/sec-js/no-incomplete-sanitization.md +113 -0
  65. codelaw_rules_security_js/rules/sec-js/no-incomplete-url-check.cases.md +61 -0
  66. codelaw_rules_security_js/rules/sec-js/no-incomplete-url-check.md +118 -0
  67. codelaw_rules_security_js/rules/sec-js/no-insecure-random.cases.md +51 -0
  68. codelaw_rules_security_js/rules/sec-js/no-insecure-random.md +127 -0
  69. codelaw_rules_security_js/rules/sec-js/no-javascript-url.cases.md +61 -0
  70. codelaw_rules_security_js/rules/sec-js/no-javascript-url.md +102 -0
  71. codelaw_rules_security_js/rules/sec-js/no-jquery-html-sink.cases.md +139 -0
  72. codelaw_rules_security_js/rules/sec-js/no-jquery-html-sink.md +131 -0
  73. codelaw_rules_security_js/rules/sec-js/no-ldap-injection.cases.md +21 -0
  74. codelaw_rules_security_js/rules/sec-js/no-ldap-injection.md +87 -0
  75. codelaw_rules_security_js/rules/sec-js/no-llm-output-to-sink.cases.md +34 -0
  76. codelaw_rules_security_js/rules/sec-js/no-llm-output-to-sink.md +105 -0
  77. codelaw_rules_security_js/rules/sec-js/no-log-injection.cases.md +11 -0
  78. codelaw_rules_security_js/rules/sec-js/no-log-injection.md +113 -0
  79. codelaw_rules_security_js/rules/sec-js/no-mass-assignment.cases.md +51 -0
  80. codelaw_rules_security_js/rules/sec-js/no-mass-assignment.md +100 -0
  81. codelaw_rules_security_js/rules/sec-js/no-new-buffer.cases.md +41 -0
  82. codelaw_rules_security_js/rules/sec-js/no-new-buffer.md +120 -0
  83. codelaw_rules_security_js/rules/sec-js/no-non-literal-fs-filename.cases.md +31 -0
  84. codelaw_rules_security_js/rules/sec-js/no-non-literal-fs-filename.md +151 -0
  85. codelaw_rules_security_js/rules/sec-js/no-non-literal-require.cases.md +41 -0
  86. codelaw_rules_security_js/rules/sec-js/no-non-literal-require.md +88 -0
  87. codelaw_rules_security_js/rules/sec-js/no-nosql-injection.cases.md +41 -0
  88. codelaw_rules_security_js/rules/sec-js/no-nosql-injection.md +114 -0
  89. codelaw_rules_security_js/rules/sec-js/no-open-redirect.cases.md +21 -0
  90. codelaw_rules_security_js/rules/sec-js/no-open-redirect.md +106 -0
  91. codelaw_rules_security_js/rules/sec-js/no-path-traversal.cases.md +54 -0
  92. codelaw_rules_security_js/rules/sec-js/no-path-traversal.md +187 -0
  93. codelaw_rules_security_js/rules/sec-js/no-prompt-injection.cases.md +31 -0
  94. codelaw_rules_security_js/rules/sec-js/no-prompt-injection.md +118 -0
  95. codelaw_rules_security_js/rules/sec-js/no-prototype-pollution.cases.md +41 -0
  96. codelaw_rules_security_js/rules/sec-js/no-prototype-pollution.md +135 -0
  97. codelaw_rules_security_js/rules/sec-js/no-secret-in-log.cases.md +31 -0
  98. codelaw_rules_security_js/rules/sec-js/no-secret-in-log.md +86 -0
  99. codelaw_rules_security_js/rules/sec-js/no-sensitive-get-query.cases.md +21 -0
  100. codelaw_rules_security_js/rules/sec-js/no-sensitive-get-query.md +89 -0
  101. codelaw_rules_security_js/rules/sec-js/no-server-env-in-client.cases.md +42 -0
  102. codelaw_rules_security_js/rules/sec-js/no-server-env-in-client.md +107 -0
  103. codelaw_rules_security_js/rules/sec-js/no-sql-template.cases.md +51 -0
  104. codelaw_rules_security_js/rules/sec-js/no-sql-template.md +112 -0
  105. codelaw_rules_security_js/rules/sec-js/no-ssrf.cases.md +41 -0
  106. codelaw_rules_security_js/rules/sec-js/no-ssrf.md +165 -0
  107. codelaw_rules_security_js/rules/sec-js/no-ssti.cases.md +54 -0
  108. codelaw_rules_security_js/rules/sec-js/no-ssti.md +128 -0
  109. codelaw_rules_security_js/rules/sec-js/no-stack-trace-response.cases.md +41 -0
  110. codelaw_rules_security_js/rules/sec-js/no-stack-trace-response.md +102 -0
  111. codelaw_rules_security_js/rules/sec-js/no-tls-bypass.cases.md +31 -0
  112. codelaw_rules_security_js/rules/sec-js/no-tls-bypass.md +117 -0
  113. codelaw_rules_security_js/rules/sec-js/no-token-in-web-storage.cases.md +41 -0
  114. codelaw_rules_security_js/rules/sec-js/no-token-in-web-storage.md +92 -0
  115. codelaw_rules_security_js/rules/sec-js/no-unsafe-deserialize.cases.md +41 -0
  116. codelaw_rules_security_js/rules/sec-js/no-unsafe-deserialize.md +115 -0
  117. codelaw_rules_security_js/rules/sec-js/no-unsafe-regex.cases.md +41 -0
  118. codelaw_rules_security_js/rules/sec-js/no-unsafe-regex.md +93 -0
  119. codelaw_rules_security_js/rules/sec-js/no-unsanitized-html.cases.md +199 -0
  120. codelaw_rules_security_js/rules/sec-js/no-unsanitized-html.md +143 -0
  121. codelaw_rules_security_js/rules/sec-js/no-unvalidated-dynamic-method.cases.md +34 -0
  122. codelaw_rules_security_js/rules/sec-js/no-unvalidated-dynamic-method.md +94 -0
  123. codelaw_rules_security_js/rules/sec-js/no-user-controlled-auth-bypass.cases.md +11 -0
  124. codelaw_rules_security_js/rules/sec-js/no-user-controlled-auth-bypass.md +102 -0
  125. codelaw_rules_security_js/rules/sec-js/no-weak-cipher.cases.md +41 -0
  126. codelaw_rules_security_js/rules/sec-js/no-weak-cipher.md +95 -0
  127. codelaw_rules_security_js/rules/sec-js/no-weak-hash.cases.md +31 -0
  128. codelaw_rules_security_js/rules/sec-js/no-weak-hash.md +97 -0
  129. codelaw_rules_security_js/rules/sec-js/no-weak-key-size.cases.md +31 -0
  130. codelaw_rules_security_js/rules/sec-js/no-weak-key-size.md +117 -0
  131. codelaw_rules_security_js/rules/sec-js/no-window-open-opener.cases.md +31 -0
  132. codelaw_rules_security_js/rules/sec-js/no-window-open-opener.md +115 -0
  133. codelaw_rules_security_js/rules/sec-js/no-xpath-injection.cases.md +21 -0
  134. codelaw_rules_security_js/rules/sec-js/no-xpath-injection.md +95 -0
  135. codelaw_rules_security_js/rules/sec-js/no-xxe.cases.md +21 -0
  136. codelaw_rules_security_js/rules/sec-js/no-xxe.md +124 -0
  137. codelaw_rules_security_js/rules/sec-js/password-hash-effort.cases.md +41 -0
  138. codelaw_rules_security_js/rules/sec-js/password-hash-effort.md +97 -0
  139. codelaw_rules_security_js/rules/sec-js/postmessage-origin.cases.md +41 -0
  140. codelaw_rules_security_js/rules/sec-js/postmessage-origin.md +125 -0
  141. codelaw_rules_security_js/rules/sec-js/timing-safe-compare.cases.md +41 -0
  142. codelaw_rules_security_js/rules/sec-js/timing-safe-compare.md +142 -0
  143. codelaw_rules_security_js/rules/sec-js/upload-limits.cases.md +21 -0
  144. codelaw_rules_security_js/rules/sec-js/upload-limits.md +115 -0
  145. codelaw_rules_security_js-0.3.0.dist-info/METADATA +193 -0
  146. codelaw_rules_security_js-0.3.0.dist-info/RECORD +148 -0
  147. codelaw_rules_security_js-0.3.0.dist-info/WHEEL +4 -0
  148. codelaw_rules_security_js-0.3.0.dist-info/licenses/LICENSE +23 -0
@@ -0,0 +1,21 @@
1
+ # sec-js/helmet-config — cases
2
+
3
+ ### case: hsts
4
+
5
+ ```js
6
+ helmet({ hsts: false });
7
+ ```
8
+
9
+ ```expect
10
+ 1:1 sec-js/helmet-config
11
+ ```
12
+
13
+ ### case: a configured policy
14
+
15
+ ```js
16
+ helmet({ hsts: { maxAge: 1 } });
17
+ ```
18
+
19
+ ```expect
20
+ (none)
21
+ ```
@@ -0,0 +1,88 @@
1
+ ---
2
+ id: sec-js/helmet-config
3
+ title: "helmet is not given false for a header it sets"
4
+ languages: [javascript, jsx, typescript, tsx]
5
+ fix: manual
6
+ fix_reason: "what the header's directives should be is a decision for the author"
7
+ stability: preview
8
+ security: { cwe: [693], owasp: ["A02:2025"], severity: medium }
9
+ since: 0.3.0
10
+ ---
11
+
12
+ `helmet({ … })` does not set `contentSecurityPolicy`, `frameguard`, `hsts`, `noSniff`, `xssFilter` or the cross-origin policies to `false`.
13
+
14
+ **Why:** Each of these headers closes one class of attack (injected scripts, clickjacking, downgrade to HTTP, MIME sniffing); turning one off opens it again (CWE-693).
15
+
16
+ ```codelaw
17
+ match:
18
+ all:
19
+ - pattern: helmet($$$ARGS)
20
+ - has:
21
+ kind: pair
22
+ stopBy: end
23
+ regex: '^["'']?(contentSecurityPolicy|frameguard|hsts|noSniff|xssFilter|crossOriginOpenerPolicy|crossOriginEmbedderPolicy|crossOriginResourcePolicy|referrerPolicy)["'']?\s*:\s*false\s*$'
24
+ message: "`helmet` is told not to send one of its headers"
25
+ ```
26
+
27
+ ## How to fix
28
+
29
+ 1. Keep the header on and tune it: give `contentSecurityPolicy` the directives the app needs.
30
+ 2. If a header must go for one route, set it off for that route only, with a comment that says why.
31
+
32
+ ## Examples
33
+
34
+ ### JavaScript
35
+
36
+ #### Don't
37
+
38
+ ```js
39
+ app.use(helmet({ contentSecurityPolicy: false }));
40
+ ```
41
+
42
+ #### Do
43
+
44
+ ```js
45
+ app.use(helmet({ contentSecurityPolicy: { directives: { defaultSrc: ["'self'"] } } }));
46
+ ```
47
+
48
+ ### JSX
49
+
50
+ #### Don't
51
+
52
+ ```jsx
53
+ app.use(helmet({ contentSecurityPolicy: false }));
54
+ ```
55
+
56
+ #### Do
57
+
58
+ ```jsx
59
+ app.use(helmet({ contentSecurityPolicy: { directives: { defaultSrc: ["'self'"] } } }));
60
+ ```
61
+
62
+ ### TypeScript
63
+
64
+ #### Don't
65
+
66
+ ```ts
67
+ app.use(helmet({ contentSecurityPolicy: false }));
68
+ ```
69
+
70
+ #### Do
71
+
72
+ ```ts
73
+ app.use(helmet({ contentSecurityPolicy: { directives: { defaultSrc: ["'self'"] } } }));
74
+ ```
75
+
76
+ ### TSX
77
+
78
+ #### Don't
79
+
80
+ ```tsx
81
+ app.use(helmet({ contentSecurityPolicy: false }));
82
+ ```
83
+
84
+ #### Do
85
+
86
+ ```tsx
87
+ app.use(helmet({ contentSecurityPolicy: { directives: { defaultSrc: ["'self'"] } } }));
88
+ ```
@@ -0,0 +1,41 @@
1
+ # sec-js/jwt-verify — cases
2
+
3
+ ### case: an algorithm list
4
+
5
+ ```js
6
+ jwt.verify(t, k, { algorithms: ["HS256"] });
7
+ ```
8
+
9
+ ```expect
10
+ (none)
11
+ ```
12
+
13
+ ### case: the none algorithm
14
+
15
+ ```js
16
+ const o = { algorithms: ["none"] };
17
+ ```
18
+
19
+ ```expect
20
+ 1:13 sec-js/jwt-verify
21
+ ```
22
+
23
+ ### case: decode with no verify in the file
24
+
25
+ ```js
26
+ const c = jwt.decode(token);
27
+ ```
28
+
29
+ ```expect
30
+ 1:11 sec-js/jwt-verify
31
+ ```
32
+
33
+ ### case: three arguments with no algorithms
34
+
35
+ ```js
36
+ jwt.verify(t, k, { audience: "a" });
37
+ ```
38
+
39
+ ```expect
40
+ 1:1 sec-js/jwt-verify
41
+ ```
@@ -0,0 +1,107 @@
1
+ ---
2
+ id: sec-js/jwt-verify
3
+ title: "A JWT is verified with a named algorithm, never `none`"
4
+ languages: [javascript, jsx, typescript, tsx]
5
+ fix: manual
6
+ fix_reason: "the algorithm to name is the one the issuer signs with"
7
+ stability: preview
8
+ security: { cwe: [347], owasp: ["A07:2025"], severity: high }
9
+ since: 0.3.0
10
+ ---
11
+
12
+ `jwt.verify` is given an `algorithms` list, no algorithm is `none`, and `jwt.decode` is not the whole check.
13
+
14
+ **Why:** Without `algorithms` a token can pick its own: `none` carries no signature, and an RSA public key used as an HMAC secret lets anyone mint tokens (CWE-347). `decode` reads a token without checking it.
15
+
16
+ ```codelaw
17
+ match:
18
+ any:
19
+ - pattern: $J.verify($T, $K)
20
+ - all:
21
+ - pattern: $J2.verify($T2, $K2, $O)
22
+ - not:
23
+ has:
24
+ stopBy: end
25
+ regex: 'algorithms'
26
+ - all:
27
+ - kind: pair
28
+ - regex: '(?i)^["'']?algorithms?["'']?\s*:\s*\[?\s*["'']none["'']'
29
+ - all:
30
+ - pattern: $J3.decode($T3)
31
+ - not:
32
+ inside:
33
+ kind: program
34
+ stopBy: end
35
+ has:
36
+ stopBy: end
37
+ regex: '\.verify\(|jwtVerify|verifyJwt'
38
+ constraints:
39
+ J: { regex: '^(jwt|jsonwebtoken|jws)$' }
40
+ J2: { regex: '^(jwt|jsonwebtoken|jws)$' }
41
+ J3: { regex: '^(jwt|jsonwebtoken|jws|jwtDecode)$' }
42
+ message: "This JWT check lets the token choose its algorithm, accepts `none`, or does not verify"
43
+ ```
44
+
45
+ ## How to fix
46
+
47
+ 1. Pass `{ algorithms: ["RS256"] }` (or the one algorithm you issue with) to `jwt.verify`.
48
+ 2. Never put `none` in the list, and never use a public key as an HMAC secret.
49
+ 3. Use `jwt.decode` only to read a token that `jwt.verify` has already accepted.
50
+
51
+ ## Examples
52
+
53
+ ### JavaScript
54
+
55
+ #### Don't
56
+
57
+ ```js
58
+ const claims = jwt.verify(token, publicKey);
59
+ ```
60
+
61
+ #### Do
62
+
63
+ ```js
64
+ const claims = jwt.verify(token, publicKey, { algorithms: ["RS256"] });
65
+ ```
66
+
67
+ ### JSX
68
+
69
+ #### Don't
70
+
71
+ ```jsx
72
+ const claims = jwt.verify(token, publicKey);
73
+ ```
74
+
75
+ #### Do
76
+
77
+ ```jsx
78
+ const claims = jwt.verify(token, publicKey, { algorithms: ["RS256"] });
79
+ ```
80
+
81
+ ### TypeScript
82
+
83
+ #### Don't
84
+
85
+ ```ts
86
+ const claims = jwt.verify(token, publicKey);
87
+ ```
88
+
89
+ #### Do
90
+
91
+ ```ts
92
+ const claims = jwt.verify(token, publicKey, { algorithms: ["RS256"] });
93
+ ```
94
+
95
+ ### TSX
96
+
97
+ #### Don't
98
+
99
+ ```tsx
100
+ const claims = jwt.verify(token, publicKey);
101
+ ```
102
+
103
+ #### Do
104
+
105
+ ```tsx
106
+ const claims = jwt.verify(token, publicKey, { algorithms: ["RS256"] });
107
+ ```
@@ -0,0 +1,22 @@
1
+ # sec-js/missing-rate-limit — cases
2
+
3
+ ### case: a client call is not a route
4
+
5
+ ```js
6
+ api.post("/auth/login", data);
7
+ ```
8
+
9
+ ```expect
10
+ (none)
11
+ ```
12
+
13
+ ### case: a limiter in the file
14
+
15
+ ```js
16
+ const loginLimiter = rateLimit({});
17
+ app.post("/login", handler);
18
+ ```
19
+
20
+ ```expect
21
+ (none)
22
+ ```
@@ -0,0 +1,119 @@
1
+ ---
2
+ id: sec-js/missing-rate-limit
3
+ title: "A login or reset route has a rate limit"
4
+ languages: [javascript, jsx, typescript, tsx]
5
+ fix: manual
6
+ fix_reason: "the limits that fit the route are a decision for the author"
7
+ stability: preview
8
+ security: { cwe: [770, 307], owasp: ["A07:2025"], severity: medium }
9
+ since: 0.3.0
10
+ ---
11
+
12
+ A route that signs in, resets a password or checks a one-time code is registered with middleware, and the file mentions a rate limiter.
13
+
14
+ **Why:** Without a limit an attacker tries passwords, codes and reset tokens as fast as the server answers (CWE-307, CWE-770).
15
+
16
+ ```codelaw
17
+ match:
18
+ all:
19
+ - pattern: $A.post($P, $H)
20
+ - not:
21
+ inside:
22
+ kind: program
23
+ stopBy: end
24
+ has:
25
+ stopBy: end
26
+ regex: '(?i)rate-?limit|limiter|throttle|slow-?down'
27
+ constraints:
28
+ P:
29
+ kind: string
30
+ regex: '(?i)login|signin|sign-in|reset|forgot|otp|verify|2fa|mfa|password|token'
31
+ H:
32
+ any:
33
+ - kind: arrow_function
34
+ - kind: function_expression
35
+ message: "This sign-in route has no rate limit"
36
+ ```
37
+
38
+ ## How to fix
39
+
40
+ 1. Add `express-rate-limit` (or the framework's equivalent) to the route: a few attempts per minute per address and per account.
41
+ 2. Add a lock-out or a growing delay after repeated failures, and log them.
42
+
43
+ ## Examples
44
+
45
+ ### JavaScript
46
+
47
+ #### Don't
48
+
49
+ ```js
50
+ app.post("/login", (req, res) => {
51
+ signIn(req, res);
52
+ });
53
+ ```
54
+
55
+ #### Do
56
+
57
+ ```js
58
+ const loginLimiter = rateLimit({ windowMs: 60000, max: 10 });
59
+ app.post("/login", loginLimiter, (req, res) => {
60
+ signIn(req, res);
61
+ });
62
+ ```
63
+
64
+ ### JSX
65
+
66
+ #### Don't
67
+
68
+ ```jsx
69
+ app.post("/login", (req, res) => {
70
+ signIn(req, res);
71
+ });
72
+ ```
73
+
74
+ #### Do
75
+
76
+ ```jsx
77
+ const loginLimiter = rateLimit({ windowMs: 60000, max: 10 });
78
+ app.post("/login", loginLimiter, (req, res) => {
79
+ signIn(req, res);
80
+ });
81
+ ```
82
+
83
+ ### TypeScript
84
+
85
+ #### Don't
86
+
87
+ ```ts
88
+ app.post("/login", (req, res) => {
89
+ signIn(req, res);
90
+ });
91
+ ```
92
+
93
+ #### Do
94
+
95
+ ```ts
96
+ const loginLimiter = rateLimit({ windowMs: 60000, max: 10 });
97
+ app.post("/login", loginLimiter, (req, res) => {
98
+ signIn(req, res);
99
+ });
100
+ ```
101
+
102
+ ### TSX
103
+
104
+ #### Don't
105
+
106
+ ```tsx
107
+ app.post("/login", (req, res) => {
108
+ signIn(req, res);
109
+ });
110
+ ```
111
+
112
+ #### Do
113
+
114
+ ```tsx
115
+ const loginLimiter = rateLimit({ windowMs: 60000, max: 10 });
116
+ app.post("/login", loginLimiter, (req, res) => {
117
+ signIn(req, res);
118
+ });
119
+ ```
@@ -0,0 +1,11 @@
1
+ # sec-js/no-archive-slip — cases
2
+
3
+ ### case: writeFile
4
+
5
+ ```js
6
+ fs.writeFileSync(path.join(dest, entry.entryName), data);
7
+ ```
8
+
9
+ ```expect
10
+ 1:1 sec-js/no-archive-slip
11
+ ```
@@ -0,0 +1,119 @@
1
+ ---
2
+ id: sec-js/no-archive-slip
3
+ title: "No archive entry name written to disk unchecked"
4
+ languages: [javascript, jsx, typescript, tsx]
5
+ fix: manual
6
+ fix_reason: "what to do with an entry that leaves the folder (skip, stop, report) is a decision for the author"
7
+ stability: preview
8
+ ported_from: [bandit/B202, ruff/S202]
9
+ security: { cwe: [22], owasp: ["A01:2025"], severity: high }
10
+ since: 0.3.0
11
+ ---
12
+
13
+ A file written while unpacking an archive is not named by the entry's own path or name without a check that it stays inside the target folder.
14
+
15
+ **Why:** An entry named `../../etc/cron.d/x` or an absolute path writes outside the folder the code meant: the zip-slip bug (CWE-22).
16
+
17
+ ```codelaw
18
+ match:
19
+ any:
20
+ - pattern: $FS.createWriteStream($P)
21
+ - pattern: $FS.createWriteStream($P, $$$REST)
22
+ - pattern: $FS.writeFile($P)
23
+ - pattern: $FS.writeFile($P, $$$REST)
24
+ - pattern: $FS.writeFileSync($P)
25
+ - pattern: $FS.writeFileSync($P, $$$REST)
26
+ - pattern: $FS.mkdir($P)
27
+ - pattern: $FS.mkdir($P, $$$REST)
28
+ - pattern: $FS.mkdirSync($P)
29
+ - pattern: $FS.mkdirSync($P, $$$REST)
30
+ - pattern: $FS.appendFile($P)
31
+ - pattern: $FS.appendFile($P, $$$REST)
32
+ - pattern: $FS.copyFile($P)
33
+ - pattern: $FS.copyFile($P, $$$REST)
34
+ - pattern: $FS.rename($P)
35
+ - pattern: $FS.rename($P, $$$REST)
36
+ constraints:
37
+ FS: { regex: '^(fs|fsp|fsPromises|fs\.promises|fse|fsExtra)$' }
38
+ P: { regex: '\b(entry|zipEntry|header|file|item|member)\.(path|fileName|entryName|name|filename)\b|\bentry\.entryName\b' }
39
+ message: "An archive entry's own name chooses where this file is written"
40
+ ```
41
+
42
+ ## How to fix
43
+
44
+ 1. Resolve the entry's path against the target folder and reject the entry when the result does not start with `target + path.sep`.
45
+ 2. Skip symbolic links and absolute entry names; set a limit on the number and total size of entries (a zip bomb).
46
+
47
+ ## Examples
48
+
49
+ ### JavaScript
50
+
51
+ #### Don't
52
+
53
+ ```js
54
+ entry.pipe(fs.createWriteStream(path.join(dest, entry.path)));
55
+ ```
56
+
57
+ #### Do
58
+
59
+ ```js
60
+ const target = path.resolve(dest, entry.path);
61
+ if (!target.startsWith(dest + path.sep)) {
62
+ throw new Error("archive entry leaves the folder");
63
+ }
64
+ entry.pipe(fs.createWriteStream(target));
65
+ ```
66
+
67
+ ### JSX
68
+
69
+ #### Don't
70
+
71
+ ```jsx
72
+ entry.pipe(fs.createWriteStream(path.join(dest, entry.path)));
73
+ ```
74
+
75
+ #### Do
76
+
77
+ ```jsx
78
+ const target = path.resolve(dest, entry.path);
79
+ if (!target.startsWith(dest + path.sep)) {
80
+ throw new Error("archive entry leaves the folder");
81
+ }
82
+ entry.pipe(fs.createWriteStream(target));
83
+ ```
84
+
85
+ ### TypeScript
86
+
87
+ #### Don't
88
+
89
+ ```ts
90
+ entry.pipe(fs.createWriteStream(path.join(dest, entry.path)));
91
+ ```
92
+
93
+ #### Do
94
+
95
+ ```ts
96
+ const target = path.resolve(dest, entry.path);
97
+ if (!target.startsWith(dest + path.sep)) {
98
+ throw new Error("archive entry leaves the folder");
99
+ }
100
+ entry.pipe(fs.createWriteStream(target));
101
+ ```
102
+
103
+ ### TSX
104
+
105
+ #### Don't
106
+
107
+ ```tsx
108
+ entry.pipe(fs.createWriteStream(path.join(dest, entry.path)));
109
+ ```
110
+
111
+ #### Do
112
+
113
+ ```tsx
114
+ const target = path.resolve(dest, entry.path);
115
+ if (!target.startsWith(dest + path.sep)) {
116
+ throw new Error("archive entry leaves the folder");
117
+ }
118
+ entry.pipe(fs.createWriteStream(target));
119
+ ```
@@ -0,0 +1,11 @@
1
+ # sec-js/no-bad-tag-filter — cases
2
+
3
+ ### case: a generic tag
4
+
5
+ ```js
6
+ html.replace(/<[^>]*>/g, "");
7
+ ```
8
+
9
+ ```expect
10
+ 1:1 sec-js/no-bad-tag-filter
11
+ ```
@@ -0,0 +1,85 @@
1
+ ---
2
+ id: sec-js/no-bad-tag-filter
3
+ title: "No regular expression that filters HTML tags"
4
+ languages: [javascript, jsx, typescript, tsx]
5
+ fix: manual
6
+ fix_reason: "which tags and attributes may stay is a decision for the author"
7
+ stability: preview
8
+ security: { cwe: [116, 185], owasp: ["A05:2025"], severity: medium }
9
+ since: 0.3.0
10
+ ---
11
+
12
+ A regular expression is not used to strip or test HTML tags (`/<script>/`, `/<[^>]*>/`); a sanitizer is.
13
+
14
+ **Why:** HTML is not regular: `<script >`, `<SCRIPT>`, `<scr<script>ipt>` and a tag split across lines slip past a pattern, and what is left still runs (CWE-116, CWE-185).
15
+
16
+ ```codelaw
17
+ match:
18
+ all:
19
+ - pattern: $S.replace($RE, $R)
20
+ - regex: '\.replace\(\s*/<\\?/?[A-Za-z\[(]'
21
+ message: "A regular expression cannot reliably remove HTML tags"
22
+ ```
23
+
24
+ ## How to fix
25
+
26
+ 1. Sanitize with a library built for it: `DOMPurify.sanitize(html)` in the browser, `sanitize-html` on the server.
27
+ 2. To show markup as text, escape it (`&lt;`) instead of removing it, or write it with `textContent`.
28
+
29
+ ## Examples
30
+
31
+ ### JavaScript
32
+
33
+ #### Don't
34
+
35
+ ```js
36
+ const clean = input.replace(/<script>/gi, "");
37
+ ```
38
+
39
+ #### Do
40
+
41
+ ```js
42
+ const clean = DOMPurify.sanitize(input);
43
+ ```
44
+
45
+ ### JSX
46
+
47
+ #### Don't
48
+
49
+ ```jsx
50
+ const clean = input.replace(/<script>/gi, "");
51
+ ```
52
+
53
+ #### Do
54
+
55
+ ```jsx
56
+ const clean = DOMPurify.sanitize(input);
57
+ ```
58
+
59
+ ### TypeScript
60
+
61
+ #### Don't
62
+
63
+ ```ts
64
+ const clean = input.replace(/<script>/gi, "");
65
+ ```
66
+
67
+ #### Do
68
+
69
+ ```ts
70
+ const clean = DOMPurify.sanitize(input);
71
+ ```
72
+
73
+ ### TSX
74
+
75
+ #### Don't
76
+
77
+ ```tsx
78
+ const clean = input.replace(/<script>/gi, "");
79
+ ```
80
+
81
+ #### Do
82
+
83
+ ```tsx
84
+ const clean = DOMPurify.sanitize(input);
85
+ ```
@@ -0,0 +1,21 @@
1
+ # sec-js/no-biased-random — cases
2
+
3
+ ### case: a power of two is not biased
4
+
5
+ ```js
6
+ const b = crypto.randomBytes(1)[0] % 16;
7
+ ```
8
+
9
+ ```expect
10
+ (none)
11
+ ```
12
+
13
+ ### case: readUInt32BE
14
+
15
+ ```js
16
+ const n = crypto.randomBytes(4).readUInt32BE(0) % 10;
17
+ ```
18
+
19
+ ```expect
20
+ 1:11 sec-js/no-biased-random
21
+ ```