Skip to content

Commit

Permalink
Merge pull request hapijs#828 from spumko/issue/807
Browse files Browse the repository at this point in the history
Add HttpOnly support to cookie auth
  • Loading branch information
geek committed May 7, 2013
2 parents 1fd96b2 + e37f42f commit 5270085
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,7 @@ of the cookie content can use it to impersonate its true owner. The `'cookie`' s
- `ttl` - sets the cookie expires time in milliseconds. Defaults to single browser session (ends when browser closes).
- `clearInvalid` - if `true`, any authentication cookie that fails validation will be marked as expired in the response and cleared. Defaults to `false`.
- `isSecure` - if `false`, the cookie is allowed to be transmitted over insecure connections which exposes it to attacks. Defaults to `true`.
- `isHttpOnly` - if `false`, the cookie will not include the 'HttpOnly' flag. Defaults to `true`.
- `redirectTo` - optional login URI to redirect unauthenticated requests to. Defaults to no redirection.
- `appendNext` - if `true` and `redirectTo` is `true`, appends the current request path to the query component of the `redirectTo` URI using the
parameter name `'next'`. Set to a string to use a different parameter name. Defaults to `false`.
Expand Down
3 changes: 2 additions & 1 deletion lib/auth/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ exports = module.exports = internals.Scheme = function (server, options) {
encoding: 'iron',
password: this.settings.password,
isSecure: this.settings.isSecure !== false, // Defaults to true
path: '/'
path: '/',
isHttpOnly: this.settings.isHttpOnly !== false // Defaults to true
};

if (this.settings.ttl) {
Expand Down
4 changes: 2 additions & 2 deletions test/integration/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,7 @@ describe('Auth', function () {

expect(res.statusCode).to.equal(200);
expect(res.result).to.equal('logged-out');
expect(res.headers['set-cookie'][0]).to.equal('special=; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Secure; Path=/');
expect(res.headers['set-cookie'][0]).to.equal('special=; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Secure; HttpOnly; Path=/');
done();
});
});
Expand All @@ -1327,7 +1327,7 @@ describe('Auth', function () {

server.inject({ method: 'GET', url: '/resource', headers: { cookie: 'special=' + cookie[1] } }, function (res) {

expect(res.headers['set-cookie'][0]).to.equal('special=; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Secure; Path=/');
expect(res.headers['set-cookie'][0]).to.equal('special=; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Secure; HttpOnly; Path=/');
expect(res.statusCode).to.equal(401);
done();
});
Expand Down

0 comments on commit 5270085

Please sign in to comment.