Skip to content

Add CSP nonce on inline script in storage-change-detection.html #1388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/web/page/web_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use tera::Context;
#[macro_export]
macro_rules! impl_webpage {
($page:ty = $template:literal $(, status = $status:expr)? $(, content_type = $content_type:expr)? $(,)?) => {
impl_webpage!($page = |_| ::std::borrow::Cow::Borrowed($template) $(, status = $status)? $(, content_type = $content_type)?);
$crate::impl_webpage!($page = |_| ::std::borrow::Cow::Borrowed($template) $(, status = $status)? $(, content_type = $content_type)?);
};

($page:ty = $template:expr $(, status = $status:expr)? $(, content_type = $content_type:expr)? $(,)?) => {
Expand Down
9 changes: 9 additions & 0 deletions src/web/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ pub(super) fn build_routes() -> Routes {

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

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

Expand Down
4 changes: 2 additions & 2 deletions templates/rustdoc/body.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
}
</script>

{# see comment in ../../static/storage-change-detection.html for details #}
<iframe src="/-/static/storage-change-detection.html" width="0" height="0" style="display: none"></iframe>
{# see comment in ../storage-change-detection.html for details #}
<iframe src="/-/storage-change-detection.html" width="0" height="0" style="display: none"></iframe>
{%- include "footer.html" -%}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
../templates/theme.js when rustdoc in the current window changes the
theme
-->
<script type="text/javascript">
<script nonce="{{ csp_nonce }}" type="text/javascript">
onstorage = function(ev) {
parent.postMessage({
storage: {
Expand Down
2 changes: 1 addition & 1 deletion templates/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ window.addEventListener('storage', function (ev) {
}
});

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