forked from brokenhandsio/VaporSecurityHeaders
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable X-XSS-Protection filter, for safety
Surprisingly, [`X-XSS-Protection` is safer when disabled][0], and browsers are dropping support for it as a result. Because it's less safe to enable the filter, this change sets the default (and only) value to `0`, instead of `1; mode=block`. This is a breaking change. See [issue brokenhandsio#25][1]. [0]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection [1]: brokenhandsio#25
- Loading branch information
Showing
5 changed files
with
15 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 2 additions & 23 deletions
25
Sources/VaporSecurityHeaders/Configurations/XSSProtectionConfiguration.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,9 @@ | ||
import Vapor | ||
|
||
public struct XSSProtectionConfiguration: SecurityHeaderConfiguration { | ||
|
||
public enum Options { | ||
case disable | ||
case enable | ||
case block | ||
case report(uri: String) | ||
} | ||
|
||
private let option: Options | ||
|
||
public init(option: Options) { | ||
self.option = option | ||
} | ||
public init () {} | ||
|
||
func setHeader(on response: Response, from request: Request) { | ||
switch option { | ||
case .disable: | ||
response.headers.replaceOrAdd(name: .xssProtection, value: "0") | ||
case .enable: | ||
response.headers.replaceOrAdd(name: .xssProtection, value: "1") | ||
case .block: | ||
response.headers.replaceOrAdd(name: .xssProtection, value: "1; mode=block") | ||
case .report(let uri): | ||
response.headers.replaceOrAdd(name: .xssProtection, value: "1; report=\(uri)") | ||
} | ||
response.headers.replaceOrAdd(name: .xssProtection, value: "0") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters