@fedify/fedify 2.3.6 → 2.3.8
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/{assert_instance_of-DBC5X09g.mjs → assert-jSdZMYam.mjs} +19 -1
- package/dist/{builder-CW-9AJCO.mjs → builder-CDForRSL.mjs} +3 -3
- package/dist/{client-D1KuWxjH.mjs → client-DYDoDpMa.mjs} +78 -4
- package/dist/compat/mod.d.cts +1 -1
- package/dist/compat/mod.d.ts +1 -1
- package/dist/compat/outgoing-jsonld.test.mjs +1 -1
- package/dist/compat/public-audience.test.mjs +1 -1
- package/dist/compat/transformers.test.mjs +3 -4
- package/dist/{context-DVoTs_wM.mjs → context-BepjCFHN.mjs} +1 -0
- package/dist/{context-BxVVO5Ro.d.ts → context-CAKnQy1x.d.ts} +4 -3
- package/dist/{context-BpmLyiPx.d.cts → context-CSIggG9_.d.cts} +4 -3
- package/dist/{deno-KC-uf6Un.mjs → deno--DCBC7WG.mjs} +1 -1
- package/dist/{docloader-BHS1yt22.mjs → docloader-BAdp-ZeK.mjs} +2 -2
- package/dist/federation/builder.test.mjs +2 -2
- package/dist/federation/circuit-breaker.test.mjs +3 -3
- package/dist/federation/collection.test.mjs +1 -1
- package/dist/federation/handler.test.mjs +128 -11
- package/dist/federation/idempotency.test.mjs +4 -4
- package/dist/federation/inbox.test.mjs +1 -1
- package/dist/federation/keycache.test.mjs +44 -10
- package/dist/federation/kv.test.mjs +1 -1
- package/dist/federation/metrics.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +109 -19
- package/dist/federation/mod.cjs +1 -1
- package/dist/federation/mod.d.cts +2 -2
- package/dist/federation/mod.d.ts +2 -2
- package/dist/federation/mod.js +1 -1
- package/dist/federation/mq.test.mjs +1 -1
- package/dist/federation/negotiation.test.mjs +2 -2
- package/dist/federation/retry.test.mjs +1 -1
- package/dist/federation/router.test.mjs +1 -1
- package/dist/federation/send.test.mjs +141 -7
- package/dist/federation/temporal.test.mjs +2 -2
- package/dist/federation/webfinger.test.mjs +3 -3
- package/dist/{http-DzgaVy-x.js → http-BKJYj9oz.js} +155 -7
- package/dist/{http-DL5ZJBC4.cjs → http-ChVf88XZ.cjs} +166 -6
- package/dist/{http-BcbYkefs.mjs → http-ClEDLGpr.mjs} +4 -4
- package/dist/{http-lf8Hsd91.d.ts → http-DQmNpfym.d.ts} +1 -1
- package/dist/{http-VyDTd4G3.d.cts → http-DiWQB8Mr.d.cts} +1 -1
- package/dist/{key-Cbkqgt-G.mjs → key-C-7sqo8D.mjs} +155 -7
- package/dist/{keycache-BeU0LCII.mjs → keycache-B3qRQNLj.mjs} +12 -4
- package/dist/{kv-cache-CT228f7w.mjs → kv-cache-C5FK4PLG.mjs} +1 -1
- package/dist/{kv-cache-BWNRhap7.js → kv-cache-C_w70bFh.js} +2 -2
- package/dist/{kv-cache-Dw94l8rT.cjs → kv-cache-DFBOAyNj.cjs} +2 -2
- package/dist/{ld-c-9mCB36.mjs → ld-CtFHB6rU.mjs} +3 -3
- package/dist/{metrics-D8s1eKfJ.mjs → metrics-FDcYXRP5.mjs} +1 -1
- package/dist/{middleware-B29rR42K.cjs → middleware-BdDtzhXb.cjs} +101 -25
- package/dist/{middleware-3L9f9ZTw.mjs → middleware-COzI8bCL.mjs} +41 -30
- package/dist/{middleware-D_cNQ7Yq.js → middleware-DunPXFJL.js} +101 -25
- package/dist/{middleware-Be2z0t5f.mjs → middleware-K7mJeIgT.mjs} +1 -1
- package/dist/{mod-yvIXFAEi.d.cts → mod-1TuoXkGs.d.cts} +1 -1
- package/dist/{mod-B0hW12_O.d.cts → mod-Bid79LFU.d.cts} +1 -1
- package/dist/{mod-Rpy4Uwkk.d.ts → mod-CFuyfw3c.d.ts} +1 -1
- package/dist/{mod-DFvNJcNb.d.ts → mod-DHgc4ygG.d.ts} +1 -1
- package/dist/{mod-CjERT09F.d.cts → mod-PVR75MeU.d.cts} +1 -1
- package/dist/{mod-COIAjwRS.d.ts → mod-TLEvgT1i.d.ts} +1 -1
- package/dist/mod.cjs +5 -5
- package/dist/mod.d.cts +6 -6
- package/dist/mod.d.ts +6 -6
- package/dist/mod.js +5 -5
- package/dist/nodeinfo/client.test.mjs +28 -1
- package/dist/nodeinfo/handler.test.mjs +3 -3
- package/dist/nodeinfo/mod.cjs +1 -1
- package/dist/nodeinfo/mod.js +1 -1
- package/dist/nodeinfo/types.test.mjs +1 -1
- package/dist/otel/exporter.test.mjs +1 -1
- package/dist/{outgoing-jsonld-OFoubetZ.mjs → outgoing-jsonld-HOAywiid.mjs} +1 -1
- package/dist/{owner-CnngXDNJ.d.ts → owner-B3hNQCG8.d.cts} +12 -1
- package/dist/owner-CGuS9lE7.mjs +175 -0
- package/dist/{owner-DEvZuyOE.d.cts → owner-CiBPcC6F.d.ts} +12 -1
- package/dist/{proof-D_6qtBdQ.mjs → proof--56drUyt.mjs} +5 -5
- package/dist/{proof-DGlDXtcc.cjs → proof-Dgozne0w.cjs} +112 -58
- package/dist/{proof-CrtfGSi7.js → proof-tjbzynMa.js} +112 -58
- package/dist/{send-i63Det4Y.mjs → send-CC1A7ATC.mjs} +68 -11
- package/dist/sig/accept.test.mjs +1 -1
- package/dist/sig/http.test.mjs +4 -4
- package/dist/sig/key.test.mjs +170 -3
- package/dist/sig/ld.test.mjs +56 -4
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.d.cts +3 -3
- package/dist/sig/mod.d.ts +3 -3
- package/dist/sig/mod.js +2 -2
- package/dist/sig/owner.test.mjs +105 -6
- package/dist/sig/proof.test.mjs +73 -5
- package/dist/{temporal-CcVjTX30.mjs → temporal-DvptXZ7V.mjs} +1 -1
- package/dist/testing/mod.mjs +1 -1
- package/dist/{types-m8u9L86X.cjs → types-DWs-qZaY.cjs} +94 -2
- package/dist/{types-DTONwNqL.js → types-sXITXcWa.js} +78 -4
- package/dist/utils/docloader.test.mjs +28 -4
- package/dist/utils/kv-cache.test.mjs +1 -1
- package/dist/utils/mod.cjs +1 -1
- package/dist/utils/mod.d.cts +1 -1
- package/dist/utils/mod.d.ts +1 -1
- package/dist/utils/mod.js +1 -1
- package/package.json +7 -7
- package/dist/assert-OguE97r2.mjs +0 -23
- package/dist/owner-CjkdUXE3.mjs +0 -120
- /package/dist/{accept-CPkZzmGN.mjs → accept-Dd__NiUL.mjs} +0 -0
- /package/dist/{activity-listener-tztVvlNb.mjs → activity-listener-ell7W1s9.mjs} +0 -0
- /package/dist/{circuit-breaker-D1fxthDI.mjs → circuit-breaker-CDABzqVf.mjs} +0 -0
- /package/dist/{circuit-breaker-test-utils-CAdwjgMi.mjs → circuit-breaker-test-utils-Dm5MM6l9.mjs} +0 -0
- /package/dist/{collection-Cc3DVAhE.mjs → collection-CA3V5zyK.mjs} +0 -0
- /package/dist/{keys-DGu1NFwu.mjs → keys-BAK-tUlf.mjs} +0 -0
- /package/dist/{kv-rV3vodCc.mjs → kv-CX8qfaad.mjs} +0 -0
- /package/dist/{negotiation-DDstyBvc.mjs → negotiation-CDW-_gUU.mjs} +0 -0
- /package/dist/{public-audience-DZJAUUi8.mjs → public-audience-jwoSIGUw.mjs} +0 -0
- /package/dist/{retry-CXg_MBI-.mjs → retry-_VvV0h9f.mjs} +0 -0
- /package/dist/{types-J53Kw7so.mjs → types-s4mCTGkT.mjs} +0 -0
package/dist/sig/ld.test.mjs
CHANGED
|
@@ -3,11 +3,11 @@ import "urlpattern-polyfill";
|
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
4
|
import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
|
|
5
5
|
import { n as assertGreaterOrEqual, r as assertFalse, t as assertRejects } from "../assert_rejects-DN60FHPX.mjs";
|
|
6
|
+
import { n as assertInstanceOf, t as assert } from "../assert-jSdZMYam.mjs";
|
|
6
7
|
import { t as assertThrows } from "../assert_throws-BOkhLGYc.mjs";
|
|
7
|
-
import {
|
|
8
|
-
import { i as
|
|
9
|
-
import { a as
|
|
10
|
-
import { a as compactJsonLd, f as isInvalidUrlTypeError, g as verifySignature, h as verifyJsonLd, i as attachSignature, n as UnsafeJsonLdError, o as createSignature, p as signJsonLd, s as detachSignature, u as hasSignatureLike } from "../ld-c-9mCB36.mjs";
|
|
8
|
+
import { a as generateCryptoKeyPair } from "../key-C-7sqo8D.mjs";
|
|
9
|
+
import { a as rsaPrivateKey3, c as rsaPublicKey3, i as rsaPrivateKey2, n as ed25519PrivateKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-BAK-tUlf.mjs";
|
|
10
|
+
import { a as compactJsonLd, f as isInvalidUrlTypeError, g as verifySignature, h as verifyJsonLd, i as attachSignature, n as UnsafeJsonLdError, o as createSignature, p as signJsonLd, s as detachSignature, u as hasSignatureLike } from "../ld-CtFHB6rU.mjs";
|
|
11
11
|
import { CryptographicKey } from "@fedify/vocab";
|
|
12
12
|
import { createTestMeterProvider, mockDocumentLoader, test } from "@fedify/fixture";
|
|
13
13
|
import { encodeBase64 } from "byte-encodings/base64";
|
|
@@ -938,5 +938,57 @@ test("compactJsonLd() rejects inputs that compact into @graph wrappers", async (
|
|
|
938
938
|
content: "two"
|
|
939
939
|
}], mockDocumentLoader), UnsafeJsonLdError, "Unsupported JSON-LD keyword: @graph.");
|
|
940
940
|
});
|
|
941
|
+
test("verifyJsonLd() rejects a key that claims a forged owner", async () => {
|
|
942
|
+
const keyId = new URL("https://attacker.example/key");
|
|
943
|
+
const impersonated = "https://example.com/person";
|
|
944
|
+
const { publicKeyPem } = await rsaPublicKey2.toJsonLd({ contextLoader: mockDocumentLoader });
|
|
945
|
+
const signed = await signJsonLd({
|
|
946
|
+
"@context": "https://www.w3.org/ns/activitystreams",
|
|
947
|
+
id: "https://attacker.example/activities/1",
|
|
948
|
+
type: "Create",
|
|
949
|
+
actor: impersonated
|
|
950
|
+
}, rsaPrivateKey2, keyId, { contextLoader: mockDocumentLoader });
|
|
951
|
+
const serveKeyOwnedBy = (owner) => (resource) => {
|
|
952
|
+
if (resource === keyId.href) return Promise.resolve({
|
|
953
|
+
contextUrl: null,
|
|
954
|
+
documentUrl: resource,
|
|
955
|
+
document: {
|
|
956
|
+
"@context": "https://w3id.org/security/v1",
|
|
957
|
+
id: keyId.href,
|
|
958
|
+
type: "CryptographicKey",
|
|
959
|
+
owner,
|
|
960
|
+
publicKeyPem
|
|
961
|
+
}
|
|
962
|
+
});
|
|
963
|
+
if (resource === "https://attacker.example/actor") return Promise.resolve({
|
|
964
|
+
contextUrl: null,
|
|
965
|
+
documentUrl: resource,
|
|
966
|
+
document: {
|
|
967
|
+
"@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"],
|
|
968
|
+
id: resource,
|
|
969
|
+
type: "Person",
|
|
970
|
+
publicKey: [keyId.href]
|
|
971
|
+
}
|
|
972
|
+
});
|
|
973
|
+
return mockDocumentLoader(resource);
|
|
974
|
+
};
|
|
975
|
+
assertEquals(await verifySignature(signed, {
|
|
976
|
+
documentLoader: serveKeyOwnedBy(impersonated),
|
|
977
|
+
contextLoader: mockDocumentLoader
|
|
978
|
+
}), null);
|
|
979
|
+
assertFalse(await verifyJsonLd(signed, {
|
|
980
|
+
documentLoader: serveKeyOwnedBy(impersonated),
|
|
981
|
+
contextLoader: mockDocumentLoader
|
|
982
|
+
}));
|
|
983
|
+
const honestLoader = serveKeyOwnedBy("https://attacker.example/actor");
|
|
984
|
+
assertInstanceOf(await verifySignature(signed, {
|
|
985
|
+
documentLoader: honestLoader,
|
|
986
|
+
contextLoader: mockDocumentLoader
|
|
987
|
+
}), CryptographicKey);
|
|
988
|
+
assertFalse(await verifyJsonLd(signed, {
|
|
989
|
+
documentLoader: honestLoader,
|
|
990
|
+
contextLoader: mockDocumentLoader
|
|
991
|
+
}));
|
|
992
|
+
});
|
|
941
993
|
//#endregion
|
|
942
994
|
export {};
|
package/dist/sig/mod.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const { Temporal } = require("@js-temporal/polyfill");
|
|
2
2
|
const { URLPattern } = require("urlpattern-polyfill");
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
-
const require_http = require("../http-
|
|
5
|
-
const require_proof = require("../proof-
|
|
4
|
+
const require_http = require("../http-ChVf88XZ.cjs");
|
|
5
|
+
const require_proof = require("../proof-Dgozne0w.cjs");
|
|
6
6
|
exports.attachSignature = require_proof.attachSignature;
|
|
7
7
|
exports.createProof = require_proof.createProof;
|
|
8
8
|
exports.createSignature = require_proof.createSignature;
|
package/dist/sig/mod.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
|
-
import { C as exportJwk, D as importJwk, E as generateCryptoKeyPair, S as KeyCache, T as fetchKeyDetailed, _ as validateAcceptSignature, a as VerifyRequestDetailedResult, b as FetchKeyOptions, c as signRequest, d as AcceptSignatureMember, f as AcceptSignatureParameters, g as parseAcceptSignature, h as fulfillAcceptSignature, i as SignRequestOptions, l as verifyRequest, m as formatAcceptSignature, n as HttpMessageSignaturesSpecDeterminer, o as VerifyRequestFailureReason, p as FulfillAcceptSignatureResult, r as Rfc9421SignRequestOptions, s as VerifyRequestOptions, t as HttpMessageSignaturesSpec, u as verifyRequestDetailed, v as FetchKeyDetailedResult, w as fetchKey, x as FetchKeyResult, y as FetchKeyErrorResult } from "../http-
|
|
3
|
-
import { i as getKeyOwner, n as GetKeyOwnerOptions, r as doesActorOwnKey, t as DoesActorOwnKeyOptions } from "../owner-
|
|
4
|
-
import { _ as hasSignatureLike, a as createProof, b as verifySignature, c as verifyObject, d as SignJsonLdOptions, f as VerifyJsonLdOptions, g as detachSignature, h as createSignature, i as VerifyProofOptions, l as verifyProof, m as attachSignature, n as SignObjectOptions, o as hasProofLike, p as VerifySignatureOptions, r as VerifyObjectOptions, s as signObject, t as CreateProofOptions, u as CreateSignatureOptions, v as signJsonLd, y as verifyJsonLd } from "../mod-
|
|
2
|
+
import { C as exportJwk, D as importJwk, E as generateCryptoKeyPair, S as KeyCache, T as fetchKeyDetailed, _ as validateAcceptSignature, a as VerifyRequestDetailedResult, b as FetchKeyOptions, c as signRequest, d as AcceptSignatureMember, f as AcceptSignatureParameters, g as parseAcceptSignature, h as fulfillAcceptSignature, i as SignRequestOptions, l as verifyRequest, m as formatAcceptSignature, n as HttpMessageSignaturesSpecDeterminer, o as VerifyRequestFailureReason, p as FulfillAcceptSignatureResult, r as Rfc9421SignRequestOptions, s as VerifyRequestOptions, t as HttpMessageSignaturesSpec, u as verifyRequestDetailed, v as FetchKeyDetailedResult, w as fetchKey, x as FetchKeyResult, y as FetchKeyErrorResult } from "../http-DiWQB8Mr.cjs";
|
|
3
|
+
import { i as getKeyOwner, n as GetKeyOwnerOptions, r as doesActorOwnKey, t as DoesActorOwnKeyOptions } from "../owner-B3hNQCG8.cjs";
|
|
4
|
+
import { _ as hasSignatureLike, a as createProof, b as verifySignature, c as verifyObject, d as SignJsonLdOptions, f as VerifyJsonLdOptions, g as detachSignature, h as createSignature, i as VerifyProofOptions, l as verifyProof, m as attachSignature, n as SignObjectOptions, o as hasProofLike, p as VerifySignatureOptions, r as VerifyObjectOptions, s as signObject, t as CreateProofOptions, u as CreateSignatureOptions, v as signJsonLd, y as verifyJsonLd } from "../mod-Bid79LFU.cjs";
|
|
5
5
|
export { AcceptSignatureMember, AcceptSignatureParameters, CreateProofOptions, CreateSignatureOptions, DoesActorOwnKeyOptions, FetchKeyDetailedResult, FetchKeyErrorResult, FetchKeyOptions, FetchKeyResult, FulfillAcceptSignatureResult, GetKeyOwnerOptions, HttpMessageSignaturesSpec, HttpMessageSignaturesSpecDeterminer, KeyCache, Rfc9421SignRequestOptions, SignJsonLdOptions, SignObjectOptions, SignRequestOptions, VerifyJsonLdOptions, VerifyObjectOptions, VerifyProofOptions, VerifyRequestDetailedResult, VerifyRequestFailureReason, VerifyRequestOptions, VerifySignatureOptions, attachSignature, createProof, createSignature, detachSignature, doesActorOwnKey, exportJwk, fetchKey, fetchKeyDetailed, formatAcceptSignature, fulfillAcceptSignature, generateCryptoKeyPair, getKeyOwner, hasProofLike, hasSignatureLike, importJwk, parseAcceptSignature, signJsonLd, signObject, signRequest, validateAcceptSignature, verifyJsonLd, verifyObject, verifyProof, verifyRequest, verifyRequestDetailed, verifySignature };
|
package/dist/sig/mod.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
|
-
import { C as exportJwk, D as importJwk, E as generateCryptoKeyPair, S as KeyCache, T as fetchKeyDetailed, _ as validateAcceptSignature, a as VerifyRequestDetailedResult, b as FetchKeyOptions, c as signRequest, d as AcceptSignatureMember, f as AcceptSignatureParameters, g as parseAcceptSignature, h as fulfillAcceptSignature, i as SignRequestOptions, l as verifyRequest, m as formatAcceptSignature, n as HttpMessageSignaturesSpecDeterminer, o as VerifyRequestFailureReason, p as FulfillAcceptSignatureResult, r as Rfc9421SignRequestOptions, s as VerifyRequestOptions, t as HttpMessageSignaturesSpec, u as verifyRequestDetailed, v as FetchKeyDetailedResult, w as fetchKey, x as FetchKeyResult, y as FetchKeyErrorResult } from "../http-
|
|
3
|
-
import { i as getKeyOwner, n as GetKeyOwnerOptions, r as doesActorOwnKey, t as DoesActorOwnKeyOptions } from "../owner-
|
|
4
|
-
import { _ as hasSignatureLike, a as createProof, b as verifySignature, c as verifyObject, d as SignJsonLdOptions, f as VerifyJsonLdOptions, g as detachSignature, h as createSignature, i as VerifyProofOptions, l as verifyProof, m as attachSignature, n as SignObjectOptions, o as hasProofLike, p as VerifySignatureOptions, r as VerifyObjectOptions, s as signObject, t as CreateProofOptions, u as CreateSignatureOptions, v as signJsonLd, y as verifyJsonLd } from "../mod-
|
|
2
|
+
import { C as exportJwk, D as importJwk, E as generateCryptoKeyPair, S as KeyCache, T as fetchKeyDetailed, _ as validateAcceptSignature, a as VerifyRequestDetailedResult, b as FetchKeyOptions, c as signRequest, d as AcceptSignatureMember, f as AcceptSignatureParameters, g as parseAcceptSignature, h as fulfillAcceptSignature, i as SignRequestOptions, l as verifyRequest, m as formatAcceptSignature, n as HttpMessageSignaturesSpecDeterminer, o as VerifyRequestFailureReason, p as FulfillAcceptSignatureResult, r as Rfc9421SignRequestOptions, s as VerifyRequestOptions, t as HttpMessageSignaturesSpec, u as verifyRequestDetailed, v as FetchKeyDetailedResult, w as fetchKey, x as FetchKeyResult, y as FetchKeyErrorResult } from "../http-DQmNpfym.js";
|
|
3
|
+
import { i as getKeyOwner, n as GetKeyOwnerOptions, r as doesActorOwnKey, t as DoesActorOwnKeyOptions } from "../owner-CiBPcC6F.js";
|
|
4
|
+
import { _ as hasSignatureLike, a as createProof, b as verifySignature, c as verifyObject, d as SignJsonLdOptions, f as VerifyJsonLdOptions, g as detachSignature, h as createSignature, i as VerifyProofOptions, l as verifyProof, m as attachSignature, n as SignObjectOptions, o as hasProofLike, p as VerifySignatureOptions, r as VerifyObjectOptions, s as signObject, t as CreateProofOptions, u as CreateSignatureOptions, v as signJsonLd, y as verifyJsonLd } from "../mod-TLEvgT1i.js";
|
|
5
5
|
export { AcceptSignatureMember, AcceptSignatureParameters, CreateProofOptions, CreateSignatureOptions, DoesActorOwnKeyOptions, FetchKeyDetailedResult, FetchKeyErrorResult, FetchKeyOptions, FetchKeyResult, FulfillAcceptSignatureResult, GetKeyOwnerOptions, HttpMessageSignaturesSpec, HttpMessageSignaturesSpecDeterminer, KeyCache, Rfc9421SignRequestOptions, SignJsonLdOptions, SignObjectOptions, SignRequestOptions, VerifyJsonLdOptions, VerifyObjectOptions, VerifyProofOptions, VerifyRequestDetailedResult, VerifyRequestFailureReason, VerifyRequestOptions, VerifySignatureOptions, attachSignature, createProof, createSignature, detachSignature, doesActorOwnKey, exportJwk, fetchKey, fetchKeyDetailed, formatAcceptSignature, fulfillAcceptSignature, generateCryptoKeyPair, getKeyOwner, hasProofLike, hasSignatureLike, importJwk, parseAcceptSignature, signJsonLd, signObject, signRequest, validateAcceptSignature, verifyJsonLd, verifyObject, verifyProof, verifyRequest, verifyRequestDetailed, verifySignature };
|
package/dist/sig/mod.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import { URLPattern } from "urlpattern-polyfill";
|
|
3
|
-
import {
|
|
4
|
-
import { C as verifySignature, S as verifyJsonLd, _ as hasSignatureLike, a as verifyProof, b as signJsonLd, c as getKeyOwner, d as attachSignature, i as verifyObject, m as detachSignature, n as hasProofLike, p as createSignature, r as signObject, s as doesActorOwnKey, t as createProof } from "../proof-
|
|
3
|
+
import { F as validateAcceptSignature, M as formatAcceptSignature, N as fulfillAcceptSignature, P as parseAcceptSignature, a as verifyRequestDetailed, c as fetchKey, d as importJwk, i as verifyRequest, l as fetchKeyDetailed, o as exportJwk, r as signRequest, u as generateCryptoKeyPair } from "../http-BKJYj9oz.js";
|
|
4
|
+
import { C as verifySignature, S as verifyJsonLd, _ as hasSignatureLike, a as verifyProof, b as signJsonLd, c as getKeyOwner, d as attachSignature, i as verifyObject, m as detachSignature, n as hasProofLike, p as createSignature, r as signObject, s as doesActorOwnKey, t as createProof } from "../proof-tjbzynMa.js";
|
|
5
5
|
export { attachSignature, createProof, createSignature, detachSignature, doesActorOwnKey, exportJwk, fetchKey, fetchKeyDetailed, formatAcceptSignature, fulfillAcceptSignature, generateCryptoKeyPair, getKeyOwner, hasProofLike, hasSignatureLike, importJwk, parseAcceptSignature, signJsonLd, signObject, signRequest, validateAcceptSignature, verifyJsonLd, verifyObject, verifyProof, verifyRequest, verifyRequestDetailed, verifySignature };
|
package/dist/sig/owner.test.mjs
CHANGED
|
@@ -4,9 +4,9 @@ globalThis.addEventListener = () => {};
|
|
|
4
4
|
import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
|
|
5
5
|
import "../std__assert-BBjXFNOb.mjs";
|
|
6
6
|
import { r as assertFalse } from "../assert_rejects-DN60FHPX.mjs";
|
|
7
|
-
import { t as assert } from "../assert-
|
|
8
|
-
import { o as rsaPublicKey1, s as rsaPublicKey2 } from "../keys-
|
|
9
|
-
import { n as getKeyOwner, t as doesActorOwnKey } from "../owner-
|
|
7
|
+
import { t as assert } from "../assert-jSdZMYam.mjs";
|
|
8
|
+
import { o as rsaPublicKey1, s as rsaPublicKey2 } from "../keys-BAK-tUlf.mjs";
|
|
9
|
+
import { n as getKeyOwner, t as doesActorOwnKey } from "../owner-CGuS9lE7.mjs";
|
|
10
10
|
import { Create, CryptographicKey, lookupObject } from "@fedify/vocab";
|
|
11
11
|
import { createTestTracerProvider, mockDocumentLoader, test } from "@fedify/fixture";
|
|
12
12
|
//#region src/sig/owner.test.ts
|
|
@@ -40,7 +40,7 @@ test("doesActorOwnKey() records OpenTelemetry span", async () => {
|
|
|
40
40
|
id: new URL("https://example.com/activity"),
|
|
41
41
|
actor: new URL("https://example.com/person")
|
|
42
42
|
}), new CryptographicKey({
|
|
43
|
-
id: new URL("https://example.com/
|
|
43
|
+
id: new URL("https://example.com/key"),
|
|
44
44
|
owner: new URL("https://example.com/person")
|
|
45
45
|
}), {
|
|
46
46
|
documentLoader: mockDocumentLoader,
|
|
@@ -50,9 +50,108 @@ test("doesActorOwnKey() records OpenTelemetry span", async () => {
|
|
|
50
50
|
assertEquals(spans.length, 1);
|
|
51
51
|
const span = spans[0];
|
|
52
52
|
assertEquals(span.attributes["activitypub.actor.id"], "https://example.com/person");
|
|
53
|
-
assertEquals(span.attributes["activitypub.key.id"], "https://example.com/
|
|
53
|
+
assertEquals(span.attributes["activitypub.key.id"], "https://example.com/key");
|
|
54
54
|
assertEquals(span.attributes["activitypub.key_ownership.verified"], true);
|
|
55
|
-
assertEquals(span.attributes["activitypub.key_ownership.method"], "
|
|
55
|
+
assertEquals(span.attributes["activitypub.key_ownership.method"], "key_owner");
|
|
56
|
+
});
|
|
57
|
+
test("doesActorOwnKey() rejects a key that only claims to be owned", async () => {
|
|
58
|
+
const options = {
|
|
59
|
+
documentLoader: mockDocumentLoader,
|
|
60
|
+
contextLoader: mockDocumentLoader
|
|
61
|
+
};
|
|
62
|
+
assertFalse(await doesActorOwnKey(new Create({ actor: new URL("https://example.com/person") }), new CryptographicKey({
|
|
63
|
+
id: new URL("https://attacker.example/key"),
|
|
64
|
+
owner: new URL("https://example.com/person")
|
|
65
|
+
}), options));
|
|
66
|
+
const unresolvable = new URL("https://impersonated.invalid/users/victim");
|
|
67
|
+
assertFalse(await doesActorOwnKey(new Create({ actor: unresolvable }), new CryptographicKey({
|
|
68
|
+
id: new URL("https://attacker.example/key"),
|
|
69
|
+
owner: unresolvable
|
|
70
|
+
}), options));
|
|
71
|
+
});
|
|
72
|
+
test("doesActorOwnKey() ignores an actor embedded in the activity", async () => {
|
|
73
|
+
const { publicKeyPem } = await rsaPublicKey1.toJsonLd({ contextLoader: mockDocumentLoader });
|
|
74
|
+
const activity = await Create.fromJsonLd({
|
|
75
|
+
"@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"],
|
|
76
|
+
id: "https://example.com/activity",
|
|
77
|
+
type: "Create",
|
|
78
|
+
actor: {
|
|
79
|
+
id: "https://example.com/person",
|
|
80
|
+
type: "Person",
|
|
81
|
+
publicKey: {
|
|
82
|
+
id: "https://attacker.example/key",
|
|
83
|
+
type: "CryptographicKey",
|
|
84
|
+
owner: "https://example.com/person",
|
|
85
|
+
publicKeyPem
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}, {
|
|
89
|
+
documentLoader: mockDocumentLoader,
|
|
90
|
+
contextLoader: mockDocumentLoader
|
|
91
|
+
});
|
|
92
|
+
assertEquals(activity.actorId, new URL("https://example.com/person"));
|
|
93
|
+
assertFalse(await doesActorOwnKey(activity, new CryptographicKey({ id: new URL("https://attacker.example/key") }), {
|
|
94
|
+
documentLoader: mockDocumentLoader,
|
|
95
|
+
contextLoader: mockDocumentLoader
|
|
96
|
+
}));
|
|
97
|
+
});
|
|
98
|
+
test("getKeyOwner() rejects an actor document from another origin", async () => {
|
|
99
|
+
const keyId = "https://attacker.example/key";
|
|
100
|
+
const { publicKeyPem } = await rsaPublicKey1.toJsonLd({ contextLoader: mockDocumentLoader });
|
|
101
|
+
const options = {
|
|
102
|
+
documentLoader(resource) {
|
|
103
|
+
if (resource === keyId) return Promise.resolve({
|
|
104
|
+
contextUrl: null,
|
|
105
|
+
documentUrl: resource,
|
|
106
|
+
document: {
|
|
107
|
+
"@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"],
|
|
108
|
+
id: "https://example.com/person",
|
|
109
|
+
type: "Person",
|
|
110
|
+
publicKey: [{
|
|
111
|
+
id: keyId,
|
|
112
|
+
type: "CryptographicKey",
|
|
113
|
+
publicKeyPem
|
|
114
|
+
}]
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
return mockDocumentLoader(resource);
|
|
118
|
+
},
|
|
119
|
+
contextLoader: mockDocumentLoader
|
|
120
|
+
};
|
|
121
|
+
assertEquals(await getKeyOwner(new URL(keyId), options), null);
|
|
122
|
+
});
|
|
123
|
+
test("doesActorOwnKey() matches a key that leaves its id implicit", async () => {
|
|
124
|
+
const actorId = "https://example.com/implicit-key-actor";
|
|
125
|
+
const { publicKeyPem } = await rsaPublicKey1.toJsonLd({ contextLoader: mockDocumentLoader });
|
|
126
|
+
const options = {
|
|
127
|
+
documentLoader(resource) {
|
|
128
|
+
if (resource === actorId) return Promise.resolve({
|
|
129
|
+
contextUrl: null,
|
|
130
|
+
documentUrl: resource,
|
|
131
|
+
document: {
|
|
132
|
+
"@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"],
|
|
133
|
+
id: actorId,
|
|
134
|
+
type: "Person",
|
|
135
|
+
publicKey: [{
|
|
136
|
+
type: "CryptographicKey",
|
|
137
|
+
owner: actorId,
|
|
138
|
+
publicKeyPem
|
|
139
|
+
}]
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
return mockDocumentLoader(resource);
|
|
143
|
+
},
|
|
144
|
+
contextLoader: mockDocumentLoader
|
|
145
|
+
};
|
|
146
|
+
const activity = new Create({ actor: new URL(actorId) });
|
|
147
|
+
assert(await doesActorOwnKey(activity, new CryptographicKey({
|
|
148
|
+
owner: new URL(actorId),
|
|
149
|
+
publicKey: rsaPublicKey1.publicKey
|
|
150
|
+
}), options));
|
|
151
|
+
assertFalse(await doesActorOwnKey(activity, new CryptographicKey({
|
|
152
|
+
owner: new URL(actorId),
|
|
153
|
+
publicKey: rsaPublicKey2.publicKey
|
|
154
|
+
}), options));
|
|
56
155
|
});
|
|
57
156
|
//#endregion
|
|
58
157
|
export {};
|
package/dist/sig/proof.test.mjs
CHANGED
|
@@ -4,11 +4,10 @@ globalThis.addEventListener = () => {};
|
|
|
4
4
|
import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
|
|
5
5
|
import "../std__assert-BBjXFNOb.mjs";
|
|
6
6
|
import { n as assertGreaterOrEqual, r as assertFalse, t as assertRejects } from "../assert_rejects-DN60FHPX.mjs";
|
|
7
|
-
import {
|
|
8
|
-
import { t as
|
|
9
|
-
import {
|
|
10
|
-
import { r as
|
|
11
|
-
import { a as verifyProof, i as verifyObject, n as hasProofLike, r as signObject, t as createProof } from "../proof-D_6qtBdQ.mjs";
|
|
7
|
+
import { n as assertInstanceOf, t as assert } from "../assert-jSdZMYam.mjs";
|
|
8
|
+
import { i as rsaPrivateKey2, n as ed25519PrivateKey, r as ed25519PublicKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-BAK-tUlf.mjs";
|
|
9
|
+
import { r as normalizeOutgoingActivityJsonLd } from "../outgoing-jsonld-HOAywiid.mjs";
|
|
10
|
+
import { a as verifyProof, i as verifyObject, n as hasProofLike, r as signObject, t as createProof } from "../proof--56drUyt.mjs";
|
|
12
11
|
import { Create, DataIntegrityProof, Document, Multikey, Note, PUBLIC_COLLECTION, Place } from "@fedify/vocab";
|
|
13
12
|
import { createTestMeterProvider, mockDocumentLoader, test } from "@fedify/fixture";
|
|
14
13
|
import { decodeMultibase, importMultibaseKey } from "@fedify/vocab-runtime";
|
|
@@ -530,5 +529,74 @@ test("verifyObject()", async () => {
|
|
|
530
529
|
assertInstanceOf(note, Note);
|
|
531
530
|
assertEquals(note.content, "Hello world");
|
|
532
531
|
});
|
|
532
|
+
test("verifyObject() rejects a key that claims a forged controller", async () => {
|
|
533
|
+
const keyId = new URL("https://attacker.example/multikey");
|
|
534
|
+
const impersonated = "https://example.com/person2";
|
|
535
|
+
const attackerActor = "https://attacker.example/actor";
|
|
536
|
+
const multikeyDocument = await ed25519Multikey.toJsonLd({ contextLoader: mockDocumentLoader });
|
|
537
|
+
const options = {
|
|
538
|
+
format: "compact",
|
|
539
|
+
contextLoader: mockDocumentLoader,
|
|
540
|
+
documentLoader: mockDocumentLoader,
|
|
541
|
+
context: ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/data-integrity/v1"]
|
|
542
|
+
};
|
|
543
|
+
const signed = await signObject(new Create({
|
|
544
|
+
id: new URL("https://attacker.example/activities/1"),
|
|
545
|
+
actor: new URL(impersonated),
|
|
546
|
+
object: new Note({
|
|
547
|
+
id: new URL("https://attacker.example/notes/1"),
|
|
548
|
+
attribution: new URL(impersonated),
|
|
549
|
+
content: "Hello world"
|
|
550
|
+
})
|
|
551
|
+
}), ed25519PrivateKey, keyId, options);
|
|
552
|
+
const jsonLd = await signed.toJsonLd(options);
|
|
553
|
+
const serveKeyControlledBy = (controller) => (resource) => {
|
|
554
|
+
if (resource === keyId.href) return Promise.resolve({
|
|
555
|
+
contextUrl: null,
|
|
556
|
+
documentUrl: resource,
|
|
557
|
+
document: {
|
|
558
|
+
...multikeyDocument,
|
|
559
|
+
id: keyId.href,
|
|
560
|
+
controller
|
|
561
|
+
}
|
|
562
|
+
});
|
|
563
|
+
if (resource === attackerActor) return Promise.resolve({
|
|
564
|
+
contextUrl: null,
|
|
565
|
+
documentUrl: resource,
|
|
566
|
+
document: {
|
|
567
|
+
"@context": [
|
|
568
|
+
"https://www.w3.org/ns/activitystreams",
|
|
569
|
+
"https://w3id.org/security/v1",
|
|
570
|
+
"https://w3id.org/security/multikey/v1",
|
|
571
|
+
"https://w3id.org/security/data-integrity/v1",
|
|
572
|
+
"https://www.w3.org/ns/did/v1"
|
|
573
|
+
],
|
|
574
|
+
id: resource,
|
|
575
|
+
type: "Person",
|
|
576
|
+
assertionMethod: [keyId.href]
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
return mockDocumentLoader(resource);
|
|
580
|
+
};
|
|
581
|
+
assertEquals(await verifyObject(Create, jsonLd, {
|
|
582
|
+
documentLoader: serveKeyControlledBy(impersonated),
|
|
583
|
+
contextLoader: mockDocumentLoader
|
|
584
|
+
}), null);
|
|
585
|
+
const honestLoader = serveKeyControlledBy(attackerActor);
|
|
586
|
+
let proof = null;
|
|
587
|
+
for await (const p of signed.getProofs(options)) {
|
|
588
|
+
proof = p;
|
|
589
|
+
break;
|
|
590
|
+
}
|
|
591
|
+
assertInstanceOf(proof, DataIntegrityProof);
|
|
592
|
+
assertInstanceOf(await verifyProof(jsonLd, proof, {
|
|
593
|
+
documentLoader: honestLoader,
|
|
594
|
+
contextLoader: mockDocumentLoader
|
|
595
|
+
}), Multikey);
|
|
596
|
+
assertEquals(await verifyObject(Create, jsonLd, {
|
|
597
|
+
documentLoader: honestLoader,
|
|
598
|
+
contextLoader: mockDocumentLoader
|
|
599
|
+
}), null);
|
|
600
|
+
});
|
|
533
601
|
//#endregion
|
|
534
602
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { c as getNormalizationContextLoader } from "./ld-
|
|
4
|
+
import { c as getNormalizationContextLoader } from "./ld-CtFHB6rU.mjs";
|
|
5
5
|
import jsonld from "@fedify/vocab-runtime/jsonld";
|
|
6
6
|
//#region src/federation/temporal.ts
|
|
7
7
|
function isPlainObject(value) {
|
package/dist/testing/mod.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "@js-temporal/polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { i as testDefinitions, n as createOutboxContext, r as createRequestContext, t as createInboxContext } from "../context-
|
|
4
|
+
import { i as testDefinitions, n as createOutboxContext, r as createRequestContext, t as createInboxContext } from "../context-BepjCFHN.mjs";
|
|
5
5
|
export { createInboxContext, createOutboxContext, createRequestContext, testDefinitions };
|
|
@@ -3,6 +3,80 @@ const { URLPattern } = require("urlpattern-polyfill");
|
|
|
3
3
|
require("./chunk-DDcVe30Y.cjs");
|
|
4
4
|
let _logtape_logtape = require("@logtape/logtape");
|
|
5
5
|
let _fedify_vocab_runtime = require("@fedify/vocab-runtime");
|
|
6
|
+
//#region src/utils/body.ts
|
|
7
|
+
/** Decoded JSON body limit: 16 MiB. @internal */
|
|
8
|
+
const MAX_BODY_SIZE = 16 * 1024 * 1024;
|
|
9
|
+
/** A body exceeded the byte limit. @internal */
|
|
10
|
+
var BodyTooLargeError = class extends _fedify_vocab_runtime.FetchError {
|
|
11
|
+
/** Creates an error for a body exceeding the given limit. */
|
|
12
|
+
constructor(url, maxBytes) {
|
|
13
|
+
super(url, `Body exceeds the limit of ${maxBytes} bytes`);
|
|
14
|
+
this.name = "BodyTooLargeError";
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
/** Validates a finite, positive byte limit. @internal */
|
|
18
|
+
function validateBodySizeLimit(maxBytes) {
|
|
19
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes <= 0) throw new RangeError("The body size limit must be a positive safe integer.");
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Reads UTF-8 text while limiting bytes received from the body stream.
|
|
23
|
+
* Fetch responses are already decompressed, so the stream count is authoritative.
|
|
24
|
+
* @param message The response or request to read.
|
|
25
|
+
* @param maxBytes The maximum number of decoded bytes to read.
|
|
26
|
+
* @param url The URL to include in errors and logs.
|
|
27
|
+
* @returns The decoded body text.
|
|
28
|
+
* @throws {BodyTooLargeError} If the body exceeds the limit.
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
async function readBoundedText(message, maxBytes, url) {
|
|
32
|
+
validateBodySizeLimit(maxBytes);
|
|
33
|
+
const reader = message.body?.getReader();
|
|
34
|
+
const tooLarge = () => {
|
|
35
|
+
(0, _logtape_logtape.getLogger)([
|
|
36
|
+
"fedify",
|
|
37
|
+
"runtime",
|
|
38
|
+
"body"
|
|
39
|
+
]).warn("Body from {url} exceeds the limit of {maxBytes} bytes.", {
|
|
40
|
+
url: url.toString(),
|
|
41
|
+
maxBytes
|
|
42
|
+
});
|
|
43
|
+
throw new BodyTooLargeError(url, maxBytes);
|
|
44
|
+
};
|
|
45
|
+
try {
|
|
46
|
+
const length = message.headers.get("Content-Length");
|
|
47
|
+
const encoding = message.headers.get("Content-Encoding");
|
|
48
|
+
if ((encoding == null || encoding.toLowerCase() === "identity") && length != null && /^\d+$/.test(length) && Number(length) > maxBytes) tooLarge();
|
|
49
|
+
if (reader == null) return "";
|
|
50
|
+
let size = 0;
|
|
51
|
+
const textReader = new ReadableStream({ async pull(controller) {
|
|
52
|
+
const { done, value } = await reader.read();
|
|
53
|
+
if (done) {
|
|
54
|
+
controller.close();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
size += value.byteLength;
|
|
58
|
+
if (size > maxBytes) tooLarge();
|
|
59
|
+
controller.enqueue(value);
|
|
60
|
+
} }, { highWaterMark: 0 }).pipeThrough(new TextDecoderStream()).getReader();
|
|
61
|
+
try {
|
|
62
|
+
const chunks = [];
|
|
63
|
+
while (true) {
|
|
64
|
+
const { done, value } = await textReader.read();
|
|
65
|
+
if (done) break;
|
|
66
|
+
chunks.push(value);
|
|
67
|
+
}
|
|
68
|
+
return chunks.join("");
|
|
69
|
+
} finally {
|
|
70
|
+
textReader.releaseLock();
|
|
71
|
+
}
|
|
72
|
+
} catch (error) {
|
|
73
|
+
if (reader != null) reader.cancel(error).catch(() => {});
|
|
74
|
+
throw error;
|
|
75
|
+
} finally {
|
|
76
|
+
reader?.releaseLock();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
6
80
|
//#region src/nodeinfo/client.ts
|
|
7
81
|
const logger = (0, _logtape_logtape.getLogger)([
|
|
8
82
|
"fedify",
|
|
@@ -83,7 +157,7 @@ async function getNodeInfo(url, options = {}) {
|
|
|
83
157
|
});
|
|
84
158
|
return;
|
|
85
159
|
}
|
|
86
|
-
const wellKnownRd = await wellKnownResponse
|
|
160
|
+
const wellKnownRd = JSON.parse(await readBoundedText(wellKnownResponse, MAX_BODY_SIZE, wellKnownUrl));
|
|
87
161
|
const link = wellKnownRd?.links?.find((link) => link != null && "rel" in link && (link.rel === "http://nodeinfo.diaspora.software/ns/schema/2.0" || link.rel === "http://nodeinfo.diaspora.software/ns/schema/2.1") && "href" in link && link.href != null);
|
|
88
162
|
if (link == null || link.href == null) {
|
|
89
163
|
logger.error("Failed to find a NodeInfo document link from {url}: {resourceDescriptor}", {
|
|
@@ -107,7 +181,7 @@ async function getNodeInfo(url, options = {}) {
|
|
|
107
181
|
});
|
|
108
182
|
return;
|
|
109
183
|
}
|
|
110
|
-
const data = await response
|
|
184
|
+
const data = JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, nodeInfoUrl));
|
|
111
185
|
if (options.parse === "none") return data;
|
|
112
186
|
return parseNodeInfo(data, { tryBestEffort: options.parse === "best-effort" }) ?? void 0;
|
|
113
187
|
} catch (error) {
|
|
@@ -353,6 +427,18 @@ function nodeInfoToJson(nodeInfo) {
|
|
|
353
427
|
};
|
|
354
428
|
}
|
|
355
429
|
//#endregion
|
|
430
|
+
Object.defineProperty(exports, "BodyTooLargeError", {
|
|
431
|
+
enumerable: true,
|
|
432
|
+
get: function() {
|
|
433
|
+
return BodyTooLargeError;
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
Object.defineProperty(exports, "MAX_BODY_SIZE", {
|
|
437
|
+
enumerable: true,
|
|
438
|
+
get: function() {
|
|
439
|
+
return MAX_BODY_SIZE;
|
|
440
|
+
}
|
|
441
|
+
});
|
|
356
442
|
Object.defineProperty(exports, "getNodeInfo", {
|
|
357
443
|
enumerable: true,
|
|
358
444
|
get: function() {
|
|
@@ -371,3 +457,9 @@ Object.defineProperty(exports, "parseNodeInfo", {
|
|
|
371
457
|
return parseNodeInfo;
|
|
372
458
|
}
|
|
373
459
|
});
|
|
460
|
+
Object.defineProperty(exports, "readBoundedText", {
|
|
461
|
+
enumerable: true,
|
|
462
|
+
get: function() {
|
|
463
|
+
return readBoundedText;
|
|
464
|
+
}
|
|
465
|
+
});
|
|
@@ -1,7 +1,81 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import { URLPattern } from "urlpattern-polyfill";
|
|
3
3
|
import { getLogger } from "@logtape/logtape";
|
|
4
|
-
import { UrlError, getUserAgent, validatePublicUrl } from "@fedify/vocab-runtime";
|
|
4
|
+
import { FetchError, UrlError, getUserAgent, validatePublicUrl } from "@fedify/vocab-runtime";
|
|
5
|
+
//#region src/utils/body.ts
|
|
6
|
+
/** Decoded JSON body limit: 16 MiB. @internal */
|
|
7
|
+
const MAX_BODY_SIZE = 16 * 1024 * 1024;
|
|
8
|
+
/** A body exceeded the byte limit. @internal */
|
|
9
|
+
var BodyTooLargeError = class extends FetchError {
|
|
10
|
+
/** Creates an error for a body exceeding the given limit. */
|
|
11
|
+
constructor(url, maxBytes) {
|
|
12
|
+
super(url, `Body exceeds the limit of ${maxBytes} bytes`);
|
|
13
|
+
this.name = "BodyTooLargeError";
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
/** Validates a finite, positive byte limit. @internal */
|
|
17
|
+
function validateBodySizeLimit(maxBytes) {
|
|
18
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes <= 0) throw new RangeError("The body size limit must be a positive safe integer.");
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Reads UTF-8 text while limiting bytes received from the body stream.
|
|
22
|
+
* Fetch responses are already decompressed, so the stream count is authoritative.
|
|
23
|
+
* @param message The response or request to read.
|
|
24
|
+
* @param maxBytes The maximum number of decoded bytes to read.
|
|
25
|
+
* @param url The URL to include in errors and logs.
|
|
26
|
+
* @returns The decoded body text.
|
|
27
|
+
* @throws {BodyTooLargeError} If the body exceeds the limit.
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
async function readBoundedText(message, maxBytes, url) {
|
|
31
|
+
validateBodySizeLimit(maxBytes);
|
|
32
|
+
const reader = message.body?.getReader();
|
|
33
|
+
const tooLarge = () => {
|
|
34
|
+
getLogger([
|
|
35
|
+
"fedify",
|
|
36
|
+
"runtime",
|
|
37
|
+
"body"
|
|
38
|
+
]).warn("Body from {url} exceeds the limit of {maxBytes} bytes.", {
|
|
39
|
+
url: url.toString(),
|
|
40
|
+
maxBytes
|
|
41
|
+
});
|
|
42
|
+
throw new BodyTooLargeError(url, maxBytes);
|
|
43
|
+
};
|
|
44
|
+
try {
|
|
45
|
+
const length = message.headers.get("Content-Length");
|
|
46
|
+
const encoding = message.headers.get("Content-Encoding");
|
|
47
|
+
if ((encoding == null || encoding.toLowerCase() === "identity") && length != null && /^\d+$/.test(length) && Number(length) > maxBytes) tooLarge();
|
|
48
|
+
if (reader == null) return "";
|
|
49
|
+
let size = 0;
|
|
50
|
+
const textReader = new ReadableStream({ async pull(controller) {
|
|
51
|
+
const { done, value } = await reader.read();
|
|
52
|
+
if (done) {
|
|
53
|
+
controller.close();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
size += value.byteLength;
|
|
57
|
+
if (size > maxBytes) tooLarge();
|
|
58
|
+
controller.enqueue(value);
|
|
59
|
+
} }, { highWaterMark: 0 }).pipeThrough(new TextDecoderStream()).getReader();
|
|
60
|
+
try {
|
|
61
|
+
const chunks = [];
|
|
62
|
+
while (true) {
|
|
63
|
+
const { done, value } = await textReader.read();
|
|
64
|
+
if (done) break;
|
|
65
|
+
chunks.push(value);
|
|
66
|
+
}
|
|
67
|
+
return chunks.join("");
|
|
68
|
+
} finally {
|
|
69
|
+
textReader.releaseLock();
|
|
70
|
+
}
|
|
71
|
+
} catch (error) {
|
|
72
|
+
if (reader != null) reader.cancel(error).catch(() => {});
|
|
73
|
+
throw error;
|
|
74
|
+
} finally {
|
|
75
|
+
reader?.releaseLock();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
5
79
|
//#region src/nodeinfo/client.ts
|
|
6
80
|
const logger = getLogger([
|
|
7
81
|
"fedify",
|
|
@@ -82,7 +156,7 @@ async function getNodeInfo(url, options = {}) {
|
|
|
82
156
|
});
|
|
83
157
|
return;
|
|
84
158
|
}
|
|
85
|
-
const wellKnownRd = await wellKnownResponse
|
|
159
|
+
const wellKnownRd = JSON.parse(await readBoundedText(wellKnownResponse, MAX_BODY_SIZE, wellKnownUrl));
|
|
86
160
|
const link = wellKnownRd?.links?.find((link) => link != null && "rel" in link && (link.rel === "http://nodeinfo.diaspora.software/ns/schema/2.0" || link.rel === "http://nodeinfo.diaspora.software/ns/schema/2.1") && "href" in link && link.href != null);
|
|
87
161
|
if (link == null || link.href == null) {
|
|
88
162
|
logger.error("Failed to find a NodeInfo document link from {url}: {resourceDescriptor}", {
|
|
@@ -106,7 +180,7 @@ async function getNodeInfo(url, options = {}) {
|
|
|
106
180
|
});
|
|
107
181
|
return;
|
|
108
182
|
}
|
|
109
|
-
const data = await response
|
|
183
|
+
const data = JSON.parse(await readBoundedText(response, MAX_BODY_SIZE, nodeInfoUrl));
|
|
110
184
|
if (options.parse === "none") return data;
|
|
111
185
|
return parseNodeInfo(data, { tryBestEffort: options.parse === "best-effort" }) ?? void 0;
|
|
112
186
|
} catch (error) {
|
|
@@ -352,4 +426,4 @@ function nodeInfoToJson(nodeInfo) {
|
|
|
352
426
|
};
|
|
353
427
|
}
|
|
354
428
|
//#endregion
|
|
355
|
-
export { getNodeInfo as n, parseNodeInfo as r, nodeInfoToJson as t };
|
|
429
|
+
export { MAX_BODY_SIZE as a, BodyTooLargeError as i, getNodeInfo as n, readBoundedText as o, parseNodeInfo as r, nodeInfoToJson as t };
|
|
@@ -5,11 +5,11 @@ import { t as esm_default } from "../esm-vrlUxr60.mjs";
|
|
|
5
5
|
import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
|
|
6
6
|
import "../std__assert-BBjXFNOb.mjs";
|
|
7
7
|
import { t as assertRejects } from "../assert_rejects-DN60FHPX.mjs";
|
|
8
|
-
import { l as verifyRequest } from "../http-
|
|
9
|
-
import { i as rsaPrivateKey2 } from "../keys-
|
|
10
|
-
import { t as getAuthenticatedDocumentLoader } from "../docloader-
|
|
8
|
+
import { l as verifyRequest } from "../http-ClEDLGpr.mjs";
|
|
9
|
+
import { i as rsaPrivateKey2 } from "../keys-BAK-tUlf.mjs";
|
|
10
|
+
import { t as getAuthenticatedDocumentLoader } from "../docloader-BAdp-ZeK.mjs";
|
|
11
11
|
import { mockDocumentLoader, test } from "@fedify/fixture";
|
|
12
|
-
import { UrlError } from "@fedify/vocab-runtime";
|
|
12
|
+
import { FetchError, UrlError } from "@fedify/vocab-runtime";
|
|
13
13
|
//#region src/utils/docloader.test.ts
|
|
14
14
|
test("getAuthenticatedDocumentLoader()", async (t) => {
|
|
15
15
|
esm_default.spyGlobal();
|
|
@@ -136,5 +136,29 @@ test("getAuthenticatedDocumentLoader() cancellation", {
|
|
|
136
136
|
});
|
|
137
137
|
esm_default.hardReset();
|
|
138
138
|
});
|
|
139
|
+
test("getAuthenticatedDocumentLoader() bounds JSON after redirects", async () => {
|
|
140
|
+
esm_default.mockGlobal();
|
|
141
|
+
let oversized = true;
|
|
142
|
+
try {
|
|
143
|
+
const url = "https://example.com/bounded";
|
|
144
|
+
esm_default.get(url, {
|
|
145
|
+
status: 302,
|
|
146
|
+
headers: { Location: `${url}/document` }
|
|
147
|
+
});
|
|
148
|
+
esm_default.get(`${url}/document`, () => new Response("{\"name\":\"hello\"}", { headers: {
|
|
149
|
+
"Content-Type": "application/activity+json",
|
|
150
|
+
...oversized ? { "Content-Length": String(16777217) } : {}
|
|
151
|
+
} }));
|
|
152
|
+
const loader = getAuthenticatedDocumentLoader({
|
|
153
|
+
privateKey: rsaPrivateKey2,
|
|
154
|
+
keyId: new URL("https://example.com/key2")
|
|
155
|
+
}, { allowPrivateAddress: true });
|
|
156
|
+
await assertRejects(() => loader(url), FetchError);
|
|
157
|
+
oversized = false;
|
|
158
|
+
assertEquals((await loader(url)).document, { name: "hello" });
|
|
159
|
+
} finally {
|
|
160
|
+
esm_default.hardReset();
|
|
161
|
+
}
|
|
162
|
+
});
|
|
139
163
|
//#endregion
|
|
140
164
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import { URLPattern } from "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { n as kvCache, t as MockKvStore } from "../kv-cache-
|
|
4
|
+
import { n as kvCache, t as MockKvStore } from "../kv-cache-C5FK4PLG.mjs";
|
|
5
5
|
import { deepStrictEqual, throws } from "node:assert";
|
|
6
6
|
import { createTestMeterProvider, mockDocumentLoader, test } from "@fedify/fixture";
|
|
7
7
|
import { preloadedContexts } from "@fedify/vocab-runtime";
|