Skip to content

Commit 9f648c0

Browse files
Remove csp_nonce field from all template types
1 parent f1488e0 commit 9f648c0

13 files changed

+11
-63
lines changed

Diff for: src/web/build_details.rs

-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ struct BuildDetailsPage {
3939
build_details: BuildDetails,
4040
all_log_filenames: Vec<String>,
4141
current_filename: Option<String>,
42-
csp_nonce: String,
4342
}
4443

4544
impl_axum_webpage! { BuildDetailsPage }
@@ -155,7 +154,6 @@ pub(crate) async fn build_details_handler(
155154
},
156155
all_log_filenames,
157156
current_filename,
158-
csp_nonce: String::new(),
159157
}
160158
.into_response())
161159
}

Diff for: src/web/builds.rs

-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ struct BuildsPage {
4949
builds: Vec<Build>,
5050
limits: Limits,
5151
canonical_url: CanonicalUrl,
52-
csp_nonce: String,
5352
}
5453

5554
impl_axum_webpage! { BuildsPage }
@@ -81,7 +80,6 @@ pub(crate) async fn build_list_handler(
8180
builds: get_builds(&mut conn, &name, &version).await?,
8281
limits: Limits::for_crate(&config, &mut conn, &name).await?,
8382
canonical_url: CanonicalUrl::from_path(format!("/crate/{name}/latest/builds")),
84-
csp_nonce: String::new(),
8583
}
8684
.into_response())
8785
}

Diff for: src/web/crate_details.rs

-7
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,6 @@ struct CrateDetailsPage {
445445
is_library: Option<bool>,
446446
last_successful_build: Option<String>,
447447
rustdoc: Option<String>, // this is description_long in database
448-
csp_nonce: String,
449448
source_size: Option<i64>,
450449
documentation_size: Option<i64>,
451450
}
@@ -545,7 +544,6 @@ pub(crate) async fn crate_details_handler(
545544
is_library,
546545
last_successful_build,
547546
rustdoc,
548-
csp_nonce: String::new(),
549547
source_size,
550548
documentation_size,
551549
}
@@ -567,7 +565,6 @@ struct ReleaseList {
567565
crate_name: String,
568566
inner_path: String,
569567
target: String,
570-
csp_nonce: String,
571568
}
572569

573570
impl_axum_webpage! {
@@ -649,7 +646,6 @@ pub(crate) async fn get_all_releases(
649646
target,
650647
inner_path,
651648
crate_name: params.name,
652-
csp_nonce: String::new(),
653649
};
654650
Ok(res.into_response())
655651
}
@@ -677,7 +673,6 @@ struct PlatformList {
677673
inner_path: String,
678674
use_direct_platform_links: bool,
679675
current_target: String,
680-
csp_nonce: String,
681676
}
682677

683678
impl_axum_webpage! {
@@ -748,7 +743,6 @@ pub(crate) async fn get_all_platforms_inner(
748743
inner_path: "".into(),
749744
use_direct_platform_links: is_crate_root,
750745
current_target: "".into(),
751-
csp_nonce: String::new(),
752746
}
753747
.into_response());
754748
}
@@ -803,7 +797,6 @@ pub(crate) async fn get_all_platforms_inner(
803797
inner_path,
804798
use_direct_platform_links: is_crate_root,
805799
current_target,
806-
csp_nonce: String::new(),
807800
}
808801
.into_response())
809802
}

Diff for: src/web/error.rs

-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ impl IntoResponse for AxumNope {
148148
title,
149149
message,
150150
status,
151-
csp_nonce: String::new(),
152151
}
153152
.into_response()
154153
}

Diff for: src/web/features.rs

-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ struct FeaturesPage {
8989
default_features: HashSet<String>,
9090
canonical_url: CanonicalUrl,
9191
is_latest_url: bool,
92-
csp_nonce: String,
9392
}
9493

9594
impl FeaturesPage {
@@ -167,7 +166,6 @@ pub(crate) async fn build_features_handler(
167166
default_features,
168167
is_latest_url: req_version.is_latest(),
169168
canonical_url: CanonicalUrl::from_path(format!("/crate/{}/latest/features", &name)),
170-
csp_nonce: String::new(),
171169
}
172170
.into_response())
173171
}

Diff for: src/web/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,6 @@ pub(crate) struct AxumErrorPage {
758758
/// The error message, displayed as a description
759759
pub message: Cow<'static, str>,
760760
pub status: StatusCode,
761-
pub csp_nonce: String,
762761
}
763762

764763
impl_axum_webpage! {

Diff for: src/web/page/web_page.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ macro_rules! impl_axum_webpage {
2626
) => {
2727
impl $crate::web::page::web_page::AddCspNonce for $page {
2828
fn render_with_csp_nonce(&mut self, csp_nonce: String) -> askama::Result<String> {
29-
self.csp_nonce = csp_nonce;
30-
self.render()
29+
let values: [(&str, &dyn std::any::Any); 1] = [("csp_nonce", &csp_nonce)];
30+
self.render_with_values(&values)
3131
}
3232
}
3333

Diff for: src/web/releases.rs

+2-18
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ async fn get_search_results(
238238
#[derive(Debug, Clone, PartialEq, Eq)]
239239
struct HomePage {
240240
recent_releases: Vec<Release>,
241-
csp_nonce: String,
242241
}
243242

244243
impl_axum_webpage! {
@@ -250,18 +249,14 @@ pub(crate) async fn home_page(mut conn: DbConnection) -> AxumResult<impl IntoRes
250249
let recent_releases =
251250
get_releases(&mut conn, 1, RELEASES_IN_HOME, Order::ReleaseTime, true).await?;
252251

253-
Ok(HomePage {
254-
recent_releases,
255-
csp_nonce: String::new(),
256-
})
252+
Ok(HomePage { recent_releases })
257253
}
258254

259255
#[derive(Template)]
260256
#[template(path = "releases/feed.xml")]
261257
#[derive(Debug, Clone, PartialEq, Eq)]
262258
struct ReleaseFeed {
263259
recent_releases: Vec<Release>,
264-
csp_nonce: String,
265260
}
266261

267262
impl_axum_webpage! {
@@ -272,10 +267,7 @@ impl_axum_webpage! {
272267
pub(crate) async fn releases_feed_handler(mut conn: DbConnection) -> AxumResult<impl IntoResponse> {
273268
let recent_releases =
274269
get_releases(&mut conn, 1, RELEASES_IN_FEED, Order::ReleaseTime, true).await?;
275-
Ok(ReleaseFeed {
276-
recent_releases,
277-
csp_nonce: String::new(),
278-
})
270+
Ok(ReleaseFeed { recent_releases })
279271
}
280272

281273
#[derive(Template)]
@@ -289,7 +281,6 @@ struct ViewReleases {
289281
show_previous_page: bool,
290282
page_number: i64,
291283
owner: Option<String>,
292-
csp_nonce: String,
293284
}
294285

295286
impl_axum_webpage! { ViewReleases }
@@ -378,7 +369,6 @@ pub(crate) async fn releases_handler(
378369
show_previous_page,
379370
page_number,
380371
owner: None,
381-
csp_nonce: String::new(),
382372
})
383373
}
384374

@@ -431,7 +421,6 @@ pub(super) struct Search {
431421
/// This should always be `ReleaseType::Search`
432422
pub(super) release_type: ReleaseType,
433423
pub(super) status: http::StatusCode,
434-
pub(super) csp_nonce: String,
435424
}
436425

437426
impl Default for Search {
@@ -445,7 +434,6 @@ impl Default for Search {
445434
search_sort_by: None,
446435
release_type: ReleaseType::Search,
447436
status: http::StatusCode::OK,
448-
csp_nonce: String::new(),
449437
}
450438
}
451439
}
@@ -644,7 +632,6 @@ struct ReleaseActivity {
644632
dates: Vec<String>,
645633
counts: Vec<i64>,
646634
failures: Vec<i64>,
647-
csp_nonce: String,
648635
}
649636

650637
impl_axum_webpage! { ReleaseActivity }
@@ -700,7 +687,6 @@ pub(crate) async fn activity_handler(mut conn: DbConnection) -> AxumResult<impl
700687
.collect(),
701688
counts: rows.iter().map(|rows| rows.counts).collect(),
702689
failures: rows.iter().map(|rows| rows.failures).collect(),
703-
csp_nonce: String::new(),
704690
})
705691
}
706692

@@ -713,7 +699,6 @@ struct BuildQueuePage {
713699
rebuild_queue: Vec<QueuedCrate>,
714700
active_cdn_deployments: Vec<String>,
715701
in_progress_builds: Vec<(String, String)>,
716-
csp_nonce: String,
717702
expand_rebuild_queue: bool,
718703
}
719704

@@ -791,7 +776,6 @@ pub(crate) async fn build_queue_handler(
791776
rebuild_queue,
792777
active_cdn_deployments,
793778
in_progress_builds,
794-
csp_nonce: String::new(),
795779
expand_rebuild_queue: params.expand.is_some(),
796780
})
797781
}

