# VNX-1027: Request data in a require() or import() module specifier (Node.js)

Reports Node.js require(), require.resolve() and dynamic import() calls whose module specifier contains Express or Koa request data.

| Field | Value |
|---|---|
| Rule ID | `VNX-1027` |
| Severity | Low |
| SARIF level | `note` |
| Kind | `sast` |
| Languages | JavaScript / TypeScript |
| CWE | [CWE-1027](https://cwe.mitre.org/data/definitions/1027.html) |
| CAPEC | [CAPEC-66](https://capec.mitre.org/data/definitions/66.html) |
| ATT&CK | [T1190](https://attack.mitre.org/techniques/T1190/) |
| CWSS vector | `CWSS:1.0/TI:L/AP:A/AL:A/IC:N/FC:LT/RP:N/RL:A/AV:I/AS:N/IN:A/SC:A/BI:L/DI:H/EX:L/EC:N/P:L` |
| Tags | `injection` `dynamic-require` `code-injection` `cwe-1027` |
| Source | [`internal/sast/rules/vnx-1027.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-1027.rego) |

## Overview

VNX-1027 maps to [CWE-1027: OWASP Top Ten 2017 Category A1 - Injection](https://cwe.mitre.org/data/definitions/1027.html). It covers the injection class that has no other rule: the module a Node.js process loads chosen by the request. It reports `require()`, `require.resolve()` and dynamic `import()` whose specifier contains Express/Koa request data (`req.query`, `req.body`, `req.params`, `req.headers`, `req.cookies`, `ctx.query`, `ctx.params`, `ctx.request.body`), directly, through a variable assigned or destructured from it a few lines above, or concatenated or interpolated into a path.

Not reported: constant specifiers, lookups through an object or `Map` (`require(PLUGINS[name])`), values checked against an allowlist (`includes`, `has`, `indexOf`, `switch`, `===`) in the lines between, comments and test files. Other A1 injection classes have their own rules: eval/Function/vm (VNX-913, VNX-94), child_process (VNX-NODE-003), SQL (VNX-NODE-007), NoSQL (VNX-NODE-014), templates (VNX-NODE-011).

## Why this matters

`require()` runs the file it loads. With a request-controlled specifier, `../../` traversal or an uploaded `.js` file turns the endpoint into remote code execution with the server's privileges.

## What gets flagged

```javascript
const plugin = require(req.query.name);
const renderer = require('./themes/' + theme);   // theme = req.body.theme
```

```typescript
const mod = await import(`./locales/${lang}.js`); // lang from req.headers
```

## Remediation

1. Map the request value through a fixed table of allowed modules: `const plugin = PLUGINS[req.query.name]`.
2. If the set is open-ended, validate the value against an explicit allowlist before loading anything.

## References

- [CWE-1027](https://cwe.mitre.org/data/definitions/1027.html)
- [CWE-94: Improper Control of Generation of Code](https://cwe.mitre.org/data/definitions/94.html)
- [OWASP Top 10 2017 A1: Injection](https://owasp.org/www-project-top-ten/2017/A1_2017-Injection)

## 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 `;`):

```text
# nosec vnx-1027
// nosec vnx-1027
```

Or record an ignore rule: `vulnetix ignore add --rule vnx-1027 --reason "..."`. See [Suppressing findings](/sast/guides/suppressing-findings.md).
