Skip to content

Commit 00970a1

Browse files
committed
Change hard-coded headernames to lowercase
1 parent 31533d9 commit 00970a1

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());
365365
}

src/security/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn default(mut headers: impl AsMut<Headers>) {
6262
// /// ```
6363
#[inline]
6464
pub fn dns_prefetch_control(mut headers: impl AsMut<Headers>) {
65-
headers.as_mut().insert("X-DNS-Prefetch-Control", "on");
65+
headers.as_mut().insert("x-dns-prefetch-control", "on");
6666
}
6767

6868
/// Set the frameguard level.
@@ -92,7 +92,7 @@ pub fn frameguard(mut headers: impl AsMut<Headers>, guard: Option<FrameOptions>)
9292
None | Some(FrameOptions::SameOrigin) => "sameorigin",
9393
Some(FrameOptions::Deny) => "deny",
9494
};
95-
headers.as_mut().insert("X-Frame-Options", kind);
95+
headers.as_mut().insert("x-frame-options", kind);
9696
}
9797

9898
/// Removes the `X-Powered-By` header to make it slightly harder for attackers to see what
@@ -111,7 +111,7 @@ pub fn frameguard(mut headers: impl AsMut<Headers>, guard: Option<FrameOptions>)
111111
// /// ```
112112
#[inline]
113113
pub fn powered_by(mut headers: impl AsMut<Headers>, value: Option<HeaderValue>) {
114-
let name = HeaderName::from_lowercase_str("X-Powered-By");
114+
let name = HeaderName::from_lowercase_str("x-powered-by");
115115
match value {
116116
Some(value) => {
117117
headers.as_mut().insert(name, value);
@@ -141,7 +141,7 @@ pub fn powered_by(mut headers: impl AsMut<Headers>, value: Option<HeaderValue>)
141141
pub fn hsts(mut headers: impl AsMut<Headers>) {
142142
headers
143143
.as_mut()
144-
.insert("Strict-Transport-Security", "max-age=5184000");
144+
.insert("strict-transport-security", "max-age=5184000");
145145
}
146146

147147
/// Prevent browsers from trying to guess (“sniff”) the MIME type, which can have security
@@ -159,7 +159,7 @@ pub fn hsts(mut headers: impl AsMut<Headers>) {
159159
// /// ```
160160
#[inline]
161161
pub fn nosniff(mut headers: impl AsMut<Headers>) {
162-
headers.as_mut().insert("X-Content-Type-Options", "nosniff");
162+
headers.as_mut().insert("x-content-type-options", "nosniff");
163163
}
164164

165165
/// Sets the `X-XSS-Protection` header to prevent reflected XSS attacks.
@@ -176,7 +176,7 @@ pub fn nosniff(mut headers: impl AsMut<Headers>) {
176176
// /// ```
177177
#[inline]
178178
pub fn xss_filter(mut headers: impl AsMut<Headers>) {
179-
headers.as_mut().insert("X-XSS-Protection", "1; mode=block");
179+
headers.as_mut().insert("x-xss-protection", "1; mode=block");
180180
}
181181

182182
/// Set the Referrer-Policy level
@@ -232,5 +232,5 @@ pub fn referrer_policy(mut headers: impl AsMut<Headers>, referrer: Option<Referr
232232

233233
// We MUST allow for multiple Referrer-Policy headers to be set.
234234
// See: https://w3c.github.io/webappsec-referrer-policy/#unknown-policy-values example #13
235-
headers.as_mut().append("Referrer-Policy", policy);
235+
headers.as_mut().append("referrer-policy", policy);
236236
}

0 commit comments

Comments
 (0)