activitypub: disallow cross-origin redirects
Changelog: Security
This commit is contained in:
parent
7e37a8fd88
commit
01f8c5d7da
1 changed files with 6 additions and 1 deletions
|
@ -118,7 +118,12 @@ export async function signedGet(_url: string, user: { id: User['id'] }): Promise
|
|||
if (res.status >= 300 && res.status < 400) {
|
||||
// Have been redirected, need to make a new signature.
|
||||
// Use Location header and fetched URL as the base URL.
|
||||
url = new URL(res.headers.get('Location'), url).href;
|
||||
let newUrl = new URL(res.headers.get('Location'), url);
|
||||
// Check that we have not been redirected to a different host.
|
||||
if (newUrl.host !== new URL(url).host) {
|
||||
throw new Error('cross-origin redirect not allowed');
|
||||
}
|
||||
url = newUrl.href;
|
||||
} else {
|
||||
if (!isActivitypub(res.headers.get('Content-Type'))) {
|
||||
throw new Error('invalid response content type');
|
||||
|
|
Loading…
Add table
Reference in a new issue