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

Disable x-xss-protection by default #147

Closed
wants to merge 2 commits into from
Closed
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: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ Enables [HTTP Strict Transport Security](https://www.owasp.org/index.php/HTTP_St

### lusca.xssProtection(options)

* `options.enabled` Boolean - Optional. If the header is enabled or not (see header docs). Defaults to `1`.
* `options.mode` String - Optional. Mode to set on the header (see header docs). Defaults to `block`.
* `options.enabled` Boolean - Optional. If the header is enabled or not (see header docs). Defaults to `0`.
* `options.mode` String - Optional. Mode to set on the header (see header docs). Defaults to ``.

Enables [X-XSS-Protection](http://blogs.msdn.com/b/ie/archive/2008/07/02/ie8-security-part-iv-the-xss-filter.aspx) headers to help prevent cross site scripting (XSS) attacks in older IE browsers (IE8)

Expand Down
11 changes: 8 additions & 3 deletions lib/xssprotection.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ module.exports = function xssProtection(options) {
options = options || {};

// `enabled` should be either `1` or `0`
var enabled = (options.enabled !== undefined) ? +options.enabled : 1;
var mode = options.mode || 'block';
var enabled = (options.enabled !== undefined) ? +options.enabled : 0;
var mode = options.mode || '';

return function xssProtection(req, res, next) {
res.header('x-xss-protection', enabled + '; mode=' + mode);
if (!mode) {
res.header('x-xss-protection', enabled);
} else {
res.header('x-xss-protection', enabled + '; mode=' + mode);
}

next();
};
};