Skip to content

Commit

Permalink
Merge pull request #739 from azylman/master
Browse files Browse the repository at this point in the history
Fixes #733 - parse x-forwarded-proto more generally
  • Loading branch information
tj committed Feb 12, 2013
2 parents 7dbd875 + fb96f99 commit 9afeb1f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/middleware/session.js
Expand Up @@ -248,7 +248,7 @@ function session(options){
res.on('header', function(){
if (!req.session) return;
var cookie = req.session.cookie
, proto = (req.headers['x-forwarded-proto'] || '').toLowerCase()
, proto = (req.headers['x-forwarded-proto'] || '').split(',')[0].toLowerCase().trim()
, tls = req.connection.encrypted || (trustProxy && 'https' == proto)
, secured = cookie.secure && tls
, isNew = unsignedCookie != req.sessionID;
Expand Down Expand Up @@ -312,7 +312,7 @@ function session(options){

// error handling
if (err) {
debug('error');
debug('error' + JSON.stringify(err));
if ('ENOENT' == err.code) {
generate();
next();
Expand Down
17 changes: 16 additions & 1 deletion test/session.js
Expand Up @@ -32,7 +32,7 @@ describe('connect.session()', function(){

describe('proxy option', function(){
describe('when enabled', function(){
it('should trust X-Forwarded-Proto', function(done){
it('should trust X-Forwarded-Proto when string', function(done){
var app = connect()
.use(connect.cookieParser())
.use(connect.session({ secret: 'keyboard cat', proxy: true, cookie: { secure: true, maxAge: 5 }}))
Expand All @@ -46,6 +46,21 @@ describe('connect.session()', function(){
done();
});
})

it('should trust X-Forwarded-Proto when comma-separated list', function(done){
var app = connect()
.use(connect.cookieParser())
.use(connect.session({ secret: 'keyboard cat', proxy: true, cookie: { secure: true, maxAge: 5 }}))
.use(respond);

app.request()
.get('/')
.set('X-Forwarded-Proto', 'https,http')
.end(function(res){
res.headers.should.have.property('set-cookie');
done();
});
})
})

describe('when disabled', function(){
Expand Down

0 comments on commit 9afeb1f

Please sign in to comment.