Crate content_security_policy
source ยทExpand description
Parse and validate Web Content-Security-Policy level 3
ยงExample
extern crate content_security_policy;
use content_security_policy::*;
fn main() {
let csp_list = CspList::parse("script-src *.notriddle.com", PolicySource::Header, PolicyDisposition::Enforce);
let (check_result, _) = csp_list.should_request_be_blocked(&Request {
url: Url::parse("https://www.notriddle.com/script.js").unwrap(),
origin: Origin::Tuple("https".to_string(), url::Host::Domain("notriddle.com".to_owned()), 443),
redirect_count: 0,
destination: Destination::Script,
initiator: Initiator::None,
nonce: String::new(),
integrity_metadata: String::new(),
parser_metadata: ParserMetadata::None,
});
assert_eq!(check_result, CheckResult::Allowed);
let (check_result, _) = csp_list.should_request_be_blocked(&Request {
url: Url::parse("https://www.evil.example/script.js").unwrap(),
origin: Origin::Tuple("https".to_string(), url::Host::Domain("notriddle.com".to_owned()), 443),
redirect_count: 0,
destination: Destination::Script,
initiator: Initiator::None,
nonce: String::new(),
integrity_metadata: String::new(),
parser_metadata: ParserMetadata::None,
});
assert_eq!(check_result, CheckResult::Blocked);
}
Re-exportsยง
pub extern crate percent_encoding;
pub extern crate url;
Modulesยง
- text_util ๐
Structsยง
- https://www.w3.org/TR/CSP/#csp-list
- https://www.w3.org/TR/CSP/#directives
- https://www.w3.org/TR/SRI/#integrity-metadata
- A single parsed content security policy.
- request to be validated
- response to be validated https://fetch.spec.whatwg.org/#concept-response
- SourceList ๐https://www.w3.org/TR/CSP/#framework-directive-source-list
- A parsed URL record.
- violation information
Enumsยง
- AllowResult ๐https://www.w3.org/TR/CSP/#allow-all-inline
- Many algorithms are allowed to return either โAllowedโ or โBlockedโ. The spec describes these as strings.
- The valid values for type are โscriptโ, โscript attributeโ, โstyleโ, and โstyle attributeโ.
- https://www.w3.org/TR/CSP/#match-element-to-source-list
- The origin of an URL
- https://www.w3.org/TR/CSP/#policy-disposition
- https://www.w3.org/TR/CSP/#policy-source
- https://www.w3.org/TR/SRI/#parse-metadata
- https://www.w3.org/TR/CSP/#does-request-violate-policy
- violation information
Staticsยง
- https://www.w3.org/TR/CSP/#grammardef-directive-name
- https://www.w3.org/TR/CSP/#grammardef-directive-value
- HASH_SOURCE_GRAMMAR ๐https://www.w3.org/TR/CSP/#grammardef-hash-source
- HOST_SOURCE_GRAMMAR ๐https://www.w3.org/TR/CSP/#grammardef-host-source
- NONCE_SOURCE_GRAMMAR ๐https://www.w3.org/TR/CSP/#grammardef-nonce-source
- NONE_SOURCE_GRAMMAR ๐
- https://www.w3.org/TR/CSP/#grammardef-scheme-source
- https://www.w3.org/TR/SRI/#the-integrity-attribute This corresponds to the โhash-expressionโ grammar.
Functionsยง
- default_port ๐
- default_port_str ๐
- https://www.w3.org/TR/CSP/#match-url-to-source-expression
- https://www.w3.org/TR/CSP/#directive-fallback-list
- https://www.w3.org/TR/CSP/#effective-directive-for-inline-check
- https://www.w3.org/TR/CSP/#effective-directive-for-a-request
- host_part_match ๐https://www.w3.org/TR/CSP/#match-hosts
- https://www.w3.org/TR/SRI/#parse-metadata
- path_part_match ๐https://www.w3.org/TR/CSP/#match-paths
- port_part_match ๐https://www.w3.org/TR/CSP/#match-ports
- https://fetch.spec.whatwg.org/#request-destination-script-like
- scheme_is_httpx ๐
- scheme_is_network ๐
- scheme_part_match ๐https://www.w3.org/TR/CSP/#match-schemes
- https://www.w3.org/TR/CSP/#script-post-request
- https://www.w3.org/TR/CSP/#script-pre-request
- https://www.w3.org/TR/CSP/#should-directive-execute
- url_port ๐