
A custom lead viewer receives a Contact Form 7 message containing angle brackets, links or pasted formatting. Before treating that content as HTML, decide whether HTML is needed at all. Most inquiry messages can be displayed as text. When a separate, deliberate rich-content workflow permits markup, a maintained sanitizer and a narrow output policy become part of the viewer’s design.
This comparison covers DOMPurify, sanitize-html, nh3, HTML Purifier and OWASP Java HTML Sanitizer. It uses official documentation and licenses reviewed October 29, 2026, not a security audit, bypass test or performance benchmark. We operate CF7 Analytics. These are developer components for custom viewers, not five native CF7 integrations or a claim that CF7 itself requires replacement sanitization.
Start with the output context
For ordinary messages, use the platform’s safe text-rendering mechanism, such as the browser’s textContent, and apply presentation separately. Our multiline message guide covers preserving paragraph breaks without turning submitted text into executable markup.
If rich HTML is a supported requirement, define allowed elements, attributes and URL schemes. Sanitized HTML is not automatically safe in a script, style sheet, URL or attribute context. Keep a separate authorized source value if required, and generate the display representation for its intended destination. Do not overwrite the original inquiry merely to simplify rendering.
| Product | Runtime | Useful fit | Key limitation |
|---|---|---|---|
| DOMPurify | Browser JavaScript or Node with DOM | DOM-based sanitization | Server DOM dependency needs maintenance |
| sanitize-html | Node.js | Explicit fragment allowlists | Transform rules require review |
| nh3 | Python | Ammonia-backed fragment cleaning | Native package and policy ownership |
| HTML Purifier | PHP | Rich document filtering | Broader policy configuration |
| OWASP Java HTML Sanitizer | Java | Composable Java policies | Custom policy needs destination checks |
DOMPurify
DOMPurify provides DOM-based sanitization in JavaScript. It fits a browser viewer that deliberately accepts a constrained HTML fragment. Its configuration can restrict the permitted content instead of treating arbitrary pasted markup as suitable for an operational record.
Strengths: documented configuration, browser-oriented integration and a clear sanitization boundary before insertion. For a custom lead viewer, keep that boundary close to the component that renders the fragment. Define the policy in maintained source and review it alongside the display requirements, rather than copying a large permissive configuration from an unrelated editor.
Limitations: server-side use needs a DOM implementation; the project stresses keeping that dependency current. Later transformations can undermine the intended output policy, so inspect the final rendering path. The README describes MPL-2.0 or Apache-2.0 licensing, and the checked license file supplies Apache-2.0 terms. There is no core software license charge. Choose it when JavaScript owns the rendering boundary and its dependencies can be maintained.
sanitize-html
sanitize-html is a Node.js fragment sanitizer with configurable tags and attributes. Its current official source is in Apostrophe’s monorepo; the older standalone repository now directs readers there. Follow the documentation for the package version actually used by your adapter.
Strengths: explicit allowlists and options for how fragments are handled. A server that prepares lead-display content can define a small formatting vocabulary and apply it consistently before returning the representation to a viewer. That makes the policy reviewable with the API response contract rather than scattering ad hoc replacements across templates.
Limitations: permitted links, styles and transformation callbacks need deliberate choices. A sanitizer default is not a business requirement, and a custom transform deserves the same review as other code affecting output. Do not assume the cleaned fragment is suitable for every later context. The checked package license is MIT, without a core fee. Choose it for a Node service that prefers a configurable fragment-processing policy and owns its final HTML consumer.
nh3
nh3 exposes Python bindings to the Rust Ammonia HTML sanitization library. Its documented API supports cleaning fragments with chosen tags, attributes, URL schemes and link behavior. A reusable Cleaner can hold a defined policy for a Python service preparing display content.
Strengths: a focused Python interface with policy settings that can be kept beside the lead-view model. This suits a worker that already handles permitted Python processing and needs to produce a constrained HTML representation. Document which content is preserved, which is removed, and how links are represented for the people reading inquiries.
Limitations: packaging and native-runtime compatibility belong in the deployment review, alongside the policy itself. Defaults for links and attributes must match the product’s intended behavior; migration from another sanitizer requires fixture comparison. It is not an automatic CF7 extension or a reason to allow HTML in a plain-text form. The nh3 wrapper is MIT-licensed, with no core license fee; review bundled dependency terms too. Choose it when Python owns this processing boundary.
HTML Purifier
HTML Purifier is a PHP filtering library oriented toward richly formatted documents, combining parsing with an allowed-content policy. It can also be configured more restrictively. This makes it relevant to a PHP application that has a real requirement to accept formatted content from another authorized system.
Strengths: a PHP-native integration path and configuration intended to describe accepted document content. A developer can keep the source and display representations distinct and apply one reviewed policy before a custom operational view renders the fragment. That can be more maintainable than a collection of regular-expression replacements.
Limitations: its broad document capabilities do not mean a lead viewer should permit broad markup. Verify configuration, serializer cache requirements and runtime compatibility for the installed release. WordPress has its own output and filtering APIs; adding this library needs a concrete custom requirement. The package declares LGPL-2.1-or-later, with license terms that differ from MIT. No core purchase fee is listed. Choose it for an owned PHP rich-content pipeline with appropriate license and maintenance review.
OWASP Java HTML Sanitizer
OWASP Java HTML Sanitizer offers Java policy factories, including prepackaged policies and a builder for custom rules. A Java service can compose a deliberate formatting-and-links policy instead of embedding a one-off string filter in each lead template.
Strengths: a policy-oriented API that makes permitted elements, attributes and protocols part of the maintained application configuration. For a lead viewer, a narrowly scoped policy can be reviewed with representative records and the exact rendering location. Keep policy ownership with the service team that can update dependencies and verify consumers.
Limitations: custom policies and subsequent content changes still need acceptance checks. The project’s documented checks and reviews are not a guarantee for your application or your changed configuration. Do not infer that an OWASP name establishes a universal security certification. Its authoritative COPYING file offers Apache-2.0 or BSD-2-Clause at your option, with bundled-code notices considered separately. There is no core license charge. Choose it when Java owns the output pipeline and explicit policy composition fits the application.
Compare the final display, not only returned strings
Use fictional ordinary text, paragraphs, allowed emphasis, permitted links, disallowed elements and malformed fragments. Agree on expected output first. Review it in the actual viewer after every transformation, including link rewriting. Record library and policy versions so a future upgrade can be compared meaningfully.
Choose DOMPurify for a maintained JavaScript DOM boundary, sanitize-html for Node fragment policies, nh3 for Python, HTML Purifier for PHP rich documents, or OWASP Java HTML Sanitizer for Java policy composition. Plain-text display remains a valid choice when formatting is unnecessary. No license fee removes integration and maintenance costs.
For submission trends, see our free Svetlik Analytics for Contact Form 7. Its statistics do not inspect HTML safety or certify a lead viewer. Keep rendering checks separate from analytics and from email-template authoring.
