Skip to content

Commit 0aba6d1

Browse files
mahsa2terop
authored andcommitted
Disable the X-XSS-Protection header in defaults
Disable the XSS Auditor in older browsers by default. The X-XSS-Protection header has been deprecated by modern browsers due to security issues it introduces on the client. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection Fixes #35.
1 parent 9b167af commit 0aba6d1

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@ The following configuration keys are supported:
138138
server is on a non-standard port. See: [wrap-ssl-redirect][9].
139139

140140
- `:xss-protection` -
141-
Enable the X-XSS-Protection header that tells supporting browsers
142-
to use heuristics to detect XSS attacks. See: [wrap-xss-protection][10].
141+
**Deprecated** Enable the X-XSS-Protection header. This is [no
142+
longer considered best practice][13] and should be avoided.
143+
See: [wrap-xss-protection][10].
143144

144145
- `:session` -
145146
A map of options for configuring session handling via the Ring
@@ -175,6 +176,7 @@ The following configuration keys are supported:
175176
[10]: https://ring-clojure.github.io/ring-headers/ring.middleware.x-headers.html#var-wrap-xss-protection
176177
[11]: https://ring-clojure.github.io/ring/ring.middleware.session.html
177178
[12]: https://ring-clojure.github.io/ring/ring.middleware.flash.html
179+
[13]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection
178180

179181

180182
## License

src/ring/middleware/defaults.clj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
:session {:flash true
4545
:cookie-attrs {:http-only true, :same-site :strict}}
4646
:security {:anti-forgery true
47-
:xss-protection {:enable? true, :mode :block}
4847
:frame-options :sameorigin
4948
:content-type-options :nosniff}
5049
:static {:resources "public"}

test/ring/middleware/defaults_test.clj

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@
2222
(is (= (set (keys (:headers resp)))
2323
#{"X-Frame-Options"
2424
"X-Content-Type-Options"
25-
"X-XSS-Protection"
2625
"Content-Type"
2726
"Set-Cookie"}))
2827
(is (= (get-in resp [:headers "X-Frame-Options"]) "SAMEORIGIN"))
2928
(is (= (get-in resp [:headers "X-Content-Type-Options"]) "nosniff"))
30-
(is (= (get-in resp [:headers "X-XSS-Protection"]) "1; mode=block"))
3129
(is (= (get-in resp [:headers "Content-Type"]) "application/octet-stream"))
3230
(let [set-cookie (first (get-in resp [:headers "Set-Cookie"]))]
3331
(is (.startsWith set-cookie "ring-session="))
@@ -99,13 +97,11 @@
9997
(is (= (set (keys (:headers resp)))
10098
#{"X-Frame-Options"
10199
"X-Content-Type-Options"
102-
"X-XSS-Protection"
103100
"Strict-Transport-Security"
104101
"Content-Type"
105102
"Set-Cookie"}))
106103
(is (= (get-in resp [:headers "X-Frame-Options"]) "SAMEORIGIN"))
107104
(is (= (get-in resp [:headers "X-Content-Type-Options"]) "nosniff"))
108-
(is (= (get-in resp [:headers "X-XSS-Protection"]) "1; mode=block"))
109105
(is (= (get-in resp [:headers "Strict-Transport-Security"])
110106
"max-age=31536000; includeSubDomains"))
111107
(is (= (get-in resp [:headers "Content-Type"]) "application/octet-stream"))
@@ -171,3 +167,13 @@
171167
(is (= @resp {:status 200
172168
:headers {"Content-Type" "application/octet-stream"}
173169
:body "foo"})))))
170+
171+
(testing "XSS protection enabled"
172+
(let [handler (-> (constantly (response "foo"))
173+
(wrap-defaults
174+
(-> site-defaults
175+
(assoc-in [:security :xss-protection :enable?] true)
176+
(assoc-in [:security :xss-protection :mode] :block))))
177+
resp (handler (request :get "/"))]
178+
(is (not (nil? (get-in resp [:headers "X-XSS-Protection"]))))
179+
(is (= (get-in resp [:headers "X-XSS-Protection"]) "1; mode=block"))))

0 commit comments

Comments
 (0)