Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(security): Prevent open redirect (#496)
Report: https://www.huntr.dev/bounties/cfc18877-c2ad-41ac-96c7-128a06c51ea9/ * reproduce open redirect problem * fix: implement and call safe redirect from /consent route
- Loading branch information
1 parent
916dc1d
commit eb7a0e0
Showing
4 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* global describe, it, before */ | ||
|
||
const { promisify } = require('util'); | ||
const assert = require('assert'); | ||
|
||
const { ADMIN_USER, cleanup, URL_PREFIX } = require('../fixtures.js'); | ||
const apiClient = require('../api-client.js'); | ||
|
||
const postRaw = promisify(apiClient.postRaw); | ||
const loginAs = promisify(apiClient.loginAs); | ||
|
||
before(cleanup); | ||
|
||
describe('security', () => { | ||
describe('Open Redirect', () => { | ||
it('should allow redirect to /stream', async () => { | ||
const target = `/stream`; | ||
const { jar } = await loginAs(ADMIN_USER); | ||
const { response } = await postRaw(jar, `/consent`, { | ||
lang: 'en', | ||
redirect: target, | ||
}); | ||
assert.equal(response.statusCode, 302); | ||
assert.equal(response.headers.location, target); | ||
}); | ||
|
||
it(`should allow redirect to ${URL_PREFIX}/stream`, async () => { | ||
const target = `${URL_PREFIX}/stream`; | ||
const { jar } = await loginAs(ADMIN_USER); | ||
const { response } = await postRaw(jar, `/consent`, { | ||
lang: 'en', | ||
redirect: target, | ||
}); | ||
assert.equal(response.statusCode, 302); | ||
assert.equal(response.headers.location, target); | ||
}); | ||
|
||
it('should NOT allow redirect to other domain', async () => { | ||
const { jar } = await loginAs(ADMIN_USER); | ||
const { response } = await postRaw(jar, `/consent`, { | ||
lang: 'en', | ||
redirect: `http://google.com`, | ||
}); | ||
assert.equal(response.statusCode, 403); // forbidden | ||
}); | ||
}); | ||
}); |