corpus-core 0.1.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 (55) hide show
  1. package/dist/autofix.d.ts +41 -0
  2. package/dist/autofix.js +159 -0
  3. package/dist/constants.d.ts +9 -0
  4. package/dist/constants.js +9 -0
  5. package/dist/cve-database.json +396 -0
  6. package/dist/cve-patterns.d.ts +54 -0
  7. package/dist/cve-patterns.js +124 -0
  8. package/dist/engine.d.ts +6 -0
  9. package/dist/engine.js +71 -0
  10. package/dist/graph-engine.d.ts +56 -0
  11. package/dist/graph-engine.js +412 -0
  12. package/dist/index.d.ts +17 -0
  13. package/dist/index.js +17 -0
  14. package/dist/log.d.ts +7 -0
  15. package/dist/log.js +33 -0
  16. package/dist/logger.d.ts +1 -0
  17. package/dist/logger.js +12 -0
  18. package/dist/memory.d.ts +67 -0
  19. package/dist/memory.js +261 -0
  20. package/dist/pattern-learner.d.ts +82 -0
  21. package/dist/pattern-learner.js +420 -0
  22. package/dist/scanners/code-safety.d.ts +13 -0
  23. package/dist/scanners/code-safety.js +114 -0
  24. package/dist/scanners/confidence-calibrator.d.ts +25 -0
  25. package/dist/scanners/confidence-calibrator.js +58 -0
  26. package/dist/scanners/context-poisoning.d.ts +18 -0
  27. package/dist/scanners/context-poisoning.js +48 -0
  28. package/dist/scanners/cross-user-firewall.d.ts +10 -0
  29. package/dist/scanners/cross-user-firewall.js +24 -0
  30. package/dist/scanners/dependency-checker.d.ts +15 -0
  31. package/dist/scanners/dependency-checker.js +203 -0
  32. package/dist/scanners/exfiltration-guard.d.ts +19 -0
  33. package/dist/scanners/exfiltration-guard.js +49 -0
  34. package/dist/scanners/index.d.ts +12 -0
  35. package/dist/scanners/index.js +12 -0
  36. package/dist/scanners/injection-firewall.d.ts +12 -0
  37. package/dist/scanners/injection-firewall.js +71 -0
  38. package/dist/scanners/scope-enforcer.d.ts +10 -0
  39. package/dist/scanners/scope-enforcer.js +30 -0
  40. package/dist/scanners/secret-detector.d.ts +34 -0
  41. package/dist/scanners/secret-detector.js +188 -0
  42. package/dist/scanners/session-hijack.d.ts +16 -0
  43. package/dist/scanners/session-hijack.js +53 -0
  44. package/dist/scanners/trust-score.d.ts +34 -0
  45. package/dist/scanners/trust-score.js +164 -0
  46. package/dist/scanners/undo-integrity.d.ts +9 -0
  47. package/dist/scanners/undo-integrity.js +38 -0
  48. package/dist/subprocess.d.ts +10 -0
  49. package/dist/subprocess.js +103 -0
  50. package/dist/types.d.ts +117 -0
  51. package/dist/types.js +16 -0
  52. package/dist/yaml-evaluator.d.ts +12 -0
  53. package/dist/yaml-evaluator.js +105 -0
  54. package/package.json +36 -0
  55. package/src/cve-database.json +396 -0
