Claude skill email injection security — SA-SKL-EMAILINJ
MCP skills that send transactional email — password resets, audit reports, notifications — are vulnerable to header injection, Reply-To hijacking, HTML body phishing, and domain spoofing when user input is not properly sanitized. SA-SKL-EMAILINJ documents all four patterns with Nodemailer-based examples and DNS-level fixes.
Why email sending requires special attention in MCP skills
Email is one of the highest-trust channels a skill can touch. A single exploited email injection can turn a legitimate password-reset endpoint into a mass-BCC spam relay, redirect reply traffic to an attacker's address, embed phishing links in what appears to be an official notification, or allow external actors to impersonate your sending domain entirely. Unlike SQL injection or XSS, email injection vulnerabilities are frequently invisible in development because Nodemailer (and similar libraries) accept malformed header strings without raising errors — the SMTP server or receiving MTA is where the injection takes effect.
MCP skills that expose audit scheduling, report delivery, or account management tools are particularly at risk because they often accept user-supplied subject lines, display names, or body content that flows directly into email construction code. SA-SKL-EMAILINJ covers the four most common attack patterns observed across skills audited on SkillAudit, ordered by exploitability.
SA-SKL-EMAILINJ in scope: EMAILINJ-001 (header injection via newline), EMAILINJ-002 (Reply-To display name abuse), EMAILINJ-003 (unsanitized HTML body), EMAILINJ-004 (missing SPF/DKIM/DMARC). Each pattern includes SkillAudit detection rules and correct fixes.
EMAILINJ-001 — Email header injection via newline in recipient or subject
SMTP email headers are separated by CRLF (\r\n) sequences. If a user-supplied value is interpolated into the to, subject, from, or any other header field without stripping newline characters, an attacker can inject additional headers. A subject of Reset your password\r\nBcc: attacker@evil.com\r\nContent-Type: text/html causes some SMTP implementations to add the attacker as a blind carbon-copy recipient on every password reset email sent by the skill, turning it into a spam relay. The fix is to strip \r and \n from all header-bound values before passing them to Nodemailer, and to validate the to address against an RFC 5321 compliant email regex.
// VULNERABLE — user-supplied subject interpolated directly into Nodemailer options
import nodemailer from 'nodemailer';
export async function sendPasswordReset(to: string, userName: string, subject: string) {
// Attacker supplies: "Reset your password\r\nBcc: attacker@evil.com"
await transporter.sendMail({
from: 'noreply@skillaudit.dev',
to, // No validation — could contain injected headers
subject, // Directly from user input — CRLF injection possible
text: `Hello ${userName}, click the link to reset your password.`,
});
}
// FIXED — strip newlines from all header values; validate email address format
import nodemailer from 'nodemailer';
const EMAIL_REGEX = /^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$/;
function sanitizeHeader(value: string): string {
// Strip carriage return and newline to prevent CRLF injection
return value.replace(/[\r\n]/g, '');
}
export async function sendPasswordReset(to: string, userName: string, subject: string) {
if (!EMAIL_REGEX.test(to)) {
throw new Error('Invalid recipient email address');
}
await transporter.sendMail({
from: 'noreply@skillaudit.dev',
to: sanitizeHeader(to),
subject: sanitizeHeader(subject),
text: `Hello ${sanitizeHeader(userName)}, click the link to reset your password.`,
});
}
to, subject, or from field without stripping \r\n characters enables CRLF header injection and BCC spam relay; fix by calling a sanitizeHeader() that strips newlines and validating email addresses against an RFC 5321 regex. Detection: SkillAudit flags Nodemailer sendMail() calls where to, subject, or header fields are assigned from function parameters or request body fields without an intervening newline-strip operation.EMAILINJ-002 — Reply-To header injection via user-controlled display name
Many MCP skills construct a Reply-To header using the user's display name in the format Display Name <noreply@skillaudit.dev>. If the display name is not validated, an attacker can register a display name of Attacker <attacker@evil.com>. When this string is used as the Reply-To value, some mail clients parse the embedded angle-bracket address as the actual reply-to address rather than the intended noreply@skillaudit.dev. Recipients who reply to what appears to be a SkillAudit notification are redirected to the attacker's address. The fix is to validate the display name against a regex that excludes <, >, @, \r, \n, and " characters, or to pass a structured address object to Nodemailer which prevents injection at the library level.
// VULNERABLE — user displayName interpolated into Reply-To string
export async function sendAuditReport(org: { name: string; email: string }) {
await transporter.sendMail({
from: 'noreply@skillaudit.dev',
to: org.email,
// If org.name = 'Attacker <attacker@evil.com>', mail clients may
// use attacker@evil.com as the reply-to address
replyTo: `${org.name} <noreply@skillaudit.dev>`,
subject: 'Your audit report is ready',
text: 'Your audit has completed. See the dashboard for results.',
});
}
// FIXED — validate display name and use structured address object
const DISPLAY_NAME_REGEX = /^[^<>@\r\n"]{1,100}$/;
export async function sendAuditReport(org: { name: string; email: string }) {
const safeName = DISPLAY_NAME_REGEX.test(org.name) ? org.name : 'SkillAudit';
await transporter.sendMail({
from: 'noreply@skillaudit.dev',
to: org.email,
// Structured object: Nodemailer encodes name safely, address is hardcoded
replyTo: { name: safeName, address: 'noreply@skillaudit.dev' },
subject: 'Your audit report is ready',
text: 'Your audit has completed. See the dashboard for results.',
});
}
/^[^<>@\r\n"]+$/ and using a Nodemailer structured address object. Detection: SkillAudit flags template literal constructions of the form `${variable} <address>` in replyTo, from, or to fields where variable originates from user input without character-class validation.EMAILINJ-003 — Unsanitized HTML in email body enables phishing content injection
When a skill generates an HTML email from user-supplied content — an audit description, a comment, or a custom message — without sanitizing the HTML, an attacker can inject arbitrary markup. A payload of <a href="https://evil-clone.com/reset">Reset your password</a> produces a convincing phishing link inside a legitimate SkillAudit notification email. More subtle attacks use hidden <form> tags or CSS-positioned overlay elements to capture user interaction. The fix is to sanitize all user-supplied HTML using DOMPurify with a server-side jsdom window (for Node.js environments), or to process user content as Markdown and convert it with a sanitizing renderer that strips arbitrary HTML tags. For notification emails that do not require rich formatting, using the Nodemailer text transport instead of html entirely eliminates this attack surface.
// VULNERABLE — user-supplied description used directly as HTML email body
export async function sendAuditSummary(orgEmail: string, description: string) {
// Attacker sets description to: '<a href="https://evil.com">Click to view report</a>'
const html = `
<html><body>
<h2>Your audit completed</h2>
<p>${description}</p>
</body></html>
`;
await transporter.sendMail({
from: 'noreply@skillaudit.dev',
to: orgEmail,
subject: 'Audit summary',
html, // Raw user HTML injected into email body
});
}
// FIXED — sanitize with DOMPurify + jsdom, or use plain text transport
import { JSDOM } from 'jsdom';
import DOMPurify from 'dompurify';
const { window } = new JSDOM('');
const purify = DOMPurify(window);
export async function sendAuditSummary(orgEmail: string, description: string) {
// Strip all dangerous HTML tags and attributes
const safeDescription = purify.sanitize(description, {
ALLOWED_TAGS: ['b', 'i', 'em', 'strong', 'p', 'br'],
ALLOWED_ATTR: [],
});
const html = `
<html><body>
<h2>Your audit completed</h2>
<p>${safeDescription}</p>
</body></html>
`;
await transporter.sendMail({
from: 'noreply@skillaudit.dev',
to: orgEmail,
subject: 'Audit summary',
html,
// Also include a plain-text fallback
text: `Your audit completed. Description: ${description.replace(/<[^>]+>/g, '')}`,
});
}
// Simplest fix for plain notifications: skip HTML entirely
export async function sendSimpleNotification(orgEmail: string, message: string) {
await transporter.sendMail({
from: 'noreply@skillaudit.dev',
to: orgEmail,
subject: 'SkillAudit notification',
text: message, // No HTML = no HTML injection surface
});
}
html field of a Nodemailer sendMail() call without sanitization allows phishing link and malicious form injection in legitimate notification emails; fix using DOMPurify with jsdom or by switching to plain text transport for notifications that do not require HTML. Detection: SkillAudit flags template literals or string concatenations in html email fields where the interpolated variable traces to user input without a DOMPurify or equivalent sanitization call.EMAILINJ-004 — Missing SPF/DKIM/DMARC allows skill-sent emails to be spoofed
Even when a skill sends email securely through Resend, SendGrid, or Postmark, those emails can be undermined if the sending domain lacks proper authentication DNS records. Without an SPF record authorizing the ESP's sending infrastructure, without DKIM signatures to cryptographically bind messages to the domain, and without a DMARC policy instructing receiving MTAs how to handle unauthenticated messages, anyone can send email that appears to originate from your domain — often with higher deliverability than your legitimate emails because they bypass your ESP's rate limits. The fix requires three DNS changes: an SPF TXT record authorizing your ESP, a DKIM public key record (provided by the ESP), and a DMARC TXT record with at least a quarantine policy.
// VULNERABLE — skill sends via Resend but DNS has no SPF, DKIM, or DMARC
// Sending code looks fine:
import { Resend } from 'resend';
const resend = new Resend(process.env.RESEND_API_KEY);
export async function sendWelcome(to: string) {
await resend.emails.send({
from: 'noreply@skillaudit.dev',
to,
subject: 'Welcome to SkillAudit',
text: 'Thanks for signing up.',
});
}
// But DNS is missing authentication records:
// skillaudit.dev TXT — no SPF record
// No DKIM selector CNAME records configured
// No _dmarc.skillaudit.dev TXT record
// Result: anyone can forge @skillaudit.dev emails with equal or better deliverability
// FIXED — add all three DNS authentication records
// 1. SPF TXT record (add to skillaudit.dev DNS):
// skillaudit.dev. IN TXT "v=spf1 include:amazonses.com ~all"
// (use the include: value provided by your ESP — Resend uses amazonses.com)
// 2. DKIM — add the CNAME records provided by your ESP to point to their keys:
// resend._domainkey.skillaudit.dev. CNAME resend._domainkey.resend.com.
// (exact record name and target provided in ESP DNS settings panel)
// 3. DMARC TXT record:
// _dmarc.skillaudit.dev. IN TXT "v=DMARC1; p=quarantine; rua=mailto:dmarc@skillaudit.dev; ruf=mailto:dmarc@skillaudit.dev; adkim=s; aspf=s"
// Start with p=none for monitoring, then move to p=quarantine, then p=reject
// Verification: check all three are configured correctly
// SPF: dig TXT skillaudit.dev
// DKIM: dig TXT resend._domainkey.skillaudit.dev
// DMARC: dig TXT _dmarc.skillaudit.dev
// Sending code is unchanged — authentication is enforced at DNS level
export async function sendWelcome(to: string) {
await resend.emails.send({
from: 'noreply@skillaudit.dev',
to,
subject: 'Welcome to SkillAudit',
text: 'Thanks for signing up.',
});
}
include: for your ESP, the ESP-provided DKIM CNAME record, and a _dmarc TXT record with p=quarantine or stricter. Detection: SkillAudit flags skills that call email-sending APIs for a custom domain without corresponding SPF, DKIM, and DMARC records resolvable via DNS at audit time.