Skip to content

Commit d728868

Browse files
committed
Change hard-coded headernames to lowercase
1 parent 7d7323a commit d728868

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/security/csp.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,9 @@ impl ContentSecurityPolicy {
357357
/// Sets the `Content-Security-Policy` (CSP) HTTP header to prevent cross-site injections
358358
pub fn apply(&mut self, mut headers: impl AsMut<Headers>) {
359359
let name = if self.report_only_flag {
360-
"Content-Security-Policy-Report-Only"
360+
"content-security-policy-report-only"
361361
} else {
362-
"Content-Security-Policy"
362+
"content-security-policy"
363363
};
364364
headers.as_mut().insert(name, self.value()).unwrap();
365365
}

src/security/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub fn dns_prefetch_control(mut headers: impl AsMut<Headers>) {
6565
// This will never fail, could use an unsafe version of insert.
6666
headers
6767
.as_mut()
68-
.insert("X-DNS-Prefetch-Control", "on")
68+
.insert("x-dns-prefetch-control", "on")
6969
.unwrap();
7070
}
7171

@@ -97,7 +97,7 @@ pub fn frameguard(mut headers: impl AsMut<Headers>, guard: Option<FrameOptions>)
9797
Some(FrameOptions::Deny) => "deny",
9898
};
9999
// This will never fail, could use an unsafe version of insert.
100-
headers.as_mut().insert("X-Frame-Options", kind).unwrap();
100+
headers.as_mut().insert("x-frame-options", kind).unwrap();
101101
}
102102

103103
/// Removes the `X-Powered-By` header to make it slightly harder for attackers to see what
@@ -116,7 +116,7 @@ pub fn frameguard(mut headers: impl AsMut<Headers>, guard: Option<FrameOptions>)
116116
// /// ```
117117
#[inline]
118118
pub fn powered_by(mut headers: impl AsMut<Headers>, value: Option<HeaderValue>) {
119-
let name = HeaderName::from_lowercase_str("X-Powered-By");
119+
let name = HeaderName::from_lowercase_str("x-powered-by");
120120
match value {
121121
Some(value) => {
122122
// Can never fail as value is already a HeaderValue, could use unsafe version of insert
@@ -148,7 +148,7 @@ pub fn hsts(mut headers: impl AsMut<Headers>) {
148148
// Never fails, could use unsafe version of insert
149149
headers
150150
.as_mut()
151-
.insert("Strict-Transport-Security", "max-age=5184000")
151+
.insert("strict-transport-security", "max-age=5184000")
152152
.unwrap();
153153
}
154154

@@ -170,7 +170,7 @@ pub fn nosniff(mut headers: impl AsMut<Headers>) {
170170
// Never fails, could use unsafe verison of insert.
171171
headers
172172
.as_mut()
173-
.insert("X-Content-Type-Options", "nosniff")
173+
.insert("x-content-type-options", "nosniff")
174174
.unwrap();
175175
}
176176

@@ -191,7 +191,7 @@ pub fn xss_filter(mut headers: impl AsMut<Headers>) {
191191
// Never fails, could use unsafe version of insert.
192192
headers
193193
.as_mut()
194-
.insert("X-XSS-Protection", "1; mode=block")
194+
.insert("x-xss-protection", "1; mode=block")
195195
.unwrap();
196196
}
197197

@@ -249,5 +249,5 @@ pub fn referrer_policy(mut headers: impl AsMut<Headers>, referrer: Option<Referr
249249
// We MUST allow for multiple Referrer-Policy headers to be set.
250250
// See: https://w3c.github.io/webappsec-referrer-policy/#unknown-policy-values example #13
251251
// Never fails, could use unsafe version of append.
252-
headers.as_mut().append("Referrer-Policy", policy).unwrap();
252+
headers.as_mut().append("referrer-policy", policy).unwrap();
253253
}

0 commit comments

Comments
 (0)