Diff for: src/web/routes.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -293,16 +293,12 @@ pub(super) fn build_axum_routes() -> AxumRouter {
293293
#[derive(Template)]
294294
#[template(path = "storage-change-detection.html")]
295295
#[derive(Debug, Clone)]
296-
struct StorageChangeDetection {
297-
csp_nonce: String,
298-
}
296+
struct StorageChangeDetection;
299297
crate::impl_axum_webpage!(
300298
StorageChangeDetection,
301299
cache_policy = |_| CachePolicy::ForeverInCdnAndBrowser,
302300
);
303-
StorageChangeDetection {
304-
csp_nonce: String::new(),
305-
}
301+
StorageChangeDetection
306302
}),
307303
)
308304
.route_with_tsr(

Diff for: src/web/sitemap.rs

+2-19
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use std::sync::Arc;
2222
#[derive(Debug, Clone, PartialEq, Eq)]
2323
struct SitemapIndexXml {
2424
sitemaps: Vec<char>,
25-
csp_nonce: String,
2625
}
2726

2827
impl_axum_webpage! {
@@ -33,10 +32,7 @@ impl_axum_webpage! {
3332
pub(crate) async fn sitemapindex_handler() -> impl IntoResponse {
3433
let sitemaps: Vec<char> = ('a'..='z').collect();
3534

36-
SitemapIndexXml {
37-
sitemaps,
38-
csp_nonce: String::new(),
39-
}
35+
SitemapIndexXml { sitemaps }
4036
}
4137

4238
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -52,7 +48,6 @@ struct SitemapRow {
5248
#[derive(Debug, Clone, PartialEq, Eq)]
5349
struct SitemapXml {
5450
releases: Vec<SitemapRow>,
55-
csp_nonce: String,
5651
}
5752

5853
impl_axum_webpage! {
@@ -102,10 +97,7 @@ pub(crate) async fn sitemap_handler(
10297
.try_collect()
10398
.await?;
10499

105-
Ok(SitemapXml {
106-
releases,
107-
csp_nonce: String::new(),
108-
})
100+
Ok(SitemapXml { releases })
109101
}
110102

111103
#[derive(Template)]
@@ -118,7 +110,6 @@ struct AboutBuilds {
118110
limits: Limits,
119111
/// Just for the template, since this isn't shared with AboutPage
120112
active_tab: &'static str,
121-
csp_nonce: String,
122113
}
123114

124115
impl_axum_webpage!(AboutBuilds);
@@ -131,7 +122,6 @@ pub(crate) async fn about_builds_handler(
131122
rustc_version: get_config::<String>(&mut conn, ConfigName::RustcVersion).await?,
132123
limits: Limits::new(&config),
133124
active_tab: "builds",
134-
csp_nonce: String::new(),
135125
})
136126
}
137127

@@ -141,7 +131,6 @@ macro_rules! about_page {
141131
#[template(path = $template)]
142132
struct $ty {
143133
active_tab: &'static str,
144-
csp_nonce: String,
145134
}
146135

147136
impl_axum_webpage! { $ty }
@@ -163,27 +152,22 @@ pub(crate) async fn about_handler(subpage: Option<Path<String>>) -> AxumResult<i
163152
let response = match &subpage[..] {
164153
"about" | "index" => AboutPage {
165154
active_tab: "index",
166-
csp_nonce: String::new(),
167155
}
168156
.into_response(),
169157
"badges" => AboutPageBadges {
170158
active_tab: "badges",
171-
csp_nonce: String::new(),
172159
}
173160
.into_response(),
174161
"metadata" => AboutPageMetadata {
175162
active_tab: "metadata",
176-
csp_nonce: String::new(),
177163
}
178164
.into_response(),
179165
"redirections" => AboutPageRedirection {
180166
active_tab: "redirections",
181-
csp_nonce: String::new(),
182167
}
183168
.into_response(),
184169
"download" => AboutPageDownload {
185170
active_tab: "download",
186-
csp_nonce: String::new(),
187171
}
188172
.into_response(),
189173
_ => {
@@ -193,7 +177,6 @@ pub(crate) async fn about_handler(subpage: Option<Path<String>>) -> AxumResult<i
193177
title: "The requested page does not exist",
194178
message: msg.into(),
195179
status: StatusCode::NOT_FOUND,
196-
csp_nonce: String::new(),
197180
};
198181
page.into_response()
199182
}

Diff for: src/web/source.rs

-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ struct SourcePage {
163163
canonical_url: CanonicalUrl,
164164
is_file_too_large: bool,
165165
is_latest_url: bool,
166-
csp_nonce: String,
167166
}
168167

169168
impl_axum_webpage! {
@@ -338,7 +337,6 @@ pub(crate) async fn source_browser_handler(
338337
canonical_url,
339338
is_file_too_large,
340339
is_latest_url: params.version.is_latest(),
341-
csp_nonce: String::new(),
342340
}
343341
.into_response())
344342
}

Diff for: templates/base.html

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
<title>{%- block title -%} Docs.rs {%- endblock title -%}</title>
1919

20+
{%- let csp_nonce = askama::get_value::<String>("csp_nonce").unwrap() -%}
21+
2022
<script nonce="{{ csp_nonce }}">{%- include "theme.js" -%}</script>
2123
{%- block css -%}{%- endblock css -%}
2224

Diff for: 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 nonce="{{ csp_nonce }}" type="text/javascript">
11+
<script nonce="{{ askama::get_value::<String>("csp_nonce").unwrap() }}" type="text/javascript">
1212
onstorage = function(ev) {
1313
parent.postMessage({
1414
storage: {

0 commit comments

Comments
 (0)