xxe-prevention

xxe-prevention is a cursor rule for coding agents from matank001/cursor-security-rules. It costs 0 tokens per session (469 once invoked), scanned A, original, MIT.

Security rules for XML-processing code that prevent external entities and related parser features from reading unintended files or network resources.

In plain words
What is it for?
Use them when parsing XML, configuring XML libraries, or reviewing generated XML-processing code.
Why use it?
They reduce the risk of XML external entity attacks, in which crafted XML makes an application access or disclose outside data.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/matank001/cursor-security-rules/xxe-prevention
Clone the repo
git clone --depth 1 https://github.com/matank001/cursor-security-rules

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for xxe-prevention

README.md
[![agentmods](https://agentmods.dev/badge/rules/matank001/cursor-security-rules/xxe-prevention.svg)](https://agentmods.dev/rules/matank001/cursor-security-rules/xxe-prevention)
Your own site
<a href="https://agentmods.dev/rules/matank001/cursor-security-rules/xxe-prevention"><img src="https://agentmods.dev/badge/rules/matank001/cursor-security-rules/xxe-prevention.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 469 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00469
Opus 5 $0.00000 $0.00234
Sonnet 5 $0.00000 $0.00094
Haiku 4.5 $0.00000 $0.00047

Measured 4d ago against content hash 602001540bf5, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

xxe-prevention scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

Origin

Copies of this mod

2 near-identical copies found in the catalogue:

xxe-prevention.mdc · 44 lines

How it starts

The opening of the file, as written. The whole thing — 44 lines — stays where its author put it; the contents beside it link to each section on GitHub.

XXE Prevention

These rules apply to all code that parses or processes XML, regardless of language or framework, including AI-generated code.

All violations must include a clear explanation of which rule was triggered and why, to help developers understand and fix the issue effectively.
Generated code must not violate these rules. If a rule is violated, a comment must be added explaining the issue and suggesting a correction.

1. Disable DTDs and External Entities

  • Rule: XML parsers must have Document Type Definitions (DTDs) disabled and must not resolve external entities.
  • Example (unsafe, Python with lxml):
    from lxml import etree
    etree.fromstring(user_xml)  # External entities allowed ➜ XXE
    
  • Example (safe, Python using defusedxml):
    from defusedxml.ElementTree import fromstring
    fromstring(user_xml)  # External entities blocked
    

2. Use Secure Parser Features / Libraries

  • Rule: Choose parsers with XXE protection by default (e.g., defusedxml in Python, XMLInputFactory with XMLConstants.FEATURE_SECURE_PROCESSING in Java). Verify that features to disallow external DTDs and entities are enabled.

3. Restrict Schema and XInclude Processing

  • Rule: Do not allow remote or file-based schema, XInclude, or XSLT processing on untrusted XML unless explicitly required and properly sandboxed.

4. Limit Resource Consumption

  • Rule: Configure parser limits (file size, entity expansion depth, timeouts) to prevent Billion Laughs and Quadratic Blow-up DoS attacks.

5. Validate and Sanitize Input Before Processing

  • Rule: Validate XML against a known schema or allow-list of expected elements. Reject unexpected or malformed content early.

6. Avoid Logging Sensitive XML Content

  • Rule: Do not log raw XML that may contain credentials, personal data, or other sensitive information.

7. Keep Parser Libraries Patched

  • Rule: Regularly update XML libraries to incorporate security patches that address newly discovered parser flaws.

Read the full file on GitHub · 44 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 44 lines · 0 tokens per session scan A 602001540bf5

Subscribe to this mod's changes

xxe-prevention is a cursor rule published in the GitHub repository matank001/cursor-security-rules (378 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 469 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.