Typescript Insecure Nest Injection
Description
This detector identifies insecure injection vulnerabilities in NestJS TypeScript applications where untrusted data flows into dependency injection without proper validation. These vulnerabilities can lead to unauthorized access to sensitive services, privilege escalation, or injection of malicious dependencies that compromise application security.
Detection Strategy
• The file must import from the '@nestjs/common' module (or related NestJS packages)
• A method invocation is found that passes unsafe, untrusted data to NestJS injection mechanisms
• A return statement contains a value that resolves to an unsafe injection pattern, where user-controlled input flows into dependency resolution without sanitization
Vulnerable code example
const { Controller, Get, Query, Param, Res, Body, Req } = require('@nestjs/common');
@Controller('example')
class ExampleController {
@Get('vulnerable1')
vulnerable1(@Query('name') name, @Res() res) {
res.send(`<h1>Hello ${name}</h1>`); // Direct XSS - user input injected into HTML...✅ Secure code example
const { Controller, Get, Query, Param, Res, Body, Req } = require('@nestjs/common');
const escapeHtml = require('escape-html');
@Controller('example')
class ExampleController {
@Get('vulnerable1')
vulnerable1(@Query('name') name, @Res() res) {...Search for vulnerabilities in your apps for free with Fluid Attacks' automated security testing! Start your 21-day free trial and discover the benefits of the Continuous Hacking Essential plan. If you prefer the Advanced plan, which includes the expertise of Fluid Attacks' hacking team, fill out this contact form.