pub enum ContentSecurityPolicyDirective<'a> {
Show 25 variants
ChildSrc(Vec<&'a str>),
ConnectSrc(Vec<&'a str>),
DefaultSrc(Vec<&'a str>),
FontSrc(Vec<&'a str>),
FrameSrc(Vec<&'a str>),
ImgSrc(Vec<&'a str>),
ManifestSrc(Vec<&'a str>),
MediaSrc(Vec<&'a str>),
ObjectSrc(Vec<&'a str>),
PrefetchSrc(Vec<&'a str>),
ScriptSrc(Vec<&'a str>),
ScriptSrcElem(Vec<&'a str>),
ScriptSrcAttr(Vec<&'a str>),
StyleSrc(Vec<&'a str>),
StyleSrcElem(Vec<&'a str>),
StyleSrcAttr(Vec<&'a str>),
WorkerSrc(Vec<&'a str>),
BaseUri(Vec<&'a str>),
Sandbox(Vec<&'a str>),
FormAction(Vec<&'a str>),
FrameAncestors(Vec<&'a str>),
ReportTo(Vec<&'a str>),
RequireTrustedTypesFor(Vec<&'a str>),
TrustedTypes(Vec<&'a str>),
UpgradeInsecureRequests,
}Expand description
Manages Content-Security-Policy header
The HTTP Content-Security-Policy response header allows web site administrators to control resources the user agent is allowed to load for a given page. With a few exceptions, policies mostly involve specifying server origins and script endpoints. This helps guard against cross-site scripting attacks (XSS).
§Directives
- child-src: Defines valid sources for web workers and nested browsing contexts loaded using elements such as
<frame>and<iframe>. - connect-src: Applies to XMLHttpRequest (AJAX), WebSocket or EventSource. If not allowed the browser emulates a 400 HTTP status code.
- default-src: The default-src is the default policy for loading content such as JavaScript, Images, CSS, Font’s, AJAX requests, Frames, HTML5 Media. See the list of directives to see which values are allowed as default.
- font-src: Defines valid sources for fonts loaded using @font-face.
- frame-src: Defines valid sources for nested browsing contexts loading using elements such as
<frame>and<iframe>. - img-src: Defines valid sources of images and favicons.
- manifest-src: Specifies which manifest can be applied to the resource.
- media-src: Defines valid sources for loading media using the
<audio>and<video>elements. - object-src: Defines valid sources for the
<object>,<embed>, and<applet>elements. - prefetch-src: Specifies which referrer to use when fetching the resource.
- script-src: Defines valid sources for JavaScript.
- script-src-elem: Defines valid sources for JavaScript inline event handlers.
- script-src-attr: Defines valid sources for JavaScript inline event handlers.
- style-src: Defines valid sources for stylesheets.
- style-src-elem: Defines valid sources for stylesheets inline event handlers.
- style-src-attr: Defines valid sources for stylesheets inline event handlers.
- worker-src: Defines valid sources for Worker, SharedWorker, or ServiceWorker scripts.
- base-uri: Restricts the URLs which can be used in a document’s
<base>element. - sandbox: Enables a sandbox for the requested resource similar to the iframe sandbox attribute. The sandbox applies a same origin policy, prevents popups, plugins and script execution is blocked. You can keep the sandbox value empty to keep all restrictions in place, or add values: allow-forms allow-same-origin allow-scripts allow-popups, allow-modals, allow-orientation-lock, allow-pointer-lock, allow-presentation, allow-popups-to-escape-sandbox, allow-top-navigation, allow-top-navigation-by-user-activation.
- form-action: Restricts the URLs which can be used as the target of a form submissions from a given context.
- frame-ancestors: Specifies valid parents that may embed a page using
<frame>,<iframe>,<object>,<embed>, or<applet>. - report-to: Enables reporting of violations.
- require-trusted-types-for: Specifies which trusted types are required by a resource.
- trusted-types: Specifies which trusted types are defined by a resource.
- upgrade-insecure-requests: Block HTTP requests on insecure elements.
§Examples
use helmet_core::ContentSecurityPolicy;
let content_security_policy = ContentSecurityPolicy::default()
.child_src(vec!["'self'", "https://youtube.com"])
.connect_src(vec!["'self'", "https://youtube.com"])
.default_src(vec!["'self'", "https://youtube.com"])
.font_src(vec!["'self'", "https://youtube.com"]);Variants§
ChildSrc(Vec<&'a str>)
Warning: Instead of child-src, if you want to regulate nested browsing contexts and workers, you should use the frame-src and worker-src directives, respectively.
ConnectSrc(Vec<&'a str>)
Applies to XMLHttpRequest (AJAX), WebSocket or EventSource. If not allowed the browser emulates a 400 HTTP status code.
DefaultSrc(Vec<&'a str>)
The default-src is the default policy for loading content such as JavaScript, Images, CSS, Font’s, AJAX requests, Frames, HTML5 Media. See the list of directives to see which values are allowed as default.
FontSrc(Vec<&'a str>)
Defines valid sources for fonts loaded using @font-face.
FrameSrc(Vec<&'a str>)
Defines valid sources for nested browsing contexts loading using elements such as <frame> and <iframe>.
ImgSrc(Vec<&'a str>)
Defines valid sources of images and favicons.
ManifestSrc(Vec<&'a str>)
Specifies which manifest can be applied to the resource.
MediaSrc(Vec<&'a str>)
Defines valid sources for loading media using the <audio> and <video> elements.
ObjectSrc(Vec<&'a str>)
Defines valid sources for the <object>, <embed>, and <applet> elements.
PrefetchSrc(Vec<&'a str>)
Specifies which referrer to use when fetching the resource.
ScriptSrc(Vec<&'a str>)
Defines valid sources for JavaScript.
ScriptSrcElem(Vec<&'a str>)
Defines valid sources for JavaScript inline event handlers.
ScriptSrcAttr(Vec<&'a str>)
Defines valid sources for JavaScript inline event handlers.
StyleSrc(Vec<&'a str>)
Defines valid sources for stylesheets.
StyleSrcElem(Vec<&'a str>)
Defines valid sources for stylesheets inline event handlers.
StyleSrcAttr(Vec<&'a str>)
Defines valid sources for stylesheets inline event handlers.
WorkerSrc(Vec<&'a str>)
Defines valid sources for Worker, SharedWorker, or ServiceWorker scripts.
BaseUri(Vec<&'a str>)
Restricts the URLs which can be used in a document’s <base> element.
Sandbox(Vec<&'a str>)
Enables a sandbox for the requested resource similar to the iframe sandbox attribute. The sandbox applies a same origin policy, prevents popups, plugins and script execution is blocked. You can keep the sandbox value empty to keep all restrictions in place, or add values: allow-forms allow-same-origin allow-scripts allow-popups, allow-modals, allow-orientation-lock, allow-pointer-lock, allow-presentation, allow-popups-to-escape-sandbox, allow-top-navigation, allow-top-navigation-by-user-activation.
FormAction(Vec<&'a str>)
Restricts the URLs which can be used as the target of a form submissions from a given context.
FrameAncestors(Vec<&'a str>)
Specifies valid parents that may embed a page using <frame>, <iframe>, <object>, <embed>, or <applet>.
ReportTo(Vec<&'a str>)
Enables reporting of violations.
report-uri is deprecated, however, it is still supported by browsers that don’t yet support report-to. ReportTo will apply both to report-uri and report-to with the same values, to support browsers that support both.
RequireTrustedTypesFor(Vec<&'a str>)
Specifies which trusted types are required by a resource.
TrustedTypes(Vec<&'a str>)
Specifies which trusted types are defined by a resource.
UpgradeInsecureRequests
Block HTTP requests on insecure elements.
Implementations§
Source§impl<'a> ContentSecurityPolicyDirective<'a>
impl<'a> ContentSecurityPolicyDirective<'a>
Sourcepub fn child_src(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
pub fn child_src(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
child-src: Defines valid sources for web workers and nested browsing contexts loaded using elements such as <frame>`` and
Sourcepub fn connect_src(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
pub fn connect_src(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
connect-src: Applies to XMLHttpRequest (AJAX), WebSocket or EventSource. If not allowed the browser emulates a 400 HTTP status code.
Sourcepub fn default_src(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
pub fn default_src(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
default-src: The default-src is the default policy for loading content such as JavaScript, Images, CSS, Font’s, AJAX requests, Frames, HTML5 Media. See the list of directives to see which values are allowed as default.
Sourcepub fn font_src(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
pub fn font_src(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
font-src: Defines valid sources for fonts loaded using @font-face.
Sourcepub fn frame_src(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
pub fn frame_src(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
frame-src: Defines valid sources for nested browsing contexts loading using elements such as <frame> and <iframe>.
Sourcepub fn img_src(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
pub fn img_src(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
img-src: Defines valid sources of images and favicons.
Sourcepub fn manifest_src(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
pub fn manifest_src(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
manifest-src: Specifies which manifest can be applied to the resource.
Sourcepub fn media_src(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
pub fn media_src(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
media-src: Defines valid sources for loading media using the <audio> and <video> elements.
Sourcepub fn object_src(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
pub fn object_src(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
object-src: Defines valid sources for the <object>, <embed>, and <applet> elements.
Sourcepub fn prefetch_src(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
pub fn prefetch_src(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
prefetch-src: Specifies which referrer to use when fetching the resource.
Sourcepub fn script_src(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
pub fn script_src(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
script-src: Defines valid sources for JavaScript.
Sourcepub fn script_src_elem(
values: Vec<&'a str>,
) -> ContentSecurityPolicyDirective<'a>
pub fn script_src_elem( values: Vec<&'a str>, ) -> ContentSecurityPolicyDirective<'a>
script-src-elem: Defines valid sources for JavaScript inline event handlers.
Sourcepub fn script_src_attr(
values: Vec<&'a str>,
) -> ContentSecurityPolicyDirective<'a>
pub fn script_src_attr( values: Vec<&'a str>, ) -> ContentSecurityPolicyDirective<'a>
script-src-attr: Defines valid sources for JavaScript inline event handlers.
Sourcepub fn style_src(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
pub fn style_src(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
style-src: Defines valid sources for stylesheets.
Sourcepub fn style_src_elem(
values: Vec<&'a str>,
) -> ContentSecurityPolicyDirective<'a>
pub fn style_src_elem( values: Vec<&'a str>, ) -> ContentSecurityPolicyDirective<'a>
style-src-elem: Defines valid sources for stylesheets inline event handlers.
Sourcepub fn style_src_attr(
values: Vec<&'a str>,
) -> ContentSecurityPolicyDirective<'a>
pub fn style_src_attr( values: Vec<&'a str>, ) -> ContentSecurityPolicyDirective<'a>
style-src-attr: Defines valid sources for stylesheets inline event handlers.
Sourcepub fn worker_src(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
pub fn worker_src(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
worker-src: Defines valid sources for Worker, SharedWorker, or ServiceWorker scripts.
Sourcepub fn base_uri(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
pub fn base_uri(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
base-uri: Restricts the URLs which can be used in a document’s <base> element.
Sourcepub fn sandbox(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
pub fn sandbox(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
sandbox: Enables a sandbox for the requested resource similar to the iframe sandbox attribute. The sandbox applies a same origin policy, prevents popups, plugins and script execution is blocked. You can keep the sandbox value empty to keep all restrictions in place, or add values: allow-forms allow-same-origin allow-scripts allow-popups, allow-modals, allow-orientation-lock, allow-pointer-lock, allow-presentation, allow-popups-to-escape-sandbox, allow-top-navigation, allow-top-navigation-by-user-activation.
Sourcepub fn form_action(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
pub fn form_action(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
form-action: Restricts the URLs which can be used as the target of a form submissions from a given context.
Sourcepub fn frame_ancestors(
values: Vec<&'a str>,
) -> ContentSecurityPolicyDirective<'a>
pub fn frame_ancestors( values: Vec<&'a str>, ) -> ContentSecurityPolicyDirective<'a>
frame-ancestors: Specifies valid parents that may embed a page using <frame>, <iframe>, <object>, <embed>, or <applet>.
Sourcepub fn report_to(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
pub fn report_to(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
report-to: Enables reporting of violations.
Sourcepub fn require_trusted_types_for(
values: Vec<&'a str>,
) -> ContentSecurityPolicyDirective<'a>
pub fn require_trusted_types_for( values: Vec<&'a str>, ) -> ContentSecurityPolicyDirective<'a>
require-trusted-types-for: Specifies which trusted types are required by a resource.
Sourcepub fn trusted_types(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
pub fn trusted_types(values: Vec<&'a str>) -> ContentSecurityPolicyDirective<'a>
trusted-types: Specifies which trusted types are defined by a resource.
Sourcepub fn upgrade_insecure_requests() -> ContentSecurityPolicyDirective<'a>
pub fn upgrade_insecure_requests() -> ContentSecurityPolicyDirective<'a>
Block HTTP requests on insecure elements.
Trait Implementations§
Source§impl<'a> Clone for ContentSecurityPolicyDirective<'a>
impl<'a> Clone for ContentSecurityPolicyDirective<'a>
Source§fn clone(&self) -> ContentSecurityPolicyDirective<'a>
fn clone(&self) -> ContentSecurityPolicyDirective<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more