Claude skill XXE injection security — SA-SKL-XXE
XML External Entity (XXE) injection allows an attacker to read arbitrary files from the server's filesystem, perform server-side request forgery, and cause denial-of-service through exponential entity expansion — all by supplying crafted XML to any endpoint that parses it. MCP skills encounter XML in direct XML API payloads, SAML SSO assertions, SVG file uploads, and XML-based configuration files. Each context requires explicit entity expansion disabling because most XML parsers enable it by default for legacy compatibility reasons.
What XXE enables
An XXE attack works by defining an external entity in the DTD (Document Type Definition) section of an XML document, referencing a SYSTEM URI that points to a local file or network resource. When the parser expands the entity, it reads the referenced resource and substitutes its content into the XML tree. The attacker can then read the parsed output — via an error message, a response body field, or an SSRF channel — to exfiltrate the file content. Classic targets on a Node.js server are /etc/passwd, .env, private keys in ~/.ssh/id_rsa, and internal metadata endpoints like http://169.254.169.254/latest/meta-data/ in cloud environments.
SA-SKL-XXE in scope: XXE-001 (external entity file read via direct XML parsing), XXE-002 (SAML assertion XXE), XXE-003 (SVG upload XXE), XXE-004 (billion laughs exponential expansion DoS). All four are detected by SkillAudit's static analysis of XML parser instantiation and configuration options.
XXE-001 — External entity file read
Any endpoint that accepts XML input and uses a parser configured with the default options (or explicitly with allowDtd: true) is vulnerable to external entity injection. In Node.js, the libxmljs library parses external entities by default; fast-xml-parser expands entities by default unless allowBooleanAttributes and similar options are explicitly set. The correct configuration is to disable external entity resolution and DTD processing entirely at parser initialization.
<!-- XXE payload — attacker submits this XML to any parsing endpoint -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE audit [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<audit>
<repo_url>&xxe;</repo_url>
</audit>
<!-- Parser expands &xxe; to the contents of /etc/passwd
If the response includes repo_url, the attacker reads the file -->
// VULNERABLE: libxmljs with default options (entities enabled)
const libxmljs = require('libxmljs');
app.post('/api/import-audit', (req, res) => {
const doc = libxmljs.parseXml(req.body); // ← External entities expanded
const repoUrl = doc.get('//repo_url').text();
res.json({ repoUrl });
});
// FIXED: disable external entity resolution
const { XMLParser } = require('fast-xml-parser');
const parser = new XMLParser({
allowBooleanAttributes: true,
processEntities: false, // Disable entity processing
ignoreDeclaration: true,
});
app.post('/api/import-audit', (req, res) => {
const doc = parser.parse(req.body);
res.json({ repoUrl: doc.audit?.repo_url });
});
// If you must use libxmljs, use parseXmlString with noent: false
const doc = libxmljs.parseXmlString(xml, { noent: false, nonet: true });
SYSTEM "file:///etc/passwd" or SYSTEM "http://169.254.169.254/" reads arbitrary files or performs SSRF via entity resolution. Fix: set processEntities: false in fast-xml-parser; set noent: true, nonet: true in libxmljs; use a JSON-only API if XML is not a business requirement.XXE-002 — SAML assertion XML parsing
SAML (Security Assertion Markup Language) uses XML to encode authentication assertions. MCP skills that implement SSO via SAML receive a base64-encoded XML assertion from the identity provider and parse it on the server to authenticate the user. If the SAML parser does not disable external entities, an attacker can forge a SAML assertion containing an XXE payload, submit it to the ACS (Assertion Consumer Service) endpoint, and read server files during the authentication flow — without possessing a valid SAML assertion. This is particularly dangerous because the ACS endpoint is typically unauthenticated by design (it's the destination for IdP redirects).
// VULNERABLE: SAML assertion parsed with default XML options
const saml = require('@node-saml/node-saml');
// If the underlying XML parser expands entities, forged SAML with XXE payload
// will be processed at the ACS endpoint before signature validation
// Attacker submits to POST /auth/saml/acs:
// SAMLResponse = base64(<!DOCTYPE foo [<!ENTITY xxe SYSTEM "file:///etc/passwd">]>
// <samlp:Response ...><Issuer>&xxe;</Issuer>...)
// FIXED: use @node-saml/node-saml v4+ which disables external entities
// and validates signature before returning any claim values
const { SAML } = require('@node-saml/node-saml');
const saml = new SAML({
cert: process.env.IDP_CERT,
issuer: 'https://skillaudit.dev',
// node-saml v4+ uses @xmldom/xmldom with no-entity defaults
// Always use the latest version — XXE fixes are in the library
});
// Validate signature FIRST; reject before parsing claims if invalid
app.post('/auth/saml/acs', async (req, res) => {
try {
const { profile } = await saml.validatePostResponseAsync(req.body);
// profile.nameID and attributes are from the VERIFIED assertion
req.session.userId = await findOrCreateUser(profile);
res.redirect('/dashboard');
} catch (err) {
res.status(401).send('Invalid SAML assertion');
}
});
@node-saml/node-saml v4+ which disables external entities; ensure signature validation precedes any claim access; pin SAML library version and monitor for XXE-related CVEs.XXE-003 — SVG upload XXE
SVG (Scalable Vector Graphics) is an XML-based image format. MCP skills that accept SVG uploads — for skill icons, report branding, or user avatars — may process them server-side for validation, thumbnail generation, or metadata extraction. If the processing pipeline involves an XML parser with entity expansion enabled, an attacker can upload a crafted SVG containing an XXE payload. The vector is especially deceptive because browsers render SVG as images; the malicious payload is invisible in the rendered output but is processed by the server's XML parser during upload handling.
<!-- Malicious SVG upload — looks like a valid image, exploits server XML parser -->
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE svg [
<!ENTITY xxe SYSTEM "file:///app/.env">
]>
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">
<text>&xxe;</text>
</svg>
<!-- Server reads .env contents during SVG validation/processing
Returns them in error message, thumbnail alt text, or logging -->
// VULNERABLE: SVG processed via XML parser during upload validation
app.post('/api/upload-icon', upload.single('icon'), async (req, res) => {
const svgContent = req.file.buffer.toString('utf8');
const doc = libxmljs.parseXml(svgContent); // ← XXE if external entities enabled
const title = doc.get('//svg:title')?.text();
res.json({ title });
});
// FIXED: disable external entities; use allowlist of safe SVG elements
const { XMLParser } = require('fast-xml-parser');
const svgParser = new XMLParser({ processEntities: false, ignoreDeclaration: true });
app.post('/api/upload-icon', upload.single('icon'), async (req, res) => {
if (req.file.mimetype !== 'image/svg+xml') {
return res.status(400).json({ error: 'Invalid file type' });
}
const svgContent = req.file.buffer.toString('utf8');
// Block DOCTYPE declarations entirely for SVG uploads
if (/<!DOCTYPE/i.test(svgContent)) {
return res.status(400).json({ error: 'DOCTYPE not allowed in SVG uploads' });
}
const doc = svgParser.parse(svgContent);
res.json({ ok: true });
});
<!DOCTYPE; set processEntities: false in the XML parser; use a sanitizing library like DOMPurify (server-side via jsdom) before any XML processing of user-uploaded SVG.XXE-004 — Billion laughs DoS via entity expansion
Even without external file read, recursive entity expansion produces a denial-of-service attack. The "billion laughs" payload defines a chain of entities where each entity references the previous one multiple times: &a; expands to 10 copies of &b;, which expands to 10 copies of &c;, and so on through 9 levels. The final expansion produces 10^9 copies of the base string — roughly 1 GB of expanded text from a 1 KB input — exhausting server memory and causing an OOM crash or extreme latency. The fix is to disable entity expansion entirely or set an entity expansion depth limit.
<!-- Billion laughs payload — 1KB input, ~1GB expansion --> <?xml version="1.0"?> <!DOCTYPE lol [ <!ENTITY lol "lol"> <!ENTITY lol2 "&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;"> <!ENTITY lol3 "&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;"> <!ENTITY lol4 "&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;"> <!ENTITY lol5 "&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;"> <!ENTITY lol6 "&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;"> <!ENTITY lol7 "&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;"> <!ENTITY lol8 "&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;"> <!ENTITY lol9 "&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;"> ]> <data>&lol9;</data>
// FIXED: disable entity processing entirely
// fast-xml-parser:
const parser = new XMLParser({ processEntities: false });
// @xmldom/xmldom (used by node-saml, svg libraries):
// Use createDocument() with no entity expansion options
// If you must use libxmljs, block DOCTYPE declarations:
function parseSafeXml(xmlString) {
if (/<!DOCTYPE/i.test(xmlString)) {
throw new Error('DOCTYPE declarations not permitted');
}
return libxmljs.parseXmlString(xmlString, { noent: true, nonet: true });
// noent: true means do NOT expand entities (counterintuitive flag name)
}
processEntities: false; explicitly block input containing <!DOCTYPE; or switch to JSON for all external API surfaces where XML provides no business value.SkillAudit detection summary — SA-SKL-XXE
| Pattern ID | Severity | What SkillAudit flags | Fix |
|---|---|---|---|
| XXE-001 | CRITICAL | XML parser instantiation without processEntities: false in endpoints accepting user-supplied XML; libxmljs.parseXml() without noent/nonet | processEntities: false in fast-xml-parser; noent: true, nonet: true in libxmljs |
| XXE-002 | CRITICAL | SAML ACS endpoint using outdated passport-saml or samlify without confirmed XXE fix; parseString() before signature validation | @node-saml/node-saml v4+; signature validation before claim access |
| XXE-003 | HIGH | SVG upload endpoint passing file buffer to XML parser; parseXml() called on uploaded file content | Reject DOCTYPE in SVG; processEntities: false; sanitize with DOMPurify server-side |
| XXE-004 | HIGH | XML parser configured without entity expansion limits on any endpoint accepting external input; no DOCTYPE block | Block DOCTYPE; processEntities: false; prefer JSON API over XML for new endpoints |
Related patterns: For SSRF via XXE external entity SYSTEM URI pointing to internal metadata endpoints, see SA-SKL-SSRF2. For SVG/XML injection via inline SVG in HTML templates, see SA-SKL-XMLSVG. For file upload security beyond XXE including MIME type validation and path traversal, see SA-SKL-UPLOAD2.