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

Handle State encoding issue inbound from Provider #114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 4 additions & 0 deletions lib/state/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ SessionStore.prototype.verify = function(req, handle, cb) {
delete req.session[key];
}

//handle providers (AWS Cognito) that don't properly encode the + [plus sign] (%2B) char in the state
// query parameter. This results in a space in the handle. Must replace with + char
handle = handle.replace(/\s/g, '+');

if (state.handle !== handle) {
return cb(null, false, { message: 'Invalid authorization request state.' });
}
Expand Down
24 changes: 23 additions & 1 deletion test/store/session.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,29 @@ describe('SessionStore', function() {
})
.authenticate();
}); // should error when app does not have session support


it('should replace whitespace characters with + character in state handle', function(done) {
chai.passport.use(strategy)
.request(function(req) {
req.query = {
code: 'SplxlOBeZQQYbYS6WxSbIA',
state: 'af 0ifjsld kj'
};
req.session = {};
req.session['openidconnect:server.example.com'] = {
state: {
handle: 'af+0ifjsld+kj'
}
};
})
.success(function(user, info) {
expect(this.session['openidconnect:server.example.com']).to.be.undefined;
done();
})
.error(done)
.authenticate();
});

}); // #verify

});