Skip to content

Commit

Permalink
oidc/callback: handle missing state param (#1392)
Browse files Browse the repository at this point in the history
Without this check, a request without a state parameter will generate an
internal server error and receive a 500-status response.

This change sends the client through the proper error-handling route.
  • Loading branch information
alxndrsn authored Feb 12, 2025
1 parent 1544035 commit 8387cbe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/resources/oidc.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ const loaderTemplate = `
parse(loaderTemplate); // caches template for future perf.

const stateFor = next => [ generators.state(), Buffer.from(next).toString('base64url') ].join(':');
const nextFrom = state => Buffer.from(state.split(':')[1], 'base64url').toString();
const nextFrom = state => {
if (state) return Buffer.from(state.split(':')[1], 'base64url').toString();
};

module.exports = (service, endpoint) => {
if (!isEnabled()) return;
Expand Down
12 changes: 12 additions & 0 deletions test/integration/api/oidc.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,24 @@ describe('api: /oidc/...', () => {
url.searchParams.get('code_challenge').should.match(/^[a-zA-Z0-9-_]{43}$/);
url.searchParams.get('state' ).should.match(/^[a-zA-Z0-9-_]{43}:$/); // eslint-disable-line space-in-parens,no-multi-spaces
})));

it('should redirect to error page if no parameters are provided', testService(service =>
service.get('/v1/oidc/callback')
.expect(303)
.then(({ text, headers }) => {
text.should.eql('See Other. Redirecting to http://localhost:8989/#/login?oidcError=internal-server-error');
headers.location.should.eql('http://localhost:8989/#/login?oidcError=internal-server-error');
})));
});
} else { // OIDC not enabled
describe('GET /oidc/login', () => {
it('should not exist', testService(service =>
service.get('/v1/oidc/login')
.expect(404)));

it('should not exist', testService(service =>
service.get('/v1/oidc/callback')
.expect(404)));
});
}
});

0 comments on commit 8387cbe

Please sign in to comment.