@fedify/fedify 2.2.0-pr.710.26 → 2.2.0-pr.715.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{builder-BG2fljmM.mjs → builder-DQtY9nHQ.mjs} +3 -3
- package/dist/compat/transformers.test.mjs +2 -2
- package/dist/{deno-Bg4eBr2D.mjs → deno-_fgAC2zJ.mjs} +1 -1
- package/dist/{docloader-DNzzLpZS.mjs → docloader-vRYuv1jI.mjs} +2 -2
- package/dist/federation/builder.test.mjs +2 -2
- package/dist/federation/collection.test.mjs +1 -1
- package/dist/federation/handler.test.mjs +4 -4
- package/dist/federation/idempotency.test.mjs +3 -3
- package/dist/federation/inbox.test.mjs +1 -1
- package/dist/federation/keycache.test.mjs +2 -2
- package/dist/federation/kv.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +7 -17
- package/dist/federation/mod.cjs +1 -1
- package/dist/federation/mod.js +1 -1
- package/dist/federation/negotiation.test.mjs +1 -1
- package/dist/federation/retry.test.mjs +1 -1
- package/dist/federation/send.test.mjs +3 -3
- package/dist/federation/webfinger.test.mjs +2 -2
- package/dist/{http-DWkREdt7.mjs → http-C8rif6ld.mjs} +2 -2
- package/dist/{http-Dgit35mk.cjs → http-R-epZzZQ.cjs} +1 -1
- package/dist/{http-Cbg9qm41.js → http-s3HaFg5o.js} +1 -1
- package/dist/{key-DkuUQiqs.mjs → key-Ce0SDXK2.mjs} +1 -1
- package/dist/{kv-cache-e9fvIFDA.cjs → kv-cache-Btpmwlb5.cjs} +1 -1
- package/dist/{kv-cache-Bl6yhpBL.js → kv-cache-ChSAw77q.js} +1 -1
- package/dist/{ld-1klZemqw.mjs → ld-BsDP9tTM.mjs} +2 -2
- package/dist/{middleware-DRNKgUtw.js → middleware-C4ymcV-E.js} +3 -4
- package/dist/{middleware-DY-mzSrv.cjs → middleware-CXG1M9Om.cjs} +1 -1
- package/dist/{middleware-BDpu1OCd.mjs → middleware-DFQeBAbL.mjs} +1 -1
- package/dist/{middleware-D1zxydrX.mjs → middleware-DtEWmK1Y.mjs} +15 -17
- package/dist/{middleware-G6DmtY5H.cjs → middleware-vUbXbazq.cjs} +4 -5
- package/dist/mod.cjs +4 -4
- package/dist/mod.js +4 -4
- package/dist/nodeinfo/client.test.mjs +1 -1
- package/dist/nodeinfo/handler.test.mjs +2 -2
- package/dist/nodeinfo/types.test.mjs +1 -1
- package/dist/otel/exporter.test.mjs +1 -1
- package/dist/{owner-ijaWLw_K.mjs → owner-CTfDotXM.mjs} +2 -2
- package/dist/{proof-CP0GRqWY.cjs → proof-3RPJLWOU.cjs} +38 -221
- package/dist/{proof-BbfBQytm.mjs → proof-UdlPVu_P.mjs} +31 -36
- package/dist/{proof-CQJHVvjQ.js → proof-qQIVjzlw.js} +41 -218
- package/dist/{send-CJyp2e8W.mjs → send-kudDOImz.mjs} +2 -2
- package/dist/sig/http.test.mjs +2 -2
- package/dist/sig/key.test.mjs +1 -1
- package/dist/sig/ld.test.mjs +2 -2
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.js +2 -2
- package/dist/sig/owner.test.mjs +1 -1
- package/dist/sig/proof.test.mjs +2 -60
- package/dist/utils/docloader.test.mjs +2 -2
- package/dist/utils/mod.cjs +1 -1
- package/dist/utils/mod.js +1 -1
- package/package.json +6 -6
- package/dist/compat/public-audience.test.d.mts +0 -2
- package/dist/compat/public-audience.test.mjs +0 -178
- package/dist/public-audience-eovWqzOF.mjs +0 -181
- /package/dist/{activity-listener-CFzUqoCS.mjs → activity-listener-Ck3JZ_hR.mjs} +0 -0
- /package/dist/{client-DVu6Fmom.mjs → client-DEpOVgY1.mjs} +0 -0
- /package/dist/{collection-BQRKGS7L.mjs → collection-BD6-SZ6O.mjs} +0 -0
- /package/dist/{keycache-C2t1kvP5.mjs → keycache-CCSwkQcY.mjs} +0 -0
- /package/dist/{kv-C-TG81Sv.mjs → kv-tL2TOE9X.mjs} +0 -0
- /package/dist/{negotiation-xb0QR3u_.mjs → negotiation-DnsfFF8I.mjs} +0 -0
- /package/dist/{retry-CJL0poaU.mjs → retry-B_E3V_Dx.mjs} +0 -0
- /package/dist/{types-CGUnLkU3.mjs → types-DCP0WLdt.mjs} +0 -0
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import "@js-temporal/polyfill";
|
|
2
|
-
import "urlpattern-polyfill";
|
|
3
|
-
globalThis.addEventListener = () => {};
|
|
4
|
-
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
5
|
-
import { t as assertNotEquals } from "../assert_not_equals--wG9hV7u.mjs";
|
|
6
|
-
import { t as normalizePublicAudience } from "../public-audience-eovWqzOF.mjs";
|
|
7
|
-
import { test } from "@fedify/fixture";
|
|
8
|
-
import { Create, Note, PUBLIC_COLLECTION } from "@fedify/vocab";
|
|
9
|
-
import { getDocumentLoader, preloadedContexts } from "@fedify/vocab-runtime";
|
|
10
|
-
//#region src/compat/public-audience.test.ts
|
|
11
|
-
const PUBLIC_URI = PUBLIC_COLLECTION.href;
|
|
12
|
-
const AS_CONTEXT = "https://www.w3.org/ns/activitystreams";
|
|
13
|
-
test("normalizePublicAudience() rewrites every addressing field and both CURIE forms", async () => {
|
|
14
|
-
const output = await normalizePublicAudience({
|
|
15
|
-
"@context": AS_CONTEXT,
|
|
16
|
-
type: "Note",
|
|
17
|
-
id: "https://example.com/notes/1",
|
|
18
|
-
to: "as:Public",
|
|
19
|
-
cc: ["as:Public", "https://example.com/bob"],
|
|
20
|
-
bto: "Public",
|
|
21
|
-
bcc: ["Public"],
|
|
22
|
-
audience: ["as:Public", "Public"]
|
|
23
|
-
});
|
|
24
|
-
assertEquals(output.to, PUBLIC_URI);
|
|
25
|
-
assertEquals(output.cc, [PUBLIC_URI, "https://example.com/bob"]);
|
|
26
|
-
assertEquals(output.bto, PUBLIC_URI);
|
|
27
|
-
assertEquals(output.bcc, [PUBLIC_URI]);
|
|
28
|
-
assertEquals(output.audience, [PUBLIC_URI, PUBLIC_URI]);
|
|
29
|
-
});
|
|
30
|
-
test("normalizePublicAudience() normalises activities serialized by @fedify/vocab", async () => {
|
|
31
|
-
const compact = await new Create({
|
|
32
|
-
id: new URL("https://example.com/activities/1"),
|
|
33
|
-
actor: new URL("https://example.com/alice"),
|
|
34
|
-
object: new Note({
|
|
35
|
-
id: new URL("https://example.com/notes/1"),
|
|
36
|
-
content: "Hello, world!",
|
|
37
|
-
tos: [PUBLIC_COLLECTION]
|
|
38
|
-
}),
|
|
39
|
-
tos: [PUBLIC_COLLECTION],
|
|
40
|
-
ccs: [new URL("https://example.com/followers")]
|
|
41
|
-
}).toJsonLd({ format: "compact" });
|
|
42
|
-
assertEquals(compact.to, "as:Public");
|
|
43
|
-
const normalized = await normalizePublicAudience(compact, getDocumentLoader());
|
|
44
|
-
assertEquals(normalized.to, PUBLIC_URI);
|
|
45
|
-
const nestedObject = normalized.object;
|
|
46
|
-
assertEquals(nestedObject.to, PUBLIC_URI);
|
|
47
|
-
});
|
|
48
|
-
test("normalizePublicAudience() is a no-op without the CURIE", async () => {
|
|
49
|
-
const input = {
|
|
50
|
-
"@context": AS_CONTEXT,
|
|
51
|
-
type: "Note",
|
|
52
|
-
id: "https://example.com/notes/3",
|
|
53
|
-
to: PUBLIC_URI
|
|
54
|
-
};
|
|
55
|
-
assertEquals(await normalizePublicAudience(input), input);
|
|
56
|
-
});
|
|
57
|
-
test("normalizePublicAudience() leaves non-addressing fields untouched", async () => {
|
|
58
|
-
const output = await normalizePublicAudience({
|
|
59
|
-
"@context": AS_CONTEXT,
|
|
60
|
-
type: "Note",
|
|
61
|
-
id: "https://example.com/notes/4",
|
|
62
|
-
name: "as:Public",
|
|
63
|
-
to: "as:Public"
|
|
64
|
-
});
|
|
65
|
-
assertEquals(output.name, "as:Public");
|
|
66
|
-
assertEquals(output.to, PUBLIC_URI);
|
|
67
|
-
});
|
|
68
|
-
test("normalizePublicAudience() rewrites without canonicalization for known-safe contexts", async () => {
|
|
69
|
-
const rejecting = () => {
|
|
70
|
-
throw new Error("contextLoader should not be called for a known-safe @context");
|
|
71
|
-
};
|
|
72
|
-
assertEquals((await normalizePublicAudience({
|
|
73
|
-
"@context": AS_CONTEXT,
|
|
74
|
-
type: "Note",
|
|
75
|
-
id: "https://example.com/notes/fast1",
|
|
76
|
-
to: "as:Public"
|
|
77
|
-
}, rejecting)).to, PUBLIC_URI);
|
|
78
|
-
assertEquals((await normalizePublicAudience({
|
|
79
|
-
"@context": [AS_CONTEXT, "https://w3id.org/security/data-integrity/v1"],
|
|
80
|
-
type: "Note",
|
|
81
|
-
id: "https://example.com/notes/fast2",
|
|
82
|
-
to: "as:Public"
|
|
83
|
-
}, rejecting)).to, PUBLIC_URI);
|
|
84
|
-
});
|
|
85
|
-
test("normalizePublicAudience() falls back to canonicalization for unknown-URL contexts", async () => {
|
|
86
|
-
let loaderCalls = 0;
|
|
87
|
-
const loader = (url) => {
|
|
88
|
-
loaderCalls++;
|
|
89
|
-
return Promise.resolve({
|
|
90
|
-
contextUrl: null,
|
|
91
|
-
documentUrl: url,
|
|
92
|
-
document: preloadedContexts[AS_CONTEXT]
|
|
93
|
-
});
|
|
94
|
-
};
|
|
95
|
-
assertEquals((await normalizePublicAudience({
|
|
96
|
-
"@context": [AS_CONTEXT, "https://custom.example/ctx"],
|
|
97
|
-
type: "Note",
|
|
98
|
-
id: "https://example.com/notes/unknown",
|
|
99
|
-
to: "as:Public"
|
|
100
|
-
}, loader)).to, PUBLIC_URI);
|
|
101
|
-
assertEquals(loaderCalls > 0, true);
|
|
102
|
-
});
|
|
103
|
-
test("normalizePublicAudience() leaves @context subtrees untouched", async () => {
|
|
104
|
-
const inlineCtx = (await normalizePublicAudience({
|
|
105
|
-
"@context": [AS_CONTEXT, { "customTerm": "as:Public" }],
|
|
106
|
-
type: "Note",
|
|
107
|
-
id: "https://example.com/notes/context",
|
|
108
|
-
to: PUBLIC_URI
|
|
109
|
-
}))["@context"][1];
|
|
110
|
-
assertEquals(inlineCtx.customTerm, "as:Public");
|
|
111
|
-
});
|
|
112
|
-
test("normalizePublicAudience() does not traverse prototype-polluted keys", async () => {
|
|
113
|
-
const polluted = Object.create({ to: "as:Public" });
|
|
114
|
-
polluted["@context"] = AS_CONTEXT;
|
|
115
|
-
polluted.type = "Note";
|
|
116
|
-
polluted.id = "https://example.com/notes/proto";
|
|
117
|
-
const output = await normalizePublicAudience(polluted);
|
|
118
|
-
assertEquals(Object.hasOwn(output, "to"), false);
|
|
119
|
-
});
|
|
120
|
-
test("normalizePublicAudience() stops before blowing the stack on pathological nesting", async () => {
|
|
121
|
-
let deep = { to: "as:Public" };
|
|
122
|
-
for (let i = 0; i < 256; i++) deep = { nested: deep };
|
|
123
|
-
assertEquals(typeof await normalizePublicAudience({
|
|
124
|
-
"@context": AS_CONTEXT,
|
|
125
|
-
type: "Note",
|
|
126
|
-
id: "https://example.com/notes/deep",
|
|
127
|
-
to: "as:Public",
|
|
128
|
-
object: deep
|
|
129
|
-
}), "object");
|
|
130
|
-
});
|
|
131
|
-
test("normalizePublicAudience() does not poison the global prototype via a __proto__ key", async () => {
|
|
132
|
-
await normalizePublicAudience(JSON.parse(`{
|
|
133
|
-
"@context": "https://www.w3.org/ns/activitystreams",
|
|
134
|
-
"type": "Note",
|
|
135
|
-
"id": "https://example.com/notes/proto-pollution",
|
|
136
|
-
"to": "as:Public",
|
|
137
|
-
"__proto__": { "polluted": true }
|
|
138
|
-
}`));
|
|
139
|
-
assertEquals(Object.prototype.polluted, void 0);
|
|
140
|
-
});
|
|
141
|
-
test("normalizePublicAudience() bails out on nested @context that redefines as:", async () => {
|
|
142
|
-
const output = await normalizePublicAudience({
|
|
143
|
-
"@context": AS_CONTEXT,
|
|
144
|
-
type: "Create",
|
|
145
|
-
id: "https://example.com/activities/nested",
|
|
146
|
-
actor: "https://example.com/alice",
|
|
147
|
-
to: "as:Public",
|
|
148
|
-
object: {
|
|
149
|
-
"@context": { "as": "https://not-activitystreams.example/" },
|
|
150
|
-
type: "https://www.w3.org/ns/activitystreams#Note",
|
|
151
|
-
id: "https://example.com/objects/nested",
|
|
152
|
-
to: "as:Public"
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
assertEquals(output.to, "as:Public");
|
|
156
|
-
const nested = output.object;
|
|
157
|
-
assertEquals(nested.to, "as:Public");
|
|
158
|
-
});
|
|
159
|
-
test("normalizePublicAudience() bails out when the rewrite changes semantics", async () => {
|
|
160
|
-
const output = await normalizePublicAudience({
|
|
161
|
-
"@context": {
|
|
162
|
-
"as": "https://not-activitystreams.example/",
|
|
163
|
-
"to": {
|
|
164
|
-
"@id": "https://www.w3.org/ns/activitystreams#to",
|
|
165
|
-
"@type": "@id"
|
|
166
|
-
},
|
|
167
|
-
"type": "@type",
|
|
168
|
-
"id": "@id"
|
|
169
|
-
},
|
|
170
|
-
type: "https://www.w3.org/ns/activitystreams#Note",
|
|
171
|
-
id: "https://example.com/notes/5",
|
|
172
|
-
to: "as:Public"
|
|
173
|
-
});
|
|
174
|
-
assertEquals(output.to, "as:Public");
|
|
175
|
-
assertNotEquals(output.to, PUBLIC_URI);
|
|
176
|
-
});
|
|
177
|
-
//#endregion
|
|
178
|
-
export {};
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import "@js-temporal/polyfill";
|
|
2
|
-
import "urlpattern-polyfill";
|
|
3
|
-
globalThis.addEventListener = () => {};
|
|
4
|
-
import { PUBLIC_COLLECTION } from "@fedify/vocab";
|
|
5
|
-
import { preloadedContexts } from "@fedify/vocab-runtime";
|
|
6
|
-
import { getLogger } from "@logtape/logtape";
|
|
7
|
-
import jsonld from "@fedify/vocab-runtime/jsonld";
|
|
8
|
-
//#region src/compat/public-audience.ts
|
|
9
|
-
const logger = getLogger([
|
|
10
|
-
"fedify",
|
|
11
|
-
"compat",
|
|
12
|
-
"public-audience"
|
|
13
|
-
]);
|
|
14
|
-
const PUBLIC_ADDRESSING_FIELDS = new Set([
|
|
15
|
-
"to",
|
|
16
|
-
"cc",
|
|
17
|
-
"bto",
|
|
18
|
-
"bcc",
|
|
19
|
-
"audience"
|
|
20
|
-
]);
|
|
21
|
-
const preloadedOnlyDocumentLoader = (url) => {
|
|
22
|
-
if (Object.hasOwn(preloadedContexts, url)) return Promise.resolve({
|
|
23
|
-
contextUrl: null,
|
|
24
|
-
documentUrl: url,
|
|
25
|
-
document: preloadedContexts[url]
|
|
26
|
-
});
|
|
27
|
-
return Promise.reject(/* @__PURE__ */ new Error("Refusing to fetch a non-preloaded JSON-LD context: " + url));
|
|
28
|
-
};
|
|
29
|
-
const AS_CONTEXT_URL = "https://www.w3.org/ns/activitystreams";
|
|
30
|
-
const MAX_TRAVERSAL_DEPTH = 64;
|
|
31
|
-
const KNOWN_SAFE_CONTEXT_URLS = new Set(Object.keys(preloadedContexts));
|
|
32
|
-
function hasPublicCurieInAddressing(value, parentKey, depth = 0) {
|
|
33
|
-
if (typeof value === "string") return parentKey != null && PUBLIC_ADDRESSING_FIELDS.has(parentKey) && (value === "as:Public" || value === "Public");
|
|
34
|
-
if (depth >= MAX_TRAVERSAL_DEPTH) return false;
|
|
35
|
-
if (Array.isArray(value)) return value.some((item) => hasPublicCurieInAddressing(item, parentKey, depth + 1));
|
|
36
|
-
if (typeof value !== "object" || value == null) return false;
|
|
37
|
-
const record = value;
|
|
38
|
-
for (const key of Object.keys(record)) {
|
|
39
|
-
if (key === "@context") continue;
|
|
40
|
-
if (hasPublicCurieInAddressing(record[key], key, depth + 1)) return true;
|
|
41
|
-
}
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
function rewritePublicAudience(value, parentKey, depth = 0) {
|
|
45
|
-
if (typeof value === "string" && parentKey != null && PUBLIC_ADDRESSING_FIELDS.has(parentKey) && (value === "as:Public" || value === "Public")) return PUBLIC_COLLECTION.href;
|
|
46
|
-
if (depth >= MAX_TRAVERSAL_DEPTH) return value;
|
|
47
|
-
if (Array.isArray(value)) {
|
|
48
|
-
let changed = false;
|
|
49
|
-
const mapped = value.map((item) => {
|
|
50
|
-
const rewritten = rewritePublicAudience(item, parentKey, depth + 1);
|
|
51
|
-
if (rewritten !== item) changed = true;
|
|
52
|
-
return rewritten;
|
|
53
|
-
});
|
|
54
|
-
return changed ? mapped : value;
|
|
55
|
-
}
|
|
56
|
-
if (typeof value !== "object" || value == null) return value;
|
|
57
|
-
const record = value;
|
|
58
|
-
let changed = false;
|
|
59
|
-
const normalized = Object.create(null);
|
|
60
|
-
for (const key of Object.keys(record)) {
|
|
61
|
-
const rewritten = key === "@context" ? record[key] : rewritePublicAudience(record[key], key, depth + 1);
|
|
62
|
-
if (rewritten !== record[key]) changed = true;
|
|
63
|
-
normalized[key] = rewritten;
|
|
64
|
-
}
|
|
65
|
-
return changed ? normalized : value;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Reports whether `value` carries an `@context` property anywhere inside
|
|
69
|
-
* its subtree (not counting the value itself). A nested `@context` can
|
|
70
|
-
* introduce a local term-definition scope that redefines `as:` or `Public`
|
|
71
|
-
* even when the top-level `@context` is safe, so the fast path must defer
|
|
72
|
-
* to the URDNA2015 equivalence check whenever one is present.
|
|
73
|
-
*/
|
|
74
|
-
function hasNestedContext(value, depth = 0) {
|
|
75
|
-
if (depth >= MAX_TRAVERSAL_DEPTH) return true;
|
|
76
|
-
if (Array.isArray(value)) return value.some((item) => hasNestedContext(item, depth + 1));
|
|
77
|
-
if (typeof value !== "object" || value == null) return false;
|
|
78
|
-
const record = value;
|
|
79
|
-
for (const key of Object.keys(record)) {
|
|
80
|
-
if (key === "@context") return true;
|
|
81
|
-
if (hasNestedContext(record[key], depth + 1)) return true;
|
|
82
|
-
}
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Checks whether the `@context` of a JSON-LD document is guaranteed not
|
|
87
|
-
* to redefine the `as:` prefix or the bare `Public` term. Only documents
|
|
88
|
-
* whose `@context` is a string, or an array of strings, drawn from Fedify's
|
|
89
|
-
* preloaded context set AND including the ActivityStreams URL qualify,
|
|
90
|
-
* AND no nested subtree carries its own `@context` that might redefine
|
|
91
|
-
* those terms within a local scope. When all of that holds the rewrite
|
|
92
|
-
* is provably semantics-preserving and the URDNA2015 equivalence check
|
|
93
|
-
* can be skipped. Any other shape (unknown external URLs, inline
|
|
94
|
-
* objects at the top level, nested `@context` blocks) is treated as
|
|
95
|
-
* potentially unsafe.
|
|
96
|
-
*/
|
|
97
|
-
function hasKnownSafeContext(jsonLd) {
|
|
98
|
-
if (typeof jsonLd !== "object" || jsonLd == null) return false;
|
|
99
|
-
const record = jsonLd;
|
|
100
|
-
if (!Object.hasOwn(record, "@context")) return false;
|
|
101
|
-
const ctx = record["@context"];
|
|
102
|
-
const entries = typeof ctx === "string" ? [ctx] : Array.isArray(ctx) ? ctx : null;
|
|
103
|
-
if (entries == null || entries.length === 0) return false;
|
|
104
|
-
let hasAs = false;
|
|
105
|
-
for (const entry of entries) {
|
|
106
|
-
if (typeof entry !== "string") return false;
|
|
107
|
-
if (!KNOWN_SAFE_CONTEXT_URLS.has(entry)) return false;
|
|
108
|
-
if (entry === AS_CONTEXT_URL) hasAs = true;
|
|
109
|
-
}
|
|
110
|
-
if (!hasAs) return false;
|
|
111
|
-
for (const key of Object.keys(record)) {
|
|
112
|
-
if (key === "@context") continue;
|
|
113
|
-
if (hasNestedContext(record[key])) return false;
|
|
114
|
-
}
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Rewrites the compact `as:Public` / `Public` CURIE appearing in activity
|
|
119
|
-
* addressing fields (`to`, `cc`, `bto`, `bcc`, `audience`) to the fully
|
|
120
|
-
* expanded `https://www.w3.org/ns/activitystreams#Public` URI.
|
|
121
|
-
*
|
|
122
|
-
* Several ActivityPub implementations, Lemmy among them, match these
|
|
123
|
-
* fields as plain URLs without running JSON-LD expansion, and silently
|
|
124
|
-
* drop activities whose public addressing appears in CURIE form. This
|
|
125
|
-
* helper works around that gap.
|
|
126
|
-
*
|
|
127
|
-
* For documents whose `@context` is drawn entirely from Fedify's
|
|
128
|
-
* preloaded context set and includes the ActivityStreams URL, the
|
|
129
|
-
* rewrite is applied directly: the content of every preloaded non-AS
|
|
130
|
-
* context is known not to redefine the `as:` prefix or the bare `Public`
|
|
131
|
-
* term, so the semantics are preserved by construction. Any other
|
|
132
|
-
* shape (an inline object, an unknown external URL, and so on) is
|
|
133
|
-
* treated as potentially unsafe and gated on a JSON-LD equivalence
|
|
134
|
-
* check; both forms are canonicalized with URDNA2015 and the resulting
|
|
135
|
-
* N-Quads are compared. When they differ, the original document is
|
|
136
|
-
* returned unchanged. Canonicalization failures also fall back to the
|
|
137
|
-
* original document.
|
|
138
|
-
*
|
|
139
|
-
* When no `contextLoader` is supplied the helper falls back to an
|
|
140
|
-
* internal loader that resolves only the URLs in Fedify's
|
|
141
|
-
* preloaded-contexts set and rejects every other URL without issuing a
|
|
142
|
-
* network request. That behaviour is deliberately narrower than
|
|
143
|
-
* `@fedify/vocab-runtime`'s `getDocumentLoader()`, which after its
|
|
144
|
-
* `validatePublicUrl` check will happily fetch non-preloaded URLs: the
|
|
145
|
-
* helper is reached from verification paths (`verifyProof()` /
|
|
146
|
-
* `verifyObject()`) that operate on inbound, potentially adversarial
|
|
147
|
-
* JSON-LD, and a default loader that fetches attacker-supplied
|
|
148
|
-
* `@context` URLs on the caller's behalf would be an SSRF vector.
|
|
149
|
-
* Canonicalization failures against the restricted loader fall back to
|
|
150
|
-
* the original document, same as any other canonicalization error.
|
|
151
|
-
* Callers that genuinely need the remote-fetch loader (for example
|
|
152
|
-
* applications that sign local JSON-LD against a custom vocabulary)
|
|
153
|
-
* should pass a `contextLoader` explicitly.
|
|
154
|
-
*
|
|
155
|
-
* Must be called before any signing step that canonicalizes the
|
|
156
|
-
* compact form byte-for-byte (for example, Object Integrity Proofs
|
|
157
|
-
* using the `eddsa-jcs-2022` cryptosuite), so the signed payload
|
|
158
|
-
* matches what is sent on the wire.
|
|
159
|
-
*/
|
|
160
|
-
async function normalizePublicAudience(jsonLd, contextLoader) {
|
|
161
|
-
if (!hasPublicCurieInAddressing(jsonLd)) return jsonLd;
|
|
162
|
-
const normalized = rewritePublicAudience(jsonLd);
|
|
163
|
-
if (hasKnownSafeContext(jsonLd)) return normalized;
|
|
164
|
-
const loader = contextLoader ?? preloadedOnlyDocumentLoader;
|
|
165
|
-
try {
|
|
166
|
-
const [before, after] = await Promise.all([jsonld.canonize(jsonLd, {
|
|
167
|
-
format: "application/n-quads",
|
|
168
|
-
documentLoader: loader
|
|
169
|
-
}), jsonld.canonize(normalized, {
|
|
170
|
-
format: "application/n-quads",
|
|
171
|
-
documentLoader: loader
|
|
172
|
-
})]);
|
|
173
|
-
if (before === after) return normalized;
|
|
174
|
-
logger.warn("Expanding the public audience CURIE to its full URI would change the canonical form of the activity; sending the activity as is. This usually means the active JSON-LD context redefines the `as:` prefix or the bare `Public` term.");
|
|
175
|
-
} catch (error) {
|
|
176
|
-
logger.debug("Failed to verify public audience normalization equivalence via JSON-LD canonicalization; sending the activity as is.\n{error}", { error });
|
|
177
|
-
}
|
|
178
|
-
return jsonLd;
|
|
179
|
-
}
|
|
180
|
-
//#endregion
|
|
181
|
-
export { normalizePublicAudience as t };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|