Email Header Injection
Description
Detects email header injection vulnerabilities where user input flows into email headers (To, From, Subject, Cc, Bcc) without validation. Attackers can inject CRLF sequences (\r\n) to add arbitrary headers or body content. Attack impact: - Send spam/phishing emails via your server - Add hidden recipients (Cc/Bcc injection) - Modify email content - Bypass spam filters using your domain reputation Common vulnerable patterns: - nodemailer with user-controlled options - SendGrid/Mailgun APIs with user input - Custom SMTP implementations
What Shoulder detects
How to fix
Validate email addresses and remove CRLF from header values:
```javascript
const validator = require('validator');
function sanitizeHeader(value) {
return value.replace(/[\r\n]/g, '');
}
if (!validator.isEmail(email)) {
return res.status(400).json({ error: 'Invalid email' });
}
const safeSubject = sanitizeHeader(subject).slice(0, 200);
await transporter.sendMail({
to: '[email protected]',
subject: `Contact: ${safeSubject}`,
text: message
});
```
Learn more: https://shoulder.dev/learn/javascript/cwe-93/email-header-injection
Applies to
Languages
Frameworks
express
fastify
koa
nextjs
References
Scan for this issue
Detect with Shoulder CLI
npx @shoulderdev/cli trust --rule=javascript-email-header-injection .