Safe rendering against XSS
Audits how your app renders user content and sanitises Markdown, with tests, so you ship pages without XSS holes.
What we improved
Fixed the nh3 example, which raised ValueError: it allowed the rel attribute on links while nh3's link_rel option is set by default. The allowlist now leaves rel to nh3 and explains the alternative (link_rel=None). Also limited URL schemes
Improved by YourAISkill from the original by wdm0006, under its MIT licence. The download includes the author's licence and a CHANGES.md listing every change. Both Claude reviews read the improved version.
Claude's review
8/10 Specific XSS rendering audit with nh3 allowlist traps, structural regression test and context-correct escaping; one garbled escape sentence.
We asked Claude the question you would ask: would I be glad I installed this? Two separate reviews, the second blind to the first, must both rate a skill 7 or higher before we sell it.
In detail
Renders stored, authored, or imported content into HTML without shipping XSS — auditing every autoescape bypass (|safe, Markup, innerHTML), sanitizing Markdown output with an allowlist, escaping on both the server and the DOM, and writing sanitization tests that assert on the right copy of the string. Use when adding a Markdown or rich-text filter, rendering user/admin-authored content, reviewing a template that marks HTML trusted, building a client that injects values into innerHTML, or fixing an XSS report.
How you use it
- Add it to your pack, then download your pack (1 credit).
- In Claude, open Customize > Skills and upload the zip. Code execution needs to be on under Settings > Capabilities.
- Ask Claude for the job in your own words. It uses the skill when your request matches what it does. Step by step guide
Safety check
Nothing risky found: no hidden instructions, no download and run, no reading of saved passwords or keys.
An automated scan lowers risk but cannot promise zero risk. How we check skills
Preview
The first lines of SKILL.md
---
name: rendering-untrusted-content
description: "Render stored, authored, or imported content into HTML without shipping XSS: audit every autoescape bypass (|safe, Markup, mark_safe, autoescape off, innerHTML, dangerouslySetInnerHTML, v-html), sanitize Markdown output with an allowlist (nh3) that keeps the constructs your content needs, escape on both the server and in the browser for the right context, and write sanitization tests that check the right copy of the string and catch silent content loss. Use when adding a Markdown or rich-text filter, rendering user- or admin-authored content, reviewing a template that marks HTML trusted, building client code that injects values into the DOM, or fixing an XSS report. Examples are Python (Jinja2, Django, python-markdown, nh3) and browser JavaScript."
---
<!-- Modified by YourAISkill (youraiskill.com) on 2 December 2026 from the original by wdm0006. See CHANGES.md. -->
# Rendering Untrusted Content
Template engines that autoescape make the vulnerable surface small and enumerable: it is exactly the places where something says *this value is already safe HTML*, plus anything rendered with autoescaping switched off. Find those first; everything else is already handled.
## Step 1: Enumerate the trust bypasses
```bash
# Server side: Jinja2, Django, and the Python that feeds them
grep -rnE '\|\s*safe\b|\|\s*safeseq|Markup\(|mark_safe|SafeString|autoescape (false|off)|format_html' templates/ src/
grep -rnE 'Environment\(|Template\(' src/ # a bare jinja2.Environment() does NOT autoescape
# Client side
grep -rnE 'innerHTML|outerHTML|insertAdjacentHTML|document\.write|dangerouslySetInnerHTML|v-html|\{@html|\[innerHTML\]|\.html\(' web/ static/ src/
```
Every hit is a claim that needs justification. A `|safe` on a value that came from a database column is a claim about *everything that has ever been written to that column*, including through an import path nobody remembers.
**Check that autoescaping is actually on.** Flask and Django enable it for HTML templates, but `jinja2.Environment()` and `jinja2.Template(...)` default to `autoescape=False`. Construct environments with `autoescape=select_autoescape()` (or `True`). `format_html()` in Django is safe only when the untrusted values are passed as arguments, never pre-formatted into the format string.
## Step 2: Markdown output is not sanitized HTML
Markdown renderers pass raw HTML through **by design**: that is a documented feature, not a bug. So a shared template filter shaped like this is an XSS sink:
```python
# BAD: the filter marks arbitrary stored markup trusted.
def _markdown(text: str) -> Markup:
return Markup(markdown.markdown(text, extensions=["extra", "tables"]))
```
"Only admins author content" is not a boundary. As soon as there is an import path, a seed script, or a second author, the content store is untrusted input.
Render, then sanitize with an **allowlist**, and only then mark trusted:
```python
...From wdm0006's repository, MIT licence.
Related skills
-
Checked
Codebase quality audit
Audits a whole code repo for bugs, security holes, slow paths and dead code, ranked in plain English.
7/101 credit -
Checked
Security and CVE audit
Runs a security and CVE audit on code in any language and scores it out of 100, with false alarms filtered.
7/101 credit -
Checked
OWASP code review
Reviews code for security flaws using the latest OWASP Top 10 lists, including those for AI and agent apps.
7/101 credit -
Checked
Code security hardening
Hardens code that handles user input, logins and data against the OWASP Top 10, starting from a threat model.
7/101 credit -
Checked
Secure web backend code
Writes and reviews login, access control and input handling for web backends, so common attacks are blocked.
8/101 credit -
Checked
Android intent security
Audits Android components and incoming intents to fix redirection and unauthorised access holes in your app.
8/101 credit