merge: Only accept HTML <link rel="alternate"> on successful HTTP statuses (!633)

View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/633

Approved-by: dakkar <dakkar@thenautilus.net>
Approved-by: Tess K <me@thvxl.se>
Approved-by: fEmber <acomputerdog@gmail.com>
Approved-by: Marie <github@yuugi.dev>
This commit is contained in:
Julia 2024-09-23 17:51:26 +00:00
commit c94f6994dd

View file

@ -207,7 +207,11 @@ export class ApRequestService {
//#region リクエスト先がhtmlかつactivity+jsonへのalternate linkタグがあるとき
const contentType = res.headers.get('content-type');
if ((contentType ?? '').split(';')[0].trimEnd().toLowerCase() === 'text/html' && _followAlternate === true) {
if (
res.ok
&& (contentType ?? '').split(';')[0].trimEnd().toLowerCase() === 'text/html'
&& _followAlternate === true
) {
const html = await res.text();
const window = new Window({
settings: {
@ -242,6 +246,8 @@ export class ApRequestService {
}
} catch (e) {
// something went wrong parsing the HTML, ignore the whole thing
} finally {
await window.happyDOM.close();
}
}
//#endregion