VNX-1287: Improper Validation of Specified Type of Input
Detects JavaScript/TypeScript request values whose type the client chooses (query-string arrays and objects, JSON body fields) used as strings with no type check: string methods or .length on req.query/req.body/ctx.query fields. The Python form is reported by VNX-241.
| Field | Value |
|---|---|
| Rule ID | VNX-1287 |
| Severity | Low |
| SARIF level | note |
| Kind | sast |
| Languages | JavaScript / TypeScript |
| CWE | CWE-1287 |
| CAPEC | CAPEC-66 |
| ATT&CK | T1190 |
| CWSS vector | CWSS:1.0/TI:L/AP:RU/AL:S/IC:N/FC:LT/RP:RU/RL:S/AV:L/AS:N/IN:A/SC:A/BI:L/DI:H/EX:L/EC:N/P:L |
| Tags | input-validation-type cwe-1287 |
| Source | internal/sast/rules/vnx-1287.rego |
Overview
VNX-1287 maps to CWE-1287: Improper Validation of Specified Type of Input. Express’s query parser turns ?q[]=a into an array and ?q[x]=1 into an object, and a JSON body field can be any JSON type. Code that treats such a value as a string either throws (a crash or a 500) or, for length, includes, indexOf and startsWith checks, gets an answer for an array and lets the request past the check.
Reported:
- JavaScript/TypeScript: a string method (
toLowerCase,trim,split,startsWith,endsWith,includes,indexOf,replace,match,search,slice,substring,concat,repeatand others) or.lengthon a field ofreq.query,req.body,request.body,ctx.queryorctx.request.body, directly or through a variable or destructured name assigned from it in the 10 lines above. The same weakness in Python, astrmethod on a field of a JSON body (request.json,request.get_json(), DRFrequest.data,json.loads(request.body)), is reported by VNX-241, and this rule does not report it a second time.
Not reported: route params (always strings); values checked with typeof or Array.isArray, or coerced with String(); files that use express-validator, Joi, zod, yup, celebrate, ajv, class-validator or superstruct; comments and strings.
What Gets Flagged
if (req.body.email.length !== 0 && req.body.password.length !== 0) { // FLAGGED
req.body.email = req.body.email.trim(); // FLAGGED
}
const { tags } = req.query;
const list = tags.split(','); // FLAGGED: ?tags[]=a is an array
What Is Not Flagged
const q = req.query.q;
if (typeof q !== 'string') return res.status(400).end();
const term = q.toLowerCase();
Remediation
- Check the type (
typeof value === 'string') before using a request value as a string. - Validate request bodies and query strings against a schema.
- In Express, consider
app.set('query parser', 'simple')so query values are never arrays or objects.
References
Suppressing this rule
Put a nosec comment on the line, or on line 1 to cover the whole file. Use the comment marker of the file’s language (#, //, -- or ;):
# nosec vnx-1287
// nosec vnx-1287
Or record an ignore rule: vulnetix ignore add --rule vnx-1287 --reason "...". See Suppressing findings.