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

Updated HSTS to support the preload flag #10

Merged
merged 1 commit into from
Apr 26, 2015
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Enables [Platform for Privacy Preferences Project](http://support.microsoft.com/
* `options.maxAge` Number - Required. Number of seconds HSTS is in effect.
* `options.includeSubDomains` Boolean - Optional. Applies HSTS to all subdomains of the host

Enables [HTTP Strict Transport Security](https://www.owasp.org/index.php/HTTP_Strict_Transport_Security) for the host domain.
Enables [HTTP Strict Transport Security](https://www.owasp.org/index.php/HTTP_Strict_Transport_Security) for the host domain. The preload flag is required for HSTS domain submissions to [Chrome's HSTS preload list](https://hstspreload.appspot.com)

### lusca.xssProtection(options)

Expand Down
1 change: 1 addition & 0 deletions lib/hsts.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ module.exports = function (options) {
if (options.includeSubDomains) {
value += '; includeSubDomains';
}
value += (value && options.preload) ? '; preload' : '';

return function* hsts(next) {
this.set('Strict-Transport-Security', value);
Expand Down
15 changes: 15 additions & 0 deletions test/hsts.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ describe('HSTS', function () {
.expect(200, done);
});

it('header (maxAge; includeSubDomains; preload)', function (done) {
var config = { hsts: { maxAge: 31536000, includeSubDomains: true, preload: true } };
var app = mock(config);

app.get('/', function* () {
this.body = 'hello';
});

request(app.listen())
.get('/')
.expect('Strict-Transport-Security', 'max-age=' + config.hsts.maxAge + '; includeSubDomains; preload')
.expect('hello')
.expect(200, done);
});

it('header (missing maxAge)', function () {
assert.throws(function () {
mock({ hsts: {} });
Expand Down