[backend] Canonicalize URLs before comparing them during object id consistency checks in the AP resolver

This commit is contained in:
Laura Hausmann 2024-09-18 23:37:09 +02:00
parent ca12d54c81
commit 7074a2efaf
No known key found for this signature in database
GPG Key ID: D044E84C5BE01605

View File

@ -125,14 +125,20 @@ export default class Resolver {
const {res, object} = await this.doFetch(value);
if (object.id == null) throw new Error("Object has no ID");
if (res.finalUrl === object.id) return object;
const objectId = new URL(object.id);
const resFinalUrl = new URL(res.finalUrl);
if (resFinalUrl.toString() === objectId.toString()) return object;
if (new URL(res.finalUrl).host !== new URL(object.id).host)
if (resFinalUrl.host !== objectId.host)
throw new Error("Object ID host doesn't match final url host");
const {res: finalRes, object: finalObject} = await this.doFetch(object.id);
if (finalRes.finalUrl !== finalObject.id)
if (finalObject.id == null) throw new Error("Final object has no ID");
const finalObjectId = new URL(finalObject.id);
const finalResFinalUrl = new URL(finalRes.finalUrl);
if (finalResFinalUrl.toString() !== finalObjectId.toString())
throw new Error("Object ID still doesn't match final URL after second fetch attempt")
return finalObject;