Skip to content

Commit

Permalink
fix: normalize single string set-cookie headers
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Nov 5, 2024
1 parent 478f9b5 commit 6effeed
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/shared/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ export default async function sessionHandler(ctx, next) {
await ctx.oidc.session.save(ttl);
}

if (ctx.response.get('set-cookie')) {
ctx.response.get('set-cookie').forEach((cookie, index, ary) => {
let setCookie;
// eslint-disable-next-line no-cond-assign
if ((setCookie = ctx.response.get('set-cookie'))) {
if (typeof setCookie === 'string') {
setCookie = [setCookie];
}
setCookie.forEach((cookie, index, ary) => {
/* eslint-disable no-param-reassign */
if (
!cookie.includes('expires=Thu, 01 Jan 1970')
Expand Down
23 changes: 23 additions & 0 deletions test/core/basic/isscookie.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import bootstrap from '../../test_helper.js';

describe('pre-middleware setting "set-cookie" header', () => {
before(bootstrap(import.meta.url));

before(function () {
this.provider.use((ctx, next) => {
ctx.response.set('set-cookie', 'foo=bar;');
return next();
});
});

it('does not disturb the session middleware', function () {
const auth = new this.AuthorizationRequest({
response_type: 'invalid',
state: null,
});

return this.wrap({ route: '/auth', verb: 'get', auth })
.expect(303)
.expect(auth.validatePresence(['error', 'error_description']));
});
});

0 comments on commit 6effeed

Please sign in to comment.