|  | 
| 2 | 2 | 
 | 
| 3 | 3 | use super::{trunk_id_selector, AssetFile, Attrs, TrunkAssetPipelineOutput, ATTR_HREF, ATTR_TYPE}; | 
| 4 | 4 | use crate::common::html_rewrite::Document; | 
|  | 5 | +use crate::common::nonce; | 
| 5 | 6 | use anyhow::{bail, Context, Result}; | 
| 6 | 7 | use std::path::PathBuf; | 
| 7 | 8 | use std::str::FromStr; | 
| @@ -125,9 +126,13 @@ impl InlineOutput { | 
| 125 | 126 |     pub async fn finalize(self, dom: &mut Document) -> Result<()> { | 
| 126 | 127 |         let html = match self.content_type { | 
| 127 | 128 |             ContentType::Html | ContentType::Svg => self.content, | 
| 128 |  | -            ContentType::Css => format!(r#"<style>{}</style>"#, self.content), | 
| 129 |  | -            ContentType::Js => format!(r#"<script>{}</script>"#, self.content), | 
| 130 |  | -            ContentType::Module => format!(r#"<script type="module">{}</script>"#, self.content), | 
|  | 129 | +            ContentType::Css => format!(r#"<style nonce="{}">{}</style>"#, nonce(), self.content), | 
|  | 130 | +            ContentType::Js => format!(r#"<script nonce="{}">{}</script>"#, nonce(), self.content), | 
|  | 131 | +            ContentType::Module => format!( | 
|  | 132 | +                r#"<script type="module" nonce="{}">{}</script>"#, | 
|  | 133 | +                nonce(), | 
|  | 134 | +                self.content | 
|  | 135 | +            ), | 
| 131 | 136 |         }; | 
| 132 | 137 | 
 | 
| 133 | 138 |         dom.replace_with_html(&trunk_id_selector(self.id), &html) | 
|  | 
0 commit comments