Skip to content

Commit

Permalink
fix(security): Prevent redirect to a disguised domain (#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienjoly committed Dec 10, 2021
1 parent 8fa2e93 commit 3870793
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/models/logging.js
Expand Up @@ -262,7 +262,8 @@ http.ServerResponse.prototype.redirect = function (url) {

http.ServerResponse.prototype.safeRedirect = function (url) {
const fullURL = new URL(url, config.urlPrefix);
if (!fullURL.toString().startsWith(config.urlPrefix)) return this.forbidden();
if (`${fullURL.protocol}//${fullURL.host}` !== config.urlPrefix)
return this.forbidden();
this.redirect(url);
};

Expand Down
9 changes: 9 additions & 0 deletions test/api/security.api.tests.js
Expand Up @@ -43,5 +43,14 @@ describe('security', () => {
});
assert.equal(response.statusCode, 403); // forbidden
});

it('should NOT allow redirect to a disguised domain', async () => {
const { jar } = await loginAs(ADMIN_USER);
const { response } = await postRaw(jar, `/consent`, {
lang: 'en',
redirect: `${URL_PREFIX}@google.com`,
});
assert.equal(response.statusCode, 403); // forbidden
});
});
});

0 comments on commit 3870793

Please sign in to comment.