Raw HTML is unprocessed markup that a browser interprets as page structure and executable content, rather than displaying it as text. When applications render user-supplied raw HTML without sanitising it, attackers inject script and cause cross-site scripting. Defenders output-encode by default, sanitise with an allow-list, and apply a Content Security Policy.
What Raw HTML Means in Secure Rendering
Raw HTML becomes dangerous when an application treats user input as trusted markup rather than inert text. That shifts control of the page’s structure and browser behaviour to the input author, which is why unfiltered HTML is a common route from content features into script execution and page manipulation.
In practice, the risk is not the word “HTML” itself, but the decision to let untrusted content pass straight into the DOM. Once that boundary is crossed, browser parsing rules, event handlers, inline scripts, dangerous URL schemes, and embedded elements can all become part of the attack surface.
How Raw HTML Becomes an XSS Path
When a renderer accepts raw HTML, the browser interprets tags and attributes, not just visible text. If sanitisation is absent or incomplete, an attacker can inject script-bearing markup, alter links and forms, or smuggle active content through attributes and nested elements.
This is why raw HTML and cross-site scripting are so closely linked. The issue is not limited to obvious script tags; many attacks rely on broken output handling, unsafe attribute contexts, or HTML fragments that appear harmless until the browser resolves them inside the full page.
Rendering pipelines are especially fragile when they mix templating, markdown conversion, rich text editing, or third-party components. One unsafe transform can reintroduce executable markup after earlier validation has already passed.
Safe Handling and Trust Boundaries
The safest default is to encode output so the browser displays content as text, not markup. When a product genuinely needs to allow some HTML, it should sanitise using a strict allow-list and treat every other element, attribute, and URL scheme as untrusted.
That trust boundary should be enforced as close to output as possible, because earlier checks can be bypassed by later transformations. Context also matters: HTML body, attribute, URL, and script contexts all require different handling, and a sanitizer that is correct for one context may still be unsafe in another.
For browser-side defence, a Content Security Policy can reduce the impact of missed sanitisation by restricting script execution, inline handlers, and risky resource loading. It is a backstop, not a substitute for proper output encoding and sanitisation.
Where Teams Commonly Get It Wrong
Many teams underestimate raw HTML because the feature is framed as “rich text” or “formatting support”. That framing hides the real decision: whether the application is willing to parse and trust attacker-controlled markup at all.
A second mistake is assuming that a library or framework will sanitize automatically. Some renderers pass HTML through by design, and others need explicit configuration before they become safe. Teams should verify the exact behaviour of the final rendering path, not just the component documentation.
Another common failure is partial sanitisation, where obvious tags are removed but dangerous attributes, protocol handlers, or nested payloads survive. That creates a false sense of safety while leaving exploit paths intact.
Risk and Threat Considerations
Raw HTML is dangerous because it turns content injection into browser execution. If attackers can influence rendered markup, they can steal sessions, perform actions in the user’s browser, deface content, or pivot into broader account compromise through trusted application state.
Failure mechanism: Untrusted markup reaches a rendering sink without strict output encoding or robust sanitisation, and the browser executes attacker-controlled structure, attributes, or script-capable content in the victim’s session.
Impact: The result can be cross-site scripting, credential theft, session hijacking, malicious redirects, UI redress, and abuse of the application’s trust relationship with the user.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
NIST SP 800-53 Rev 5, OWASP ASVS and CIS Controls v8 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| NIST SP 800-53 Rev 5 | SI-10 — Information Input Validation | Raw HTML safety depends on validating and constraining untrusted input before rendering. |
| SI-3 — Malicious Code Protection | Sanitisation and browser-side restrictions help block injected script from executing. | |
| Recommendation — Validate and constrain untrusted content before it reaches any rendering sink. Use layered protections that prevent or contain malicious script execution. | ||
| OWASP ASVS | V1 — Encoding and Sanitization | Raw HTML is governed by secure encoding and sanitization requirements in web output handling. |
| V12 — Secure Communication | Browser-side policy controls support safer delivery and reduce script-loading abuse. | |
| Recommendation — Encode output by default and sanitize any permitted HTML with a strict allow-list. Apply restrictive browser security policies to limit script and resource execution. | ||
| CIS Controls v8 | CIS-16 — Application Software Security | Safe rendering of user-controlled HTML is a core application security control concern. |
| Recommendation — Build and test application output handling so untrusted markup cannot execute. | ||
Practitioner Guidance
Why practitioners should care: Treat raw HTML as a high-risk feature, not a convenience. If the product must support it, define exactly which tags, attributes, and URL schemes are permitted and verify that every rendering path applies the same policy.
What to watch for: Inspect any place where user content can enter templates, markdown renderers, WYSIWYG editors, preview panes, comment systems, or support portals. The dangerous pattern is not just direct HTML input, but any transformation chain that reintroduces markup after earlier validation.
Practitioner takeaway: Default to text, allow only tightly controlled HTML where business need is real, and test the final browser-rendered output rather than assuming upstream validation is enough.
Related resources from NHI Mgmt Group
- Guide: Markdown Rendering Security Guide
- Why do helpers like raw, html_safe, and link_to become dangerous when they receive user-controlled values?
- Why do built-in framework protections stop being sufficient once raw HTML rendering is introduced?
- What should teams do when a framework requires raw HTML but the content may still vary at runtime?
- What breaks when HTML input filtering only checks the raw string?
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on November 26, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org