@@ -0,0 +1,396 @@
1
+ {
2
+ "version": 1,
3
+ "lastUpdated": "2026-04-05",
4
+ "patterns": [
5
+ {
6
+ "id": "CVE-2017-5941",
7
+ "name": "node-serialize RCE",
8
+ "pattern": "\\bunserialize\\s*\\(",
9
+ "flags": "gi",
10
+ "description": "node-serialize unserialize() allows remote code execution when an attacker passes an IIFE (Immediately Invoked Function Expression) encoded as a serialized string. The function evaluates JavaScript code within the serialized payload.",
11
+ "severity": "CRITICAL",
12
+ "ecosystem": "npm",
13
+ "affectedPackages": ["node-serialize"],
14
+ "references": ["https://nvd.nist.gov/vuln/detail/CVE-2017-5941", "https://github.com/luin/serialize/issues/4"],
15
+ "codeExample": "var serialize = require('node-serialize');\nvar payload = '{\"rce\":\"_$$ND_FUNC$$_function(){require(\\\"child_process\\\").exec(\\\"whoami\\\")}()\"}';\nserialize.unserialize(payload);",
16
+ "fixExample": "// Never use node-serialize with untrusted input.\n// Use JSON.parse() for deserialization instead:\nconst data = JSON.parse(userInput);"
17
+ },
18
+ {
19
+ "id": "CVE-2021-23337",
20
+ "name": "Lodash template injection",
21
+ "pattern": "_\\.template\\s*\\([^)]*\\b(req\\.|params\\.|query\\.|body\\.|headers\\.|user[Ii]nput|args|argv)",
22
+ "flags": "g",
23
+ "description": "lodash _.template() allows command injection when template strings are constructed from user-controlled input. An attacker can inject template delimiters to execute arbitrary JavaScript code.",
24
+ "severity": "CRITICAL",
25
+ "ecosystem": "npm",
26
+ "affectedPackages": ["lodash", "lodash.template"],
27
+ "references": ["https://nvd.nist.gov/vuln/detail/CVE-2021-23337", "https://github.com/lodash/lodash/issues/5261"],
28
+ "codeExample": "const _ = require('lodash');\nconst compiled = _.template(req.body.templateStr);\nconst result = compiled({ name: 'user' });",
29
+ "fixExample": "// Never pass user input as the template string.\n// Only use static template strings:\nconst compiled = _.template('<h1><%= name %></h1>');\nconst result = compiled({ name: sanitize(req.body.name) });"
30
+ },
31
+ {
32
+ "id": "CVE-2019-10744",
33
+ "name": "Lodash defaultsDeep prototype pollution",
34
+ "pattern": "_\\.defaultsDeep\\s*\\(",
35
+ "flags": "g",
36
+ "description": "lodash defaultsDeep allows prototype pollution via crafted payloads containing __proto__ or constructor.prototype properties, enabling an attacker to inject properties onto Object.prototype.",
37
+ "severity": "HIGH",
38
+ "ecosystem": "npm",
39
+ "affectedPackages": ["lodash", "lodash.defaultsdeep"],
40
+ "references": ["https://nvd.nist.gov/vuln/detail/CVE-2019-10744", "https://github.com/lodash/lodash/pull/4336"],
41
+ "codeExample": "const _ = require('lodash');\nconst payload = JSON.parse('{\"__proto__\":{\"polluted\":true}}');\n_.defaultsDeep({}, payload);",
42
+ "fixExample": "// Upgrade lodash to >= 4.17.12.\n// Sanitize input before passing to defaultsDeep:\nfunction sanitize(obj) {\n const str = JSON.stringify(obj);\n if (str.includes('__proto__') || str.includes('constructor')) throw new Error('Invalid input');\n return obj;\n}"
43
+ },
44
+ {
45
+ "id": "CVE-2022-24999",
46
+ "name": "qs prototype pollution",
47
+ "pattern": "\\bqs\\.parse\\s*\\([^)]*\\{[^}]*(allowPrototypes\\s*:\\s*true)",
48
+ "flags": "g",
49
+ "description": "The qs package allows prototype pollution when allowPrototypes option is enabled. Attackers can inject properties onto Object.prototype via crafted query strings.",
50
+ "severity": "HIGH",
51
+ "ecosystem": "npm",
52
+ "affectedPackages": ["qs"],
53
+ "references": ["https://nvd.nist.gov/vuln/detail/CVE-2022-24999", "https://github.com/ljharb/qs/issues/200"],
54
+ "codeExample": "const qs = require('qs');\nconst parsed = qs.parse(req.query, { allowPrototypes: true });",
55
+ "fixExample": "// Upgrade qs to >= 6.10.3.\n// Never set allowPrototypes to true:\nconst parsed = qs.parse(req.query, { allowPrototypes: false });"
56
+ },
57
+ {
58
+ "id": "CVE-2023-22578",
59
+ "name": "Sequelize raw query SQL injection",
60
+ "pattern": "sequelize\\.(query|literal)\\s*\\(\\s*`[^`]*\\$\\{",
61
+ "flags": "g",
62
+ "description": "Sequelize allows SQL injection when raw queries are constructed using template literals with user-controlled input instead of using parameterized replacements.",
63
+ "severity": "CRITICAL",
64
+ "ecosystem": "npm",
65
+ "affectedPackages": ["sequelize"],
66
+ "references": ["https://nvd.nist.gov/vuln/detail/CVE-2023-22578", "https://github.com/sequelize/sequelize/issues/14519"],
67
+ "codeExample": "const results = await sequelize.query(`SELECT * FROM users WHERE id = ${req.params.id}`);",
68
+ "fixExample": "// Use parameterized replacements:\nconst results = await sequelize.query(\n 'SELECT * FROM users WHERE id = :id',\n { replacements: { id: req.params.id }, type: QueryTypes.SELECT }\n);"
69
+ },
70
+ {
71
+ "id": "CVE-2022-25883",
72
+ "name": "semver ReDoS",
73
+ "pattern": "semver\\.(satisfies|valid|coerce|clean|gt|lt|gte|lte|eq|compare)\\s*\\([^)]*\\b(req\\.|params\\.|query\\.|body\\.|headers\\.|user[Ii]nput)",
74
+ "flags": "g",
75
+ "description": "The semver package is vulnerable to Regular Expression Denial of Service (ReDoS) via crafted version strings. User-controlled input passed directly to semver functions can freeze the event loop.",
76
+ "severity": "HIGH",
77
+ "ecosystem": "npm",
78
+ "affectedPackages": ["semver"],
79
+ "references": ["https://nvd.nist.gov/vuln/detail/CVE-2022-25883", "https://github.com/npm/node-semver/pull/564"],
80
+ "codeExample": "const semver = require('semver');\nconst isValid = semver.valid(req.body.version);",
81
+ "fixExample": "// Upgrade semver to >= 7.5.2.\n// Validate input length before passing to semver:\nconst version = req.body.version;\nif (typeof version !== 'string' || version.length > 256) throw new Error('Invalid version');\nconst isValid = semver.valid(version);"
82
+ },
83
+ {
84
+ "id": "CVE-2021-3749",
85
+ "name": "axios SSRF",
86
+ "pattern": "axios\\.(get|post|put|delete|patch|request|head)\\s*\\(\\s*(req\\.|params\\.|query\\.|body\\.|headers\\.|user[Ii]nput|args)",
87
+ "flags": "g",
88
+ "description": "axios is vulnerable to Server-Side Request Forgery when user-controlled input is passed directly as the URL. Attackers can make the server issue requests to internal services.",
89
+ "severity": "HIGH",
90
+ "ecosystem": "npm",
91
+ "affectedPackages": ["axios"],
92
+ "references": ["https://nvd.nist.gov/vuln/detail/CVE-2021-3749", "https://github.com/axios/axios/issues/3407"],
93
+ "codeExample": "const axios = require('axios');\nconst response = await axios.get(req.body.url);",
94
+ "fixExample": "// Validate and whitelist URLs before making requests:\nconst url = new URL(req.body.url);\nconst allowedHosts = ['api.example.com'];\nif (!allowedHosts.includes(url.hostname)) throw new Error('Forbidden host');\nconst response = await axios.get(url.toString());"
95
+ },
96
+ {
97
+ "id": "CVE-2022-0155",
98
+ "name": "follow-redirects data exposure",
99
+ "pattern": "follow-redirects|maxRedirects\\s*:\\s*([2-9]\\d|\\d{3,})",
100
+ "flags": "g",
101
+ "description": "follow-redirects exposes sensitive headers (Authorization, Cookie) to third-party hosts when following cross-origin redirects. High maxRedirects values increase exposure surface.",
102
+ "severity": "MEDIUM",
103
+ "ecosystem": "npm",
104
+ "affectedPackages": ["follow-redirects"],
105
+ "references": ["https://nvd.nist.gov/vuln/detail/CVE-2022-0155", "https://github.com/follow-redirects/follow-redirects/issues/169"],
106
+ "codeExample": "const http = require('follow-redirects').http;\nhttp.get({ host: userInput, headers: { Authorization: 'Bearer ' + token } });",
107
+ "fixExample": "// Upgrade follow-redirects to >= 1.14.8.\n// Strip sensitive headers on redirect:\nconst http = require('follow-redirects').http;\nhttp.get({\n host: 'trusted.example.com',\n beforeRedirect: (options) => { delete options.headers.authorization; }\n});"
108
+ },
109
+ {
110
+ "id": "CVE-2021-44228-JS",
111
+ "name": "Log injection via template literals",
112
+ "pattern": "(console\\.(log|warn|error|info|debug)|logger\\.(log|warn|error|info|debug|trace|fatal))\\s*\\(\\s*`[^`]*\\$\\{[^}]*(req\\.|params\\.|query\\.|body\\.|headers\\.|user[Ii]nput|args)",
113
+ "flags": "g",
114
+ "description": "Log4Shell-inspired log injection in JavaScript: user-controlled input interpolated directly into log statements via template literals can enable log forging, ANSI escape injection, or downstream log processor exploitation.",
115
+ "severity": "MEDIUM",
116
+ "ecosystem": "npm",
117
+ "affectedPackages": [],
118
+ "references": ["https://nvd.nist.gov/vuln/detail/CVE-2021-44228", "https://owasp.org/www-community/attacks/Log_Injection"],
119
+ "codeExample": "console.log(`User login: ${req.body.username}`);",
120
+ "fixExample": "// Sanitize user input before logging:\nconst sanitized = req.body.username.replace(/[\\n\\r\\t]/g, '');\nconsole.log('User login:', sanitized);"
121
+ },
122
+ {
123
+ "id": "CVE-2020-7660",
124
+ "name": "serialize-javascript code execution",
125
+ "pattern": "serialize\\s*\\(\\s*[^,)]*\\{[^}]*\\bspace\\b",
126
+ "flags": "g",
127
+ "description": "serialize-javascript allows remote code execution through crafted input when the space option is used. Malicious payloads can break out of the serialized context and execute arbitrary code.",
128
+ "severity": "CRITICAL",
129
+ "ecosystem": "npm",
130
+ "affectedPackages": ["serialize-javascript"],
131
+ "references": ["https://nvd.nist.gov/vuln/detail/CVE-2020-7660", "https://github.com/yahoo/serialize-javascript/issues/73"],
132
+ "codeExample": "const serialize = require('serialize-javascript');\nconst output = serialize(userInput, { space: 2 });",
133
+ "fixExample": "// Upgrade serialize-javascript to >= 3.1.0.\n// Avoid serializing untrusted input:\nconst output = serialize(trustedData, { space: 2, isJSON: true });"
134
+ },
135
+ {
136
+ "id": "CVE-2019-11358",
137
+ "name": "jQuery extend prototype pollution",
138
+ "pattern": "\\$\\.extend\\s*\\(\\s*true\\s*,",
139
+ "flags": "g",
140
+ "description": "jQuery $.extend with deep=true allows prototype pollution. Attackers can inject __proto__ properties through crafted objects to pollute Object.prototype.",
141
+ "severity": "MEDIUM",
142
+ "ecosystem": "npm",
143
+ "affectedPackages": ["jquery"],
144
+ "references": ["https://nvd.nist.gov/vuln/detail/CVE-2019-11358", "https://github.com/jquery/jquery/commit/753d591aea698e57d6db58c9f722cd0808619b1b"],
145
+ "codeExample": "$.extend(true, {}, JSON.parse(userInput));",
146
+ "fixExample": "// Upgrade jQuery to >= 3.4.0.\n// Filter dangerous keys from input:\nfunction safeExtend(target, source) {\n for (const key of Object.keys(source)) {\n if (key === '__proto__' || key === 'constructor' || key === 'prototype') continue;\n target[key] = source[key];\n }\n return target;\n}"
147
+ },
148
+ {
149
+ "id": "CVE-2023-26136",
150
+ "name": "tough-cookie prototype pollution",
151
+ "pattern": "tough-cookie|new\\s+Cookie\\s*\\(",
152
+ "flags": "g",
153
+ "description": "tough-cookie is vulnerable to prototype pollution via the Cookie constructor when processing crafted cookie strings containing __proto__ keys.",
154
+ "severity": "MEDIUM",
155
+ "ecosystem": "npm",
156
+ "affectedPackages": ["tough-cookie"],
157
+ "references": ["https://nvd.nist.gov/vuln/detail/CVE-2023-26136", "https://github.com/salesforce/tough-cookie/issues/282"],
158
+ "codeExample": "const { Cookie } = require('tough-cookie');\nconst cookie = Cookie.parse(userInput);",
159
+ "fixExample": "// Upgrade tough-cookie to >= 4.1.3.\n// Validate cookie strings before parsing:\nif (userInput.includes('__proto__') || userInput.includes('constructor')) {\n throw new Error('Invalid cookie');\n}"
160
+ },
161
+ {
162
+ "id": "CVE-2022-29078",
163
+ "name": "EJS template injection",
164
+ "pattern": "ejs\\.render(File)?\\s*\\([^)]*\\b(req\\.|params\\.|query\\.|body\\.|settings\\s*\\[)",
165
+ "flags": "g",
166
+ "description": "EJS allows server-side template injection when user-controlled input is passed into render options or when settings object is exposed. Attackers can achieve RCE through crafted view options.",
167
+ "severity": "CRITICAL",
168
+ "ecosystem": "npm",
169
+ "affectedPackages": ["ejs"],
170
+ "references": ["https://nvd.nist.gov/vuln/detail/CVE-2022-29078", "https://github.com/mde/ejs/issues/720"],
171
+ "codeExample": "app.get('/page', (req, res) => {\n res.render('page', req.query);\n});",
172
+ "fixExample": "// Upgrade EJS to >= 3.1.7.\n// Never pass user input directly as render options:\napp.get('/page', (req, res) => {\n res.render('page', { title: sanitize(req.query.title) });\n});"
173
+ },
174
+ {
175
+ "id": "CVE-2018-3721",
176
+ "name": "Lodash merge prototype pollution",
177
+ "pattern": "_\\.merge\\s*\\([^)]*\\b(req\\.|params\\.|query\\.|body\\.|headers\\.|user[Ii]nput|JSON\\.parse)",
178
+ "flags": "g",
179
+ "description": "lodash _.merge allows prototype pollution when merging objects from untrusted sources. Attackers can inject __proto__ properties to pollute Object.prototype and modify application behavior.",
180
+ "severity": "HIGH",
181
+ "ecosystem": "npm",
182
+ "affectedPackages": ["lodash", "lodash.merge"],
183
+ "references": ["https://nvd.nist.gov/vuln/detail/CVE-2018-3721", "https://github.com/lodash/lodash/commit/d299b0f"],
184
+ "codeExample": "const _ = require('lodash');\nconst config = _.merge({}, JSON.parse(req.body.settings));",
185
+ "fixExample": "// Upgrade lodash to >= 4.17.5.\n// Sanitize input before merging:\nfunction stripProto(obj) {\n return JSON.parse(JSON.stringify(obj), (key, value) => {\n if (key === '__proto__' || key === 'constructor') return undefined;\n return value;\n });\n}\nconst config = _.merge({}, stripProto(req.body.settings));"
186
+ },
187
+ {
188
+ "id": "CVE-2021-32804",
189
+ "name": "tar path traversal",
190
+ "pattern": "tar\\.(extract|x)\\s*\\(|tar\\.Extract|new\\s+tar\\.Unpack",
191
+ "flags": "g",
192
+ "description": "The tar package allows path traversal via crafted tar entries with absolute paths or ../ sequences. Files can be written outside the intended extraction directory.",
193
+ "severity": "HIGH",
194
+ "ecosystem": "npm",
195
+ "affectedPackages": ["tar"],
196
+ "references": ["https://nvd.nist.gov/vuln/detail/CVE-2021-32804", "https://github.com/npm/node-tar/security/advisories/GHSA-3jfq-g458-7qm9"],
197
+ "codeExample": "const tar = require('tar');\ntar.extract({ file: userUpload, cwd: '/tmp/extract' });",
198
+ "fixExample": "// Upgrade tar to >= 6.1.9.\n// Validate entries before extraction:\nconst tar = require('tar');\ntar.extract({\n file: userUpload,\n cwd: '/tmp/extract',\n filter: (path) => !path.includes('..') && !path.startsWith('/')\n});"
199
+ },
200
+ {
201
+ "id": "CVE-2019-10758",
202
+ "name": "mongo-express RCE",
203
+ "pattern": "mongo-express|mongoExpress\\s*\\(",
204
+ "flags": "g",
205
+ "description": "mongo-express allows remote code execution via crafted BSON data in the document editing interface. When exposed publicly, attackers can execute arbitrary commands on the server.",
206
+ "severity": "CRITICAL",
207
+ "ecosystem": "npm",
208
+ "affectedPackages": ["mongo-express"],
209
+ "references": ["https://nvd.nist.gov/vuln/detail/CVE-2019-10758", "https://github.com/mongo-express/mongo-express/issues/577"],
210
+ "codeExample": "const mongoExpress = require('mongo-express/lib/middleware');\napp.use('/mongo', mongoExpress(config));",
211
+ "fixExample": "// Upgrade mongo-express to >= 0.54.0.\n// Never expose mongo-express to the public internet.\n// Use authentication and restrict to localhost:\napp.use('/mongo', requireAuth, mongoExpress(config));\n// Bind to localhost only:\napp.listen(8081, '127.0.0.1');"
212
+ },
213
+ {
214
+ "id": "CVE-2023-36665",
215
+ "name": "protobuf.js prototype pollution",
216
+ "pattern": "protobufjs|protobuf\\.load|protobuf\\.parse",
217
+ "flags": "g",
218
+ "description": "protobuf.js allows prototype pollution through crafted protobuf messages containing __proto__ fields. This can lead to denial of service or remote code execution.",
219
+ "severity": "HIGH",
220
+ "ecosystem": "npm",
221
+ "affectedPackages": ["protobufjs"],
222
+ "references": ["https://nvd.nist.gov/vuln/detail/CVE-2023-36665", "https://github.com/protobufjs/protobuf.js/security/advisories/GHSA-h755-8qp9-cq85"],
223
+ "codeExample": "const protobuf = require('protobufjs');\nconst root = await protobuf.load('schema.proto');\nconst decoded = MessageType.decode(userBuffer);",
224
+ "fixExample": "// Upgrade protobufjs to >= 7.2.5.\n// Validate and freeze prototypes after decoding:\nconst decoded = MessageType.decode(userBuffer);\nconst safe = MessageType.toObject(decoded);\nObject.freeze(Object.getPrototypeOf(safe));"
225
+ },
226
+ {
227
+ "id": "CORPUS-PATH-TRAVERSAL",
228
+ "name": "Path traversal via user input",
229
+ "pattern": "(readFile|readFileSync|createReadStream|access|stat|writeFile|writeFileSync|unlink|rmdir|mkdir|appendFile|rename|copyFile)\\s*\\([^)]*\\.\\.[\\\\/]|\\.\\.(/|\\\\\\\\)",
230
+ "flags": "g",
231
+ "description": "Path traversal occurs when user-controlled input containing ../ sequences is used in filesystem operations, allowing access to files outside the intended directory.",
232
+ "severity": "HIGH",
233
+ "ecosystem": "npm",
234
+ "affectedPackages": [],
235
+ "references": ["https://owasp.org/www-community/attacks/Path_Traversal"],
236
+ "codeExample": "const filePath = path.join('/uploads', req.params.filename);\nconst content = fs.readFileSync(filePath);",
237
+ "fixExample": "// Resolve and validate the path stays within the intended directory:\nconst basePath = path.resolve('/uploads');\nconst filePath = path.resolve('/uploads', req.params.filename);\nif (!filePath.startsWith(basePath)) throw new Error('Path traversal detected');\nconst content = fs.readFileSync(filePath);"
238
+ },
239
+ {
240
+ "id": "CORPUS-SQL-INJECTION",
241
+ "name": "SQL injection via string concatenation",
242
+ "pattern": "(query|execute|raw|prepare)\\s*\\(\\s*(['\"`]\\s*(SELECT|INSERT|UPDATE|DELETE|DROP|ALTER|CREATE)\\b[^'\"`)]*\\s*\\+|`[^`]*(SELECT|INSERT|UPDATE|DELETE|DROP|ALTER|CREATE)\\b[^`]*\\$\\{)",
243
+ "flags": "gi",
244
+ "description": "SQL injection occurs when user input is concatenated or interpolated into SQL query strings instead of using parameterized queries or prepared statements.",
245
+ "severity": "CRITICAL",
246
+ "ecosystem": "npm",
247
+ "affectedPackages": [],
248
+ "references": ["https://owasp.org/www-community/attacks/SQL_Injection"],
249
+ "codeExample": "const result = await db.query('SELECT * FROM users WHERE id = ' + req.params.id);\nconst result = await db.query(`SELECT * FROM users WHERE name = '${req.body.name}'`);",
250
+ "fixExample": "// Use parameterized queries:\nconst result = await db.query('SELECT * FROM users WHERE id = $1', [req.params.id]);"
251
+ },
252
+ {
253
+ "id": "CORPUS-SSRF",
254
+ "name": "SSRF via user-controlled URL",
255
+ "pattern": "(fetch|axios\\.(get|post|put|delete|patch|request)|http\\.get|https\\.get|http\\.request|https\\.request|got|superagent|request)\\s*\\(\\s*(req\\.|params\\.|query\\.|body\\.|headers\\.|user[Ii]nput|args\\[|process\\.argv)",
256
+ "flags": "g",
257
+ "description": "Server-Side Request Forgery occurs when user-controlled input is used as a URL in server-side HTTP requests, allowing attackers to access internal services and resources.",
258
+ "severity": "HIGH",
259
+ "ecosystem": "npm",
260
+ "affectedPackages": [],
261
+ "references": ["https://owasp.org/www-community/attacks/Server_Side_Request_Forgery"],
262
+ "codeExample": "const response = await fetch(req.body.url);\nconst data = await axios.get(req.query.endpoint);",
263
+ "fixExample": "// Validate and whitelist URLs:\nconst url = new URL(req.body.url);\nconst allowedHosts = ['api.trusted.com'];\nif (!allowedHosts.includes(url.hostname)) throw new Error('Forbidden host');\nif (['127.0.0.1', 'localhost', '0.0.0.0'].includes(url.hostname)) throw new Error('Blocked');\nconst response = await fetch(url.toString());"
264
+ },
265
+ {
266
+ "id": "CORPUS-UNSAFE-DESER",
267
+ "name": "Unsafe deserialization of user input",
268
+ "pattern": "JSON\\.parse\\s*\\(\\s*(req\\.|params\\.|query\\.|body\\.|headers\\.|user[Ii]nput|Buffer\\.from|readFileSync|await\\s+fetch)",
269
+ "flags": "g",
270
+ "description": "Parsing JSON from untrusted sources without validation can lead to prototype pollution if the parsed object contains __proto__ keys, or unexpected behavior from crafted payloads.",
271
+ "severity": "MEDIUM",
272
+ "ecosystem": "npm",
273
+ "affectedPackages": [],
274
+ "references": ["https://owasp.org/www-project-web-security-testing-guide/latest/4-Web_Application_Security_Testing/07-Input_Validation_Testing/17-Testing_for_HTTP_Incoming_Requests"],
275
+ "codeExample": "const data = JSON.parse(req.body.payload);\nObject.assign(config, data);",
276
+ "fixExample": "// Validate parsed JSON against a schema:\nconst data = JSON.parse(req.body.payload);\nconst validated = schema.validate(data);\nif (validated.error) throw new Error('Invalid input');"
277
+ },
278
+ {
279
+ "id": "CORPUS-CMD-INJECTION",
280
+ "name": "Command injection via exec/spawn",
281
+ "pattern": "(exec|execSync|spawn|spawnSync|execFile|execFileSync)\\s*\\(\\s*(`[^`]*\\$\\{|[^,)]*\\+\\s*(req\\.|params\\.|query\\.|body\\.|headers\\.|user[Ii]nput|args))",
282
+ "flags": "g",
283
+ "description": "Command injection occurs when user-controlled input is interpolated or concatenated into shell commands executed via child_process functions.",
284
+ "severity": "CRITICAL",
285
+ "ecosystem": "npm",
286
+ "affectedPackages": [],
287
+ "references": ["https://owasp.org/www-community/attacks/Command_Injection"],
288
+ "codeExample": "const { exec } = require('child_process');\nexec(`git clone ${req.body.repoUrl}`);",
289
+ "fixExample": "// Use execFile with argument arrays instead of exec:\nconst { execFile } = require('child_process');\nexecFile('git', ['clone', '--', req.body.repoUrl]);"
290
+ },
291
+ {
292
+ "id": "CORPUS-OPEN-REDIRECT",
293
+ "name": "Open redirect via user-controlled URL",
294
+ "pattern": "(res\\.redirect|location\\.href\\s*=|window\\.location\\s*=|location\\.replace)\\s*\\(\\s*(req\\.|params\\.|query\\.|body\\.|headers\\.|user[Ii]nput)",
295
+ "flags": "g",
296
+ "description": "Open redirect occurs when a web application redirects users to a URL controlled by attacker input, enabling phishing attacks and credential theft.",
297
+ "severity": "MEDIUM",
298
+ "ecosystem": "npm",
299
+ "affectedPackages": [],
300
+ "references": ["https://owasp.org/www-project-web-security-testing-guide/latest/4-Web_Application_Security_Testing/11-Client-side_Testing/04-Testing_for_Client-side_URL_Redirect"],
301
+ "codeExample": "app.get('/redirect', (req, res) => {\n res.redirect(req.query.url);\n});",
302
+ "fixExample": "// Validate redirect URL against an allowlist:\nconst allowedPaths = ['/dashboard', '/profile'];\nconst target = req.query.url;\nif (!allowedPaths.includes(target)) return res.status(400).send('Invalid redirect');\nres.redirect(target);"
303
+ },
304
+ {
305
+ "id": "CORPUS-XXE",
306
+ "name": "XXE via XML parsing without entity restriction",
307
+ "pattern": "(xml2js|libxmljs|DOMParser|parseXml|parseString|xml\\.parse|sax\\.parser|fast-xml-parser)\\s*[.(]",
308
+ "flags": "g",
309
+ "description": "XML External Entity (XXE) injection occurs when XML parsers process external entity references in untrusted XML input, potentially leading to file disclosure, SSRF, or denial of service.",
310
+ "severity": "HIGH",
311
+ "ecosystem": "npm",
312
+ "affectedPackages": [],
313
+ "references": ["https://owasp.org/www-community/vulnerabilities/XML_External_Entity_(XXE)_Processing"],
314
+ "codeExample": "const xml2js = require('xml2js');\nconst parser = new xml2js.Parser();\nparser.parseString(userXml, callback);",
315
+ "fixExample": "// Disable external entities and DTD processing:\nconst parser = new xml2js.Parser({\n explicitRoot: false,\n // xml2js is generally safe, but validate input:\n});\n// For libxmljs: { noent: false, dtdload: false, dtdattr: false }\n// Always sanitize XML input before parsing."
316
+ },
317
+ {
318
+ "id": "CORPUS-INSECURE-RANDOM",
319
+ "name": "Insecure randomness for security purposes",
320
+ "pattern": "Math\\.random\\s*\\(\\s*\\)\\s*[^;]*\\b(token|secret|key|password|salt|nonce|csrf|session|auth|otp|api[Kk]ey|apiSecret)",
321
+ "flags": "gi",
322
+ "description": "Math.random() is not cryptographically secure and should never be used to generate tokens, secrets, keys, or other security-sensitive values. It uses a predictable PRNG that can be reverse-engineered.",
323
+ "severity": "HIGH",
324
+ "ecosystem": "npm",
325
+ "affectedPackages": [],
326
+ "references": ["https://owasp.org/www-community/vulnerabilities/Insecure_Randomness"],
327
+ "codeExample": "const token = Math.random().toString(36).substring(2);\nconst apiKey = 'key_' + Math.random().toString(36);",
328
+ "fixExample": "// Use crypto.randomBytes or crypto.randomUUID:\nconst crypto = require('crypto');\nconst token = crypto.randomBytes(32).toString('hex');\nconst apiKey = 'key_' + crypto.randomUUID();"
329
+ },
330
+ {
331
+ "id": "CORPUS-HARDCODED-JWT",
332
+ "name": "Hardcoded JWT signing secret",
333
+ "pattern": "jwt\\.sign\\s*\\([^)]*,\\s*['\"][^'\"]{1,64}['\"]",
334
+ "flags": "g",
335
+ "description": "Signing JWTs with hardcoded string literals means the secret is embedded in source code. If the repository is leaked or the code is decompiled, all tokens can be forged.",
336
+ "severity": "HIGH",
337
+ "ecosystem": "npm",
338
+ "affectedPackages": [],
339
+ "references": ["https://owasp.org/www-project-web-security-testing-guide/latest/4-Web_Application_Security_Testing/06-Session_Management_Testing/10-Testing_JSON_Web_Tokens"],
340
+ "codeExample": "const jwt = require('jsonwebtoken');\nconst token = jwt.sign({ userId: 1 }, 'my-super-secret-key');",
341
+ "fixExample": "// Load secret from environment variable:\nconst token = jwt.sign({ userId: 1 }, process.env.JWT_SECRET);"
342
+ },
343
+ {
344
+ "id": "CORPUS-NO-RATE-LIMIT",
345
+ "name": "Auth endpoint without rate limiting",
346
+ "pattern": "(app|router)\\.(post|put)\\s*\\(\\s*['\"`]\\/(login|signin|auth|register|signup|reset-password|forgot-password|verify|token|oauth)['\"`]\\s*,\\s*(async\\s+)?\\(?(req|ctx)",
347
+ "flags": "gi",
348
+ "description": "Authentication endpoints without rate limiting are vulnerable to brute-force attacks, credential stuffing, and enumeration attacks.",
349
+ "severity": "MEDIUM",
350
+ "ecosystem": "npm",
351
+ "affectedPackages": [],
352
+ "references": ["https://owasp.org/www-community/controls/Blocking_Brute_Force_Attacks"],
353
+ "codeExample": "app.post('/login', async (req, res) => {\n const user = await authenticate(req.body.email, req.body.password);\n});",
354
+ "fixExample": "// Add rate limiting middleware:\nconst rateLimit = require('express-rate-limit');\nconst authLimiter = rateLimit({ windowMs: 15 * 60 * 1000, max: 10 });\napp.post('/login', authLimiter, async (req, res) => {\n const user = await authenticate(req.body.email, req.body.password);\n});"
355
+ },
356
+ {
357
+ "id": "CORPUS-INSECURE-COOKIE",
358
+ "name": "Cookie without secure/httpOnly flags",
359
+ "pattern": "(res\\.cookie|setCookie|cookies\\.set)\\s*\\([^)]*\\{[^}]*(?!secure\\s*:\\s*true|httpOnly\\s*:\\s*true)[^}]*\\}",
360
+ "flags": "g",
361
+ "description": "Setting cookies without the secure and httpOnly flags allows session hijacking via network sniffing (no secure flag) and XSS-based cookie theft (no httpOnly flag).",
362
+ "severity": "MEDIUM",
363
+ "ecosystem": "npm",
364
+ "affectedPackages": [],
365
+ "references": ["https://owasp.org/www-community/controls/SecureCookieAttribute"],
366
+ "codeExample": "res.cookie('session', token, { maxAge: 900000 });",
367
+ "fixExample": "res.cookie('session', token, {\n maxAge: 900000,\n httpOnly: true,\n secure: true,\n sameSite: 'strict'\n});"
368
+ },
369
+ {
370
+ "id": "CORPUS-TIMING-ATTACK",
371
+ "name": "Timing attack in secret comparison",
372
+ "pattern": "(===|==|!==|!=)\\s*(secret|token|apiKey|password|hash|hmac|signature|digest)|\\b(secret|token|apiKey|password|hash|hmac|signature|digest)\\s*(===|==|!==|!=)",
373
+ "flags": "g",
374
+ "description": "Using standard equality operators to compare secrets enables timing attacks. The comparison short-circuits on the first mismatched character, leaking information about the secret's value.",
375
+ "severity": "MEDIUM",
376
+ "ecosystem": "npm",
377
+ "affectedPackages": [],
378
+ "references": ["https://owasp.org/www-community/attacks/Timing_attack"],
379
+ "codeExample": "if (req.headers['x-api-key'] === apiKey) {\n // allow access\n}",
380
+ "fixExample": "// Use constant-time comparison:\nconst crypto = require('crypto');\nconst isValid = crypto.timingSafeEqual(\n Buffer.from(req.headers['x-api-key']),\n Buffer.from(apiKey)\n);"
381
+ },
382
+ {
383
+ "id": "CORPUS-MASS-ASSIGNMENT",
384
+ "name": "Mass assignment via spread of user input",
385
+ "pattern": "(create|update|insert|save|findOneAndUpdate|updateOne|updateMany|findByIdAndUpdate|upsert)\\s*\\(\\s*(\\{\\s*\\.\\.\\.\\s*(req\\.|body\\.|params\\.|query\\.|user[Ii]nput)|(req\\.body|req\\.query|req\\.params)\\s*[,)])",
386
+ "flags": "g",
387
+ "description": "Mass assignment occurs when user-supplied input is directly spread into or passed to database operations, allowing attackers to set fields they should not control (e.g., isAdmin, role, balance).",
388
+ "severity": "HIGH",
389
+ "ecosystem": "npm",
390
+ "affectedPackages": [],
391
+ "references": ["https://owasp.org/API-Security/editions/2023/en/0xa3-broken-object-property-level-authorization/"],
392
+ "codeExample": "await User.create(req.body);\nawait User.update({ ...req.body }, { where: { id } });",
393
+ "fixExample": "// Explicitly pick allowed fields:\nconst { name, email } = req.body;\nawait User.create({ name, email });\n// Or use an allowlist:\nconst allowed = ['name', 'email', 'avatar'];\nconst data = Object.fromEntries(\n Object.entries(req.body).filter(([k]) => allowed.includes(k))\n);\nawait User.create(data);"
394
+ }
395
+ ]
396
+ }