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,127 @@
1
+ ---
2
+ id: sec-js/no-insecure-random
3
+ title: "No Math.random for a token, a secret or a password"
4
+ languages: [javascript, jsx, typescript, tsx]
5
+ fix: suggest
6
+ fix_reason: "the token's length and alphabet change, and anything that checks its shape has to follow; a numeric code needs `crypto.randomInt` instead"
7
+ stability: preview
8
+ ported_from: [eslint-plugin-security/detect-pseudoRandomBytes, bandit/B311, ruff/S311]
9
+ security: { cwe: [338], owasp: ["A04:2025"], severity: high }
10
+ since: 0.3.0
11
+ ---
12
+
13
+ `Math.random()` is not used to make a token, a secret, a password, a nonce, a salt or a session id, and `crypto.pseudoRandomBytes` is not used.
14
+
15
+ **Why:** `Math.random()` is not random enough to guess-proof anything: its next value can be worked out from a few earlier ones (CWE-338); `pseudoRandomBytes` may return predictable bytes.
16
+
17
+ ```codelaw
18
+ match:
19
+ any:
20
+ - all:
21
+ - pattern:
22
+ context: 'const $N = $E'
23
+ selector: variable_declarator
24
+ - regex: '(?i)^[\w$]*(token|secret|passw(or)?d|passwd|pwd|nonce|salt|otp|csrf|session|api_?key|uuid|guid|reset|invite|verification)[\w$]*\s*=\s*Math\.random\(\)\.toString\(\d+\)(\.(slice|substring|substr)\(\d+(,\s*\d+)?\))?$'
25
+ - all:
26
+ - pattern: $N = $E
27
+ - regex: '(?i)^[\w$.]*(token|secret|passw(or)?d|passwd|pwd|nonce|salt|otp|csrf|session|api_?key|uuid|guid|reset|invite|verification)[\w$]*\s*=\s*Math\.random\(\)\.toString\(\d+\)(\.(slice|substring|substr)\(\d+(,\s*\d+)?\))?$'
28
+ - all:
29
+ - kind: variable_declarator
30
+ - regex: '(?is)^[\w$]*(token|secret|passw(or)?d|passwd|pwd|nonce|salt|otp|csrf|session|api_?key|uuid|guid|reset|invite|verification)[\w$]*\s*=.*Math\.random\(\)'
31
+ - all:
32
+ - kind: assignment_expression
33
+ - regex: '(?is)^[\w$.]*(token|secret|passw(or)?d|passwd|pwd|nonce|salt|otp|csrf|session|api_?key|uuid|guid|reset|invite|verification)[\w$]*\s*=.*Math\.random\(\)'
34
+ - all:
35
+ - kind: pair
36
+ - regex: '(?is)^["'']?[\w$]*(token|secret|passw(or)?d|passwd|pwd|nonce|salt|otp|csrf|session|api_?key|uuid|guid|reset|invite|verification)[\w$]*["'']?\s*:.*Math\.random\(\)'
37
+ - pattern: crypto.pseudoRandomBytes($$$P)
38
+ - pattern: pseudoRandomBytes($$$P)
39
+ message: "This value is meant to be unguessable, but `Math.random()` can be predicted"
40
+ fix:
41
+ - replace: { target: $E, with: "crypto.randomUUID()" }
42
+ ```
43
+
44
+ ## How to fix
45
+
46
+
47
+ ## Examples
48
+
49
+ ### JavaScript
50
+
51
+ #### Don't
52
+
53
+ ```js
54
+ const token = Math.random().toString(36).slice(2);
55
+ ```
56
+
57
+ #### Do
58
+
59
+ ```js
60
+ const token = crypto.randomUUID();
61
+ ```
62
+
63
+ #### Fixed
64
+
65
+ ```js
66
+ const token = crypto.randomUUID();
67
+ ```
68
+
69
+ ### JSX
70
+
71
+ #### Don't
72
+
73
+ ```jsx
74
+ const token = Math.random().toString(36).slice(2);
75
+ ```
76
+
77
+ #### Do
78
+
79
+ ```jsx
80
+ const token = crypto.randomUUID();
81
+ ```
82
+
83
+ #### Fixed
84
+
85
+ ```jsx
86
+ const token = crypto.randomUUID();
87
+ ```
88
+
89
+ ### TypeScript
90
+
91
+ #### Don't
92
+
93
+ ```ts
94
+ const token = Math.random().toString(36).slice(2);
95
+ ```
96
+
97
+ #### Do
98
+
99
+ ```ts
100
+ const token = crypto.randomUUID();
101
+ ```
102
+
103
+ #### Fixed
104
+
105
+ ```ts
106
+ const token = crypto.randomUUID();
107
+ ```
108
+
109
+ ### TSX
110
+
111
+ #### Don't
112
+
113
+ ```tsx
114
+ const token = Math.random().toString(36).slice(2);
115
+ ```
116
+
117
+ #### Do
118
+
119
+ ```tsx
120
+ const token = crypto.randomUUID();
121
+ ```
122
+
123
+ #### Fixed
124
+
125
+ ```tsx
126
+ const token = crypto.randomUUID();
127
+ ```
@@ -0,0 +1,61 @@
1
+ # sec-js/no-javascript-url — cases
2
+
3
+ ### case: an anchor
4
+
5
+ ```js
6
+ link.href = "javascript:void(0)";
7
+ ```
8
+
9
+ ```expect
10
+ 1:1 sec-js/no-javascript-url
11
+ ```
12
+
13
+ ### case: location.assign of the hash
14
+
15
+ ```js
16
+ location.assign(location.hash.slice(1));
17
+ ```
18
+
19
+ ```expect
20
+ 1:1 sec-js/no-javascript-url
21
+ ```
22
+
23
+ ### case: a relative path
24
+
25
+ ```js
26
+ location.href = "/home";
27
+ ```
28
+
29
+ ```expect
30
+ (none)
31
+ ```
32
+
33
+ ### case: location.replace
34
+
35
+ ```js
36
+ location.replace("javascript:alert(1)");
37
+ ```
38
+
39
+ ```expect
40
+ 1:1 sec-js/no-javascript-url
41
+ ```
42
+
43
+ ### case: setAttribute
44
+
45
+ ```js
46
+ a.setAttribute("href", "javascript:go()");
47
+ ```
48
+
49
+ ```expect
50
+ 1:1 sec-js/no-javascript-url
51
+ ```
52
+
53
+ ### case: referrer
54
+
55
+ ```js
56
+ location.href = document.referrer;
57
+ ```
58
+
59
+ ```expect
60
+ 1:1 sec-js/no-javascript-url
61
+ ```
@@ -0,0 +1,102 @@
1
+ ---
2
+ id: sec-js/no-javascript-url
3
+ title: "No javascript: URL, no navigation to a URL taken from the address"
4
+ languages: [javascript, jsx, typescript, tsx]
5
+ fix: manual
6
+ fix_reason: "which targets a page may navigate to is a decision for the author"
7
+ stability: preview
8
+ ported_from: [eslint/no-script-url]
9
+ security: { cwe: [79], owasp: ["A05:2025"], severity: high }
10
+ since: 0.3.0
11
+ ---
12
+
13
+ A `javascript:` URL is not written into `location` or `href`, and the address, the referrer or `window.name` is not assigned to `location` or passed to `location.assign` and `location.replace`.
14
+
15
+ **Why:** A `javascript:` URL runs its script in the page when it is followed, and a navigation target taken from the address lets a link choose where the page goes or what it runs (CWE-79).
16
+
17
+ ```codelaw
18
+ match:
19
+ any:
20
+ - kind: assignment_expression
21
+ regex: '^[\w$.\[\]"'']*(location|href)\s*=\s*["''`]\s*(javascript|vbscript|data:text/html)'
22
+ - kind: call_expression
23
+ regex: '^[\w$.]*location\.(assign|replace)\(\s*["''`]\s*(javascript|vbscript|data:text/html)'
24
+ - kind: call_expression
25
+ regex: '^[\w$.]*setAttribute\(\s*["'']href["'']\s*,\s*["''`]\s*(javascript|vbscript)'
26
+ - kind: assignment_expression
27
+ regex: '^[\w$.]*(location|href)\s*=\s*(window\.|document\.)?(location\.(hash|search|href)|URL|documentURI|baseURI|referrer|name)\b'
28
+ - kind: call_expression
29
+ regex: '^[\w$.]*location\.(assign|replace)\(\s*(window\.|document\.)?(location\.(hash|search|href)|URL|documentURI|baseURI|referrer|name)\b'
30
+ message: "This navigation target can run script or is taken from the address"
31
+ ```
32
+
33
+ ## How to fix
34
+
35
+ 1. Link to a path or an `https:` URL; put script in an event handler, not in the URL.
36
+ 2. Parse the target with `new URL(value, location.origin)` and check `protocol` and `origin` against an allow-list before navigating.
37
+
38
+ ## Examples
39
+
40
+ ### JavaScript
41
+
42
+ #### Don't
43
+
44
+ ```js
45
+ window.location.href = "javascript:" + code;
46
+ window.location = location.hash.slice(1);
47
+ ```
48
+
49
+ #### Do
50
+
51
+ ```js
52
+ window.location.href = "/next";
53
+ window.location = new URL(location.hash.slice(1), location.origin).pathname;
54
+ ```
55
+
56
+ ### JSX
57
+
58
+ #### Don't
59
+
60
+ ```jsx
61
+ window.location.href = "javascript:" + code;
62
+ window.location = location.hash.slice(1);
63
+ ```
64
+
65
+ #### Do
66
+
67
+ ```jsx
68
+ window.location.href = "/next";
69
+ window.location = new URL(location.hash.slice(1), location.origin).pathname;
70
+ ```
71
+
72
+ ### TypeScript
73
+
74
+ #### Don't
75
+
76
+ ```ts
77
+ window.location.href = "javascript:" + code;
78
+ window.location = location.hash.slice(1);
79
+ ```
80
+
81
+ #### Do
82
+
83
+ ```ts
84
+ window.location.href = "/next";
85
+ window.location = new URL(location.hash.slice(1), location.origin).pathname;
86
+ ```
87
+
88
+ ### TSX
89
+
90
+ #### Don't
91
+
92
+ ```tsx
93
+ window.location.href = "javascript:" + code;
94
+ window.location = location.hash.slice(1);
95
+ ```
96
+
97
+ #### Do
98
+
99
+ ```tsx
100
+ window.location.href = "/next";
101
+ window.location = new URL(location.hash.slice(1), location.origin).pathname;
102
+ ```
@@ -0,0 +1,139 @@
1
+ # sec-js/no-jquery-html-sink — cases
2
+
3
+ ### case: a selector variable is not a tag
4
+
5
+ ```js
6
+ $(selector).hide();
7
+ ```
8
+
9
+ ```expect
10
+ (none)
11
+ ```
12
+
13
+ ### case: html() with no argument reads
14
+
15
+ ```js
16
+ const h = $("#a").html();
17
+ ```
18
+
19
+ ```expect
20
+ (none)
21
+ ```
22
+
23
+ ### case: jQuery(tag)
24
+
25
+ ```js
26
+ jQuery("<div>" + label + "</div>");
27
+ ```
28
+
29
+ ```expect
30
+ 1:1 sec-js/no-jquery-html-sink
31
+ ```
32
+
33
+ ### case: html with a value
34
+
35
+ ```js
36
+ $("#a").html(userHtml);
37
+ ```
38
+
39
+ ```expect
40
+ 1:1 sec-js/no-jquery-html-sink
41
+ ```
42
+
43
+ ### case: extend: the project function passes
44
+
45
+ ```js options={"sanitizers":[{"name":"cleanHtml","module":"@acme/security"}]}
46
+ import { cleanHtml } from "@acme/security";
47
+ $(el).html(cleanHtml(x));
48
+ ```
49
+
50
+ ```expect
51
+ (none)
52
+ ```
53
+
54
+ ### case: extend: the built-in DOMPurify still passes
55
+
56
+ ```js options={"sanitizers":[{"name":"cleanHtml","module":"@acme/security"}]}
57
+ import DOMPurify from "dompurify";
58
+ $(el).html(DOMPurify.sanitize(x));
59
+ ```
60
+
61
+ ```expect
62
+ (none)
63
+ ```
64
+
65
+ ### case: replace: the project function passes
66
+
67
+ ```js options={"sanitizers":[{"name":"cleanHtml","module":"@acme/security"}],"sanitizers_mode":"replace"}
68
+ import { cleanHtml } from "@acme/security";
69
+ $(el).html(cleanHtml(x));
70
+ ```
71
+
72
+ ```expect
73
+ (none)
74
+ ```
75
+
76
+ ### case: replace: DOMPurify is reported
77
+
78
+ ```js options={"sanitizers":[{"name":"cleanHtml","module":"@acme/security"}],"sanitizers_mode":"replace"}
79
+ import DOMPurify from "dompurify";
80
+ $(el).html(DOMPurify.sanitize(x));
81
+ ```
82
+
83
+ ```expect
84
+ 2:1 sec-js/no-jquery-html-sink
85
+ ```
86
+
87
+ ### case: an aliased import passes
88
+
89
+ ```js options={"sanitizers":[{"name":"cleanHtml","module":"@acme/security"}]}
90
+ import { cleanHtml as clean } from "@acme/security";
91
+ $(el).html(clean(x));
92
+ ```
93
+
94
+ ```expect
95
+ (none)
96
+ ```
97
+
98
+ ### case: a same-named local function is reported
99
+
100
+ ```js
101
+ function sanitizeHtml(x) { return x; }
102
+ $(el).html(sanitizeHtml(x));
103
+ ```
104
+
105
+ ```expect
106
+ 2:1 sec-js/no-jquery-html-sink
107
+ ```
108
+
109
+ ### case: a function of the same name from another module is reported
110
+
111
+ ```js options={"sanitizers":[{"name":"cleanHtml","module":"@acme/security"}]}
112
+ import { cleanHtml } from "left-pad";
113
+ $(el).html(cleanHtml(x));
114
+ ```
115
+
116
+ ```expect
117
+ 2:1 sec-js/no-jquery-html-sink
118
+ ```
119
+
120
+ ### case: the global DOMPurify passes
121
+
122
+ ```js
123
+ $(el).html(DOMPurify.sanitize(x));
124
+ ```
125
+
126
+ ```expect
127
+ (none)
128
+ ```
129
+
130
+ ### case: the built-in sanitize-html import passes
131
+
132
+ ```js
133
+ import sanitizeHtml from "sanitize-html";
134
+ $(el).html(sanitizeHtml(x));
135
+ ```
136
+
137
+ ```expect
138
+ (none)
139
+ ```
@@ -0,0 +1,131 @@
1
+ ---
2
+ id: sec-js/no-jquery-html-sink
3
+ title: "No jQuery call that parses a built string as HTML"
4
+ languages: [javascript, jsx, typescript, tsx]
5
+ fix: manual
6
+ fix_reason: "whether the value is text or markup is a decision for the author"
7
+ stability: preview
8
+ security: { cwe: [79], owasp: ["A05:2025"], severity: high }
9
+ since: 0.3.0
10
+ options:
11
+ sanitizers:
12
+ type: "call[]"
13
+ description: "functions whose result may reach the sink: a callee path (global) or { name, module }; `sanitizers_mode: replace` makes them the only ones that count"
14
+ default:
15
+ - { name: DOMPurify.sanitize, module: [dompurify, isomorphic-dompurify] }
16
+ - DOMPurify.sanitize
17
+ - { name: sanitizeHtml, module: sanitize-html }
18
+ - { name: xss, module: xss }
19
+ - { name: filterXSS, module: xss }
20
+ - { name: escapeHtml, module: escape-html }
21
+ - { name: escape, module: [lodash, lodash-es, lodash/escape, he] }
22
+ - { name: _.escape, module: [lodash, lodash-es] }
23
+ - { name: he.escape, module: he }
24
+ - "*.createHTML"
25
+ ---
26
+
27
+ jQuery's `.html(x)` is not given a value that is not a literal, and `$(x)`, `.append(x)`, `.prepend(x)`, `.after(x)`, `.before(x)`, `.replaceWith(x)` and `.wrap(x)` are not given a template or concatenation that holds a tag.
28
+
29
+ **Your sanitizer:** a value passes when it is a call to one of the `sanitizers`: the built-in list (DOMPurify, sanitize-html, xss, escape-html, lodash and he `escape`, Trusted Types `createHTML`) plus your own, each matched by name and by the module it is imported from, so a local `function sanitize(x) { return x }` does not pass. `sanitizers_mode = "replace"` makes yours the only ones that count. It does not follow a value through a variable: `const c = clean(x)` then `c` at the sink is not a call. Add a project function with `sanitizers = [{ name = "sanitizeHtml", module = "@acme/security" }]`.
30
+
31
+ **Why:** These calls parse their argument as HTML, so markup in a value built into it runs in the page (CWE-79).
32
+
33
+ ```codelaw
34
+ match:
35
+ any:
36
+ - pattern: $O.html($V)
37
+ - pattern: $($H)
38
+ - pattern: jQuery($H)
39
+ - pattern: $O.append($H)
40
+ - pattern: $O.prepend($H)
41
+ - pattern: $O.after($H)
42
+ - pattern: $O.before($H)
43
+ - pattern: $O.replaceWith($H)
44
+ - pattern: $O.wrap($H)
45
+ - pattern: $O.appendTo($H)
46
+ - pattern: $O.prependTo($H)
47
+ - pattern: $O.wrapAll($H)
48
+ - pattern: $O.wrapInner($H)
49
+ constraints:
50
+ V: { not: { any: [ { kind: string }, { regex: '^`[^`$]*`$' } ] } }
51
+ H:
52
+ any:
53
+ - kind: template_string
54
+ - kind: binary_expression
55
+ regex: '<'
56
+ where:
57
+ $V: { not: { calls: sanitizers } }
58
+ message: "A built string is parsed as HTML here; markup in a value inside it runs in the page"
59
+ ```
60
+
61
+ ## How to fix
62
+
63
+ 1. Use `.text(value)` to write a value as text.
64
+ 2. Build elements with `$("<li>").text(name)` and append them, rather than concatenating markup.
65
+ 3. Where markup is needed, pass the value through a sanitizer (`DOMPurify.sanitize`) first.
66
+
67
+ ## Examples
68
+
69
+ ### JavaScript
70
+
71
+ #### Don't
72
+
73
+ ```js
74
+ $("#out").html(comment.body);
75
+ $("#list").append("<li>" + name + "</li>");
76
+ ```
77
+
78
+ #### Do
79
+
80
+ ```js
81
+ $("#out").text(comment.body);
82
+ $("#list").append($("<li>").text(name));
83
+ ```
84
+
85
+ ### JSX
86
+
87
+ #### Don't
88
+
89
+ ```jsx
90
+ $("#out").html(comment.body);
91
+ $("#list").append("<li>" + name + "</li>");
92
+ ```
93
+
94
+ #### Do
95
+
96
+ ```jsx
97
+ $("#out").text(comment.body);
98
+ $("#list").append($("<li>").text(name));
99
+ ```
100
+
101
+ ### TypeScript
102
+
103
+ #### Don't
104
+
105
+ ```ts
106
+ $("#out").html(comment.body);
107
+ $("#list").append("<li>" + name + "</li>");
108
+ ```
109
+
110
+ #### Do
111
+
112
+ ```ts
113
+ $("#out").text(comment.body);
114
+ $("#list").append($("<li>").text(name));
115
+ ```
116
+
117
+ ### TSX
118
+
119
+ #### Don't
120
+
121
+ ```tsx
122
+ $("#out").html(comment.body);
123
+ $("#list").append("<li>" + name + "</li>");
124
+ ```
125
+
126
+ #### Do
127
+
128
+ ```tsx
129
+ $("#out").text(comment.body);
130
+ $("#list").append($("<li>").text(name));
131
+ ```
@@ -0,0 +1,21 @@
1
+ # sec-js/no-ldap-injection — cases
2
+
3
+ ### case: a concatenated filter
4
+
5
+ ```js
6
+ client.search(base, { filter: "(uid=" + name + ")" }, cb);
7
+ ```
8
+
9
+ ```expect
10
+ 1:23 sec-js/no-ldap-injection
11
+ ```
12
+
13
+ ### case: a literal filter
14
+
15
+ ```js
16
+ client.search(base, { filter: "(objectClass=*)" }, cb);
17
+ ```
18
+
19
+ ```expect
20
+ (none)
21
+ ```
@@ -0,0 +1,87 @@
1
+ ---
2
+ id: sec-js/no-ldap-injection
3
+ title: "No LDAP filter built from a template or concatenation"
4
+ languages: [javascript, jsx, typescript, tsx]
5
+ fix: manual
6
+ fix_reason: "which filter classes or escape function the project uses is its own choice"
7
+ stability: preview
8
+ security: { cwe: [90], owasp: ["A05:2025"], severity: high }
9
+ since: 0.3.0
10
+ ---
11
+
12
+ The `filter` of an LDAP search is a literal or built with the library's filter classes, not a template literal or a concatenation.
13
+
14
+ **Why:** A value in a filter can add clauses: `*)(uid=*))(|(uid=*` matches every entry, or bypasses a login (CWE-90).
15
+
16
+ ```codelaw
17
+ match:
18
+ kind: pair
19
+ regex: '(?s)^["'']?filter["'']?\s*:\s*(`[^`]*\$\{|["''][^"'']*["'']\s*\+|[A-Za-z_$][\w$.]*\s*\+)'
20
+ inside:
21
+ stopBy: end
22
+ pattern: $C.search($$$ARGS)
23
+ message: "An LDAP filter is built from a value here; a value in it can add clauses"
24
+ ```
25
+
26
+ ## How to fix
27
+
28
+ 1. Build the filter with the library's filter objects (ldapjs `EqualityFilter`, `AndFilter`) so values are escaped.
29
+ 2. Where a string filter is unavoidable, escape each value for the LDAP filter syntax (RFC 4515: `\\`, `*`, `(`, `)` and NUL) before it is spliced in.
30
+
31
+ ## Examples
32
+
33
+ ### JavaScript
34
+
35
+ #### Don't
36
+
37
+ ```js
38
+ client.search(base, { filter: `(uid=${name})`, scope: "sub" }, callback);
39
+ ```
40
+
41
+ #### Do
42
+
43
+ ```js
44
+ client.search(base, { filter: new EqualityFilter({ attribute: "uid", value: name }), scope: "sub" }, callback);
45
+ ```
46
+
47
+ ### JSX
48
+
49
+ #### Don't
50
+
51
+ ```jsx
52
+ client.search(base, { filter: `(uid=${name})`, scope: "sub" }, callback);
53
+ ```
54
+
55
+ #### Do
56
+
57
+ ```jsx
58
+ client.search(base, { filter: new EqualityFilter({ attribute: "uid", value: name }), scope: "sub" }, callback);
59
+ ```
60
+
61
+ ### TypeScript
62
+
63
+ #### Don't
64
+
65
+ ```ts
66
+ client.search(base, { filter: `(uid=${name})`, scope: "sub" }, callback);
67
+ ```
68
+
69
+ #### Do
70
+
71
+ ```ts
72
+ client.search(base, { filter: new EqualityFilter({ attribute: "uid", value: name }), scope: "sub" }, callback);
73
+ ```
74
+
75
+ ### TSX
76
+
77
+ #### Don't
78
+
79
+ ```tsx
80
+ client.search(base, { filter: `(uid=${name})`, scope: "sub" }, callback);
81
+ ```
82
+
83
+ #### Do
84
+
85
+ ```tsx
86
+ client.search(base, { filter: new EqualityFilter({ attribute: "uid", value: name }), scope: "sub" }, callback);
87
+ ```
@@ -0,0 +1,34 @@
1
+ # sec-js/no-llm-output-to-sink — cases
2
+
3
+ ### case: innerHTML
4
+
5
+ ```js
6
+ const t = response.content[0].text;
7
+ el.innerHTML = t;
8
+ ```
9
+
10
+ ```expect
11
+ 2:1 sec-js/no-llm-output-to-sink
12
+ ```
13
+
14
+ ### case: a SQL call
15
+
16
+ ```js
17
+ const q = completion.choices[0].message.content;
18
+ db.query(q);
19
+ ```
20
+
21
+ ```expect
22
+ 2:1 sec-js/no-llm-output-to-sink
23
+ ```
24
+
25
+ ### case: a shell call
26
+
27
+ ```js
28
+ const c = result.text;
29
+ exec(c);
30
+ ```
31
+
32
+ ```expect
33
+ 2:1 sec-js/no-llm-output-to-sink
34
+ ```