Skip to content

Commit 63fe23e

Browse files
Nemo157Joshua Nelson
authored and
Joshua Nelson
committed
Add CSP nonce on inline script in storage-change-detection.html
1 parent 36ba3a3 commit 63fe23e

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed

src/web/page/web_page.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use tera::Context;
1010
#[macro_export]
1111
macro_rules! impl_webpage {
1212
($page:ty = $template:literal $(, status = $status:expr)? $(, content_type = $content_type:expr)? $(,)?) => {
13-
impl_webpage!($page = |_| ::std::borrow::Cow::Borrowed($template) $(, status = $status)? $(, content_type = $content_type)?);
13+
$crate::impl_webpage!($page = |_| ::std::borrow::Cow::Borrowed($template) $(, status = $status)? $(, content_type = $content_type)?);
1414
};
1515

1616
($page:ty = $template:expr $(, status = $status:expr)? $(, content_type = $content_type:expr)? $(,)?) => {

src/web/routes.rs

+9
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ pub(super) fn build_routes() -> Routes {
3131

3232
routes.static_resource("/-/static/:single", super::statics::static_handler);
3333
routes.static_resource("/-/static/*", super::statics::static_handler);
34+
routes.internal_page("/-/storage-change-detection.html", {
35+
#[derive(Debug, serde::Serialize)]
36+
struct StorageChangeDetection {}
37+
crate::impl_webpage!(StorageChangeDetection = "storage-change-detection.html");
38+
fn storage_change_detection(req: &mut iron::Request) -> iron::IronResult<iron::Response> {
39+
crate::web::page::WebPage::into_response(StorageChangeDetection {}, req)
40+
}
41+
storage_change_detection
42+
});
3443

3544
routes.internal_page("/", super::releases::home_page);
3645

templates/rustdoc/body.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
}
3232
</script>
3333

34-
{# see comment in ../../static/storage-change-detection.html for details #}
35-
<iframe src="/-/static/storage-change-detection.html" width="0" height="0" style="display: none"></iframe>
34+
{# see comment in ../storage-change-detection.html for details #}
35+
<iframe src="/-/storage-change-detection.html" width="0" height="0" style="display: none"></iframe>
3636
{%- include "footer.html" -%}

static/storage-change-detection.html renamed to templates/storage-change-detection.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
../templates/theme.js when rustdoc in the current window changes the
99
theme
1010
-->
11-
<script type="text/javascript">
11+
<script nonce="{{ csp_nonce }}" type="text/javascript">
1212
onstorage = function(ev) {
1313
parent.postMessage({
1414
storage: {

templates/theme.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ window.addEventListener('storage', function (ev) {
88
}
99
});
1010

11-
// see ../static/storage-change-detection.html for details
11+
// see ./storage-change-detection.html for details
1212
window.addEventListener('message', function (ev) {
1313
if (ev.data && ev.data.storage && ev.data.storage.key === 'rustdoc-theme') {
1414
applyTheme(ev.data.storage.value);

0 commit comments

Comments
 (0)