pub struct CspPlugin;Expand description
Plugin that extracts inline styles/scripts to external files with SRI.
Runs in after_compile after all other content transforms but before
minification. For each HTML file:
- Finds
<style>…</style>and<script>…</script>inline blocks - Writes each block to
_csp/<hash>.cssor_csp/<hash>.js - Replaces the inline block with a
<link>/<script src>tag includingintegrityandcrossoriginattributes — SHA-384 by default, configurable via[security] sri_algorithminssg.toml(v0.0.47 plan §3 item 2.3) - Rewrites any
<meta>CSP tags to remove'unsafe-inline'
Blocks with type="application/ld+json" or data-ssg-livereload
attributes are skipped (structured data / dev-only scripts).
§Computed policy
The single string the plugin posture enforces is exposed via
computed_policy; downstream HTTP-header emitters (e.g. the
edge_headers postprocess plugin) call that function rather than
hardcoding a CSP string of their own, so the policy stays in
lock-step across <meta> injection and platform HTTP headers.
Implementations§
Trait Implementations§
impl Copy for CspPlugin
Source§impl Plugin for CspPlugin
impl Plugin for CspPlugin
Source§fn has_transform(&self) -> bool
fn has_transform(&self) -> bool
Returns
true if this plugin implements transform_html.
Override to true to opt in to the fused transform pass.Source§fn transform_html(
&self,
html: &str,
path: &Path,
ctx: &PluginContext,
) -> Result<String, SsgError>
fn transform_html( &self, html: &str, path: &Path, ctx: &PluginContext, ) -> Result<String, SsgError>
Per-file HTML transform hook — called once per HTML file during
the fused transform pass. Read more
Source§fn after_compile(&self, ctx: &PluginContext) -> Result<(), SsgError>
fn after_compile(&self, ctx: &PluginContext) -> Result<(), SsgError>
Called after site compilation completes. Read more
Source§fn before_compile(&self, _ctx: &PluginContext) -> Result<(), SsgError>
fn before_compile(&self, _ctx: &PluginContext) -> Result<(), SsgError>
Called before site compilation begins. Read more
Source§fn needs_all_files(&self) -> bool
fn needs_all_files(&self) -> bool
Returns
true if this plugin must always observe the full
cache.html_files() list — even during --incremental
rebuilds that only invalidated a handful of pages. Read moreAuto Trait Implementations§
impl Freeze for CspPlugin
impl RefUnwindSafe for CspPlugin
impl Send for CspPlugin
impl Sync for CspPlugin
impl Unpin for CspPlugin
impl UnsafeUnpin for CspPlugin
impl UnwindSafe for CspPlugin
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more