xss-filters
Context-aware output encoders for preventing cross-site scripting. Each filter applies the minimal encoding required so an untrusted string cannot break out of a declared HTML output context and run script.
Supported contexts: HTML data, HTML comment, single/double/unquoted attribute
values, and URIs placed inside any of those. URI filters also normalize IPv6
hosts and block dangerous protocols such as javascript: and data:.
Installation
[]
= "0.1"
Usage
Match the filter to the exact place the value lands in the document.
use ;
// <div>{{ value }}</div>
assert_eq!;
// <input value="{{ value }}">
assert_eq!;
// <a href="{{ value }}">
assert_eq!;
Do not apply these filters inside scriptable contexts such as <script>,
<style>, on* attributes, or style attributes. They target HTML and URI
contexts only.
Features
std(default): enablestd::error::Errorimpls. The crate is otherwiseno_stdplusalloc.css: expose thecssmodule. It escapes CSS strings, validates CSS values, neutralizesexpression(...)andurl(...)tricks, and blocks dangerous URL protocols. Enable it forstyleattributes and<style>blocks.
[]
= { = "0.1", = ["css"] }
No-std
The crate builds without std and depends only on alloc. Disable default
features to drop the std error impls.
[]
= { = "0.1", = false }
License
BSD 3-Clause. See LICENSE.