Skip to content
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

Set X-XSS-Protection to 1; mode=block. #1550

Merged
merged 1 commit into from
Aug 6, 2018
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
4 changes: 4 additions & 0 deletions yesod-core/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.6.8

* Sets the `X-XSS-Protection` header to `1; mode=block` [#1550](https://github.com/yesodweb/yesod/pull/1550)

## 1.6.7

* If no matches are found, `selectRep` chooses first representation regardless
Expand Down
4 changes: 3 additions & 1 deletion yesod-core/Yesod/Core/Class/Yesod.hs
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,14 @@ defaultShouldLogIO :: LogSource -> LogLevel -> IO Bool
defaultShouldLogIO _ level = return $ level >= LevelInfo

-- | Default implementation of 'yesodMiddleware'. Adds the response header
-- \"Vary: Accept, Accept-Language\" and performs authorization checks.
-- \"Vary: Accept, Accept-Language\", \"X-XSS-Protection: 1; mode=block\", and
-- performs authorization checks.
--
-- Since 1.2.0
defaultYesodMiddleware :: Yesod site => HandlerFor site res -> HandlerFor site res
defaultYesodMiddleware handler = do
addHeader "Vary" "Accept, Accept-Language"
addHeader "X-XSS-Protection" "1; mode=block"
authorizationCheck
handler

Expand Down
7 changes: 7 additions & 0 deletions yesod-core/test/YesodCoreTest/Header.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,16 @@ header3Test = do
assertHeader "michael" "snoyman" res
assertHeader "yesod" "book" res

xssHeaderTest :: IO ()
xssHeaderTest = do
runner $ do
res <- request defaultRequest {pathInfo = decodePathSegments "/header1"}
assertHeader "X-XSS-Protection" "1; mode=block" res

headerTest :: Spec
headerTest =
describe "Test.Header" $ do
it "addHeader" addHeaderTest
it "multiple header" multipleHeaderTest
it "persist headers" header3Test
it "has X-XSS-Protection: 1; mode=block" xssHeaderTest
2 changes: 1 addition & 1 deletion yesod-core/yesod-core.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: yesod-core
version: 1.6.7
version: 1.6.8
license: MIT
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>
Expand Down