@fedify/fedify 2.2.19 → 2.2.21
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/attachment-arrays-CalAATqD.mjs +16 -0
- package/dist/{builder-UmydCxtK.mjs → builder-4ImvtjG4.mjs} +3 -3
- package/dist/callback-0KrwzutD.d.mts +2607 -0
- package/dist/{client-CSddvgWN.d.ts → client-9DPcy_Yx.d.ts} +16 -1
- package/dist/{client-CAM_bQXx.d.cts → client-B3ruDgWg.d.cts} +16 -1
- package/dist/{client-9F_u23dc.mjs → client-XYMC0Mmk.mjs} +189 -65
- package/dist/compat/attachment-arrays.test.d.mts +2 -0
- package/dist/compat/attachment-arrays.test.mjs +255 -0
- 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 +1 -1
- package/dist/{context-tJbL_Hkw.d.cts → context-CjWuov0g.d.cts} +57 -14
- package/dist/{context-OkwEpc3-.d.ts → context-DZqI2LJD.d.ts} +57 -14
- package/dist/{deno-CD-8UlUi.mjs → deno-AWk3S2Ug.mjs} +1 -1
- package/dist/docloader-Bogpjg4d.mjs +125 -0
- package/dist/federation/attachment-responses.test.d.mts +2 -0
- package/dist/federation/attachment-responses.test.mjs +182 -0
- package/dist/federation/builder.test.mjs +1 -1
- package/dist/federation/collection.test.mjs +1 -1
- package/dist/federation/delivery-attachments.test.d.mts +2 -0
- package/dist/federation/delivery-attachments.test.mjs +288 -0
- package/dist/federation/handler.test.mjs +208 -16
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/inbox.test.mjs +2 -2
- package/dist/federation/middleware.test.mjs +1567 -30
- 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/negotiation.test.mjs +1 -1
- package/dist/federation/retry.test.mjs +1 -1
- package/dist/federation/send.test.mjs +723 -68
- package/dist/federation/temporal.test.mjs +25 -1
- package/dist/federation/webfinger.test.mjs +1 -1
- package/dist/{http-BBBUbwKh.mjs → http-B3wCvgu8.mjs} +199 -99
- package/dist/{http-DrUG4fPS.cjs → http-BNaPJVnF.cjs} +178 -107
- package/dist/{http-DJK2udgX.js → http-BpdLaGy8.js} +177 -106
- package/dist/{http-Dl00HXr4.d.ts → http-C8qLHs_Z.d.cts} +3 -4
- package/dist/{http-DqZhyEso.d.cts → http-D8WmcRAF.d.ts} +3 -4
- package/dist/{inbox-Dca_0fwc.mjs → inbox-DLy6WBXU.mjs} +1 -1
- package/dist/{key-DolXUaLH.mjs → key-Bhc8cQC7.mjs} +3 -2
- package/dist/{kv-cache-Bk3V1Tiu.cjs → kv-cache-Bj3CY9Jo.cjs} +59 -17
- package/dist/{kv-cache-DDm80t1K.js → kv-cache-CvjLUQTf.js} +60 -18
- package/dist/{ld-rTdIfZ63.mjs → ld-DTeykI0e.mjs} +153 -21
- package/dist/ld-signature-Dgz_b89j.mjs +23 -0
- package/dist/{middleware-BWOwEGpy.cjs → middleware-BSQP4d9p.cjs} +642 -149
- package/dist/{middleware-B4-Rzdi3.cjs → middleware-CWOzxb3o.cjs} +1 -1
- package/dist/{middleware-DYK_res8.mjs → middleware-DkMsC5mQ.mjs} +1 -1
- package/dist/{middleware-BimXKBcP.js → middleware-Dx1iwFk8.js} +641 -149
- package/dist/{middleware-CpXoRHs3.mjs → middleware-dlGvSrXl.mjs} +452 -122
- package/dist/{mod-D2JyWtW3.d.cts → mod-BmxqcEnU.d.ts} +30 -13
- package/dist/{mod-a6kmB8xD.d.cts → mod-DWEx2D4q.d.cts} +1 -1
- package/dist/{mod-DQGjRJUG.d.ts → mod-DnPmz3-S.d.ts} +1 -1
- package/dist/{mod-ej_rLx8h.d.ts → mod-INjDw-m0.d.cts} +30 -13
- package/dist/{mod-B6LmugJ4.d.ts → mod-REfljt0T.d.ts} +4 -10
- package/dist/{mod-V2vDnYNu.d.cts → mod-UvIGUHqW.d.cts} +4 -10
- package/dist/mod.cjs +5 -5
- package/dist/mod.d.cts +8 -8
- package/dist/mod.d.ts +8 -8
- package/dist/mod.js +5 -5
- package/dist/nodeinfo/client.test.mjs +764 -18
- package/dist/nodeinfo/handler.test.mjs +1 -1
- package/dist/nodeinfo/mod.cjs +1 -1
- package/dist/nodeinfo/mod.d.cts +1 -1
- package/dist/nodeinfo/mod.d.ts +1 -1
- package/dist/nodeinfo/mod.js +1 -1
- package/dist/nodeinfo/types.test.mjs +1 -1
- package/dist/otel/exporter.test.mjs +292 -30
- package/dist/otel/mod.cjs +36 -30
- package/dist/otel/mod.d.cts +13 -0
- package/dist/otel/mod.d.ts +13 -0
- package/dist/otel/mod.js +36 -30
- package/dist/{outgoing-jsonld-amccRMrV.mjs → outgoing-jsonld-DHf_DYXp.mjs} +38 -8
- package/dist/{owner-CVfzyM5V.mjs → owner-BsA7qMHB.mjs} +2 -2
- package/dist/{proof-gOGM-sJS.mjs → proof-C63Hqt9N.mjs} +40 -15
- package/dist/{proof-DhaTTn-P.cjs → proof-Dbz6ApNP.cjs} +1190 -1007
- package/dist/{proof-CaQ4KG6y.js → proof-QV_o5ZqS.js} +1174 -1003
- package/dist/send-CAdpwbFX.mjs +416 -0
- package/dist/sig/http.test.mjs +528 -2
- package/dist/sig/key-types.test.d.mts +218 -0
- package/dist/sig/key-types.test.mjs +8 -0
- package/dist/sig/key.test.mjs +2 -2
- package/dist/sig/ld.test.mjs +573 -8
- 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 +1 -1
- package/dist/sig/proof.test.mjs +96 -4
- package/dist/{temporal-CA4Y9hBJ.mjs → temporal-B3JGkVgk.mjs} +3 -5
- package/dist/testing/mod.d.mts +1 -2396
- package/dist/{types-DRPjmHVV.cjs → types-BWx7zw3Y.cjs} +187 -63
- package/dist/{types-miAYfiGO.js → types-Dx_w2JSM.js} +188 -64
- package/dist/utils/docloader.test.mjs +318 -34
- 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 +6 -6
- package/dist/docloader-D1ghurDJ.mjs +0 -83
- package/dist/send-D35Va72B.mjs +0 -260
- /package/dist/{activity-listener-ell7W1s9.mjs → activity-listener-tztVvlNb.mjs} +0 -0
- /package/dist/{collection-D-HqUuA2.mjs → collection-CA3V5zyK.mjs} +0 -0
- /package/dist/{negotiation-SQvQgUqe.mjs → negotiation-VnHNB0Q5.mjs} +0 -0
- /package/dist/{public-audience-DpJqzPuh.mjs → public-audience-4g3_Ze4y.mjs} +0 -0
- /package/dist/{retry-v_sGLH1d.mjs → retry-CXg_MBI-.mjs} +0 -0
- /package/dist/{types-J53Kw7so.mjs → types-BFowWFTT.mjs} +0 -0
|
@@ -7,11 +7,12 @@ let _opentelemetry_api = require("@opentelemetry/api");
|
|
|
7
7
|
let byte_encodings_hex = require("byte-encodings/hex");
|
|
8
8
|
let _fedify_vocab_runtime = require("@fedify/vocab-runtime");
|
|
9
9
|
let structured_field_values = require("structured-field-values");
|
|
10
|
+
let _fedify_vocab_runtime_internal = require("@fedify/vocab-runtime/internal");
|
|
10
11
|
let _opentelemetry_semantic_conventions = require("@opentelemetry/semantic-conventions");
|
|
11
12
|
let byte_encodings_base64 = require("byte-encodings/base64");
|
|
12
13
|
//#region deno.json
|
|
13
14
|
var name = "@fedify/fedify";
|
|
14
|
-
var version = "2.2.
|
|
15
|
+
var version = "2.2.21";
|
|
15
16
|
//#endregion
|
|
16
17
|
//#region src/sig/accept.ts
|
|
17
18
|
/**
|
|
@@ -262,7 +263,7 @@ function generateCryptoKeyPair(algorithm) {
|
|
|
262
263
|
*/
|
|
263
264
|
async function exportJwk(key) {
|
|
264
265
|
validateCryptoKey(key);
|
|
265
|
-
const jwk = await crypto.subtle.exportKey("jwk", key);
|
|
266
|
+
const jwk = await crypto.subtle.exportKey("jwk", (0, _fedify_vocab_runtime_internal.asCryptoKey)(key));
|
|
266
267
|
if (jwk.crv === "Ed25519") jwk.alg = "Ed25519";
|
|
267
268
|
return jwk;
|
|
268
269
|
}
|
|
@@ -775,12 +776,13 @@ const DOUBLE_KNOCK_TRANSPORT_RETRY_DELAY_MS = 100;
|
|
|
775
776
|
*/
|
|
776
777
|
async function signRequest(request, privateKey, keyId, options = {}) {
|
|
777
778
|
validateCryptoKey(privateKey, "private");
|
|
779
|
+
const signingKey = (0, _fedify_vocab_runtime_internal.asCryptoKey)(privateKey);
|
|
778
780
|
return await (options.tracerProvider ?? _opentelemetry_api.trace.getTracerProvider()).getTracer(name, version).startActiveSpan("http_signatures.sign", async (span) => {
|
|
779
781
|
try {
|
|
780
782
|
const spec = options.spec ?? "draft-cavage-http-signatures-12";
|
|
781
783
|
let signed;
|
|
782
|
-
if (spec === "rfc9421") signed = await signRequestRfc9421(request,
|
|
783
|
-
else signed = await signRequestDraft(request,
|
|
784
|
+
if (spec === "rfc9421") signed = await signRequestRfc9421(request, signingKey, keyId, span, options.currentTime, options.body, options.rfc9421);
|
|
785
|
+
else signed = await signRequestDraft(request, signingKey, keyId, span, options.currentTime, options.body);
|
|
784
786
|
if (span.isRecording()) {
|
|
785
787
|
span.setAttribute(_opentelemetry_semantic_conventions.ATTR_HTTP_REQUEST_METHOD, signed.method);
|
|
786
788
|
span.setAttribute(_opentelemetry_semantic_conventions.ATTR_URL_FULL, signed.url);
|
|
@@ -1598,10 +1600,10 @@ async function createRedirectRequest(request, location, body, validateRedirect)
|
|
|
1598
1600
|
cache: request.cache
|
|
1599
1601
|
});
|
|
1600
1602
|
}
|
|
1601
|
-
async function fetchDoubleKnockRequest(request, signedRequest, signal) {
|
|
1603
|
+
async function fetchDoubleKnockRequest(session, request, signedRequest, signal) {
|
|
1602
1604
|
const maxAttempts = request.method === "GET" || request.method === "HEAD" ? 2 : 1;
|
|
1603
1605
|
for (let attempt = 1;; attempt++) try {
|
|
1604
|
-
return await fetch(signedRequest, {
|
|
1606
|
+
return await session.fetch(signedRequest, {
|
|
1605
1607
|
redirect: "manual",
|
|
1606
1608
|
signal
|
|
1607
1609
|
});
|
|
@@ -1652,118 +1654,187 @@ function getAbortReason(signal) {
|
|
|
1652
1654
|
return signal.reason ?? new DOMException("The operation was aborted.", "AbortError");
|
|
1653
1655
|
}
|
|
1654
1656
|
/**
|
|
1655
|
-
* Performs a double-knock request
|
|
1656
|
-
*
|
|
1657
|
-
*
|
|
1657
|
+
* Performs a double-knock request like {@link doubleKnock}, opening a session
|
|
1658
|
+
* for every hop with the given function, and passes the final response to
|
|
1659
|
+
* the given function. The final session is closed after `consume` settles,
|
|
1660
|
+
* so `consume` must read or cancel the response body before it returns.
|
|
1661
|
+
* This is not exported from any entry point.
|
|
1658
1662
|
* @param request The request to send.
|
|
1659
1663
|
* @param identity The identity to use for signing the request.
|
|
1660
1664
|
* @param options The options for double-knock requests.
|
|
1661
|
-
* @
|
|
1662
|
-
*
|
|
1665
|
+
* @param openHop The function to open a session for each hop. The session of
|
|
1666
|
+
* a hop is closed before the next hop is opened.
|
|
1667
|
+
* @param consume The function to consume the final response.
|
|
1668
|
+
* @returns The value returned by `consume`.
|
|
1663
1669
|
*/
|
|
1664
|
-
async function
|
|
1665
|
-
|
|
1670
|
+
async function doubleKnockScoped(request, identity, options, openHop, consume) {
|
|
1671
|
+
const { response, session } = await doubleKnockCore(request, identity, options, openHop);
|
|
1672
|
+
try {
|
|
1673
|
+
return await consume(response);
|
|
1674
|
+
} catch (error) {
|
|
1675
|
+
(0, _logtape_logtape.getLogger)([
|
|
1676
|
+
"fedify",
|
|
1677
|
+
"sig",
|
|
1678
|
+
"http"
|
|
1679
|
+
]).debug("Failed to consume the response from {url}; closing the session: {error}", {
|
|
1680
|
+
url: request.url,
|
|
1681
|
+
error
|
|
1682
|
+
});
|
|
1683
|
+
throw error;
|
|
1684
|
+
} finally {
|
|
1685
|
+
await session.close();
|
|
1686
|
+
}
|
|
1666
1687
|
}
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
let response = await fetchDoubleKnockRequest(request, signedRequest, signal);
|
|
1681
|
-
if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
|
|
1682
|
-
if (redirected >= maximumRedirection) throw new _fedify_vocab_runtime.FetchError(request.url, `Too many redirections (${redirected + 1})`);
|
|
1683
|
-
const redirectRequest = await createRedirectRequest(request, response.headers.get("Location"), body, options.validateRedirect);
|
|
1684
|
-
if (visited.has(redirectRequest.url)) throw new _fedify_vocab_runtime.FetchError(request.url, `Redirect loop detected: ${redirectRequest.url}`);
|
|
1685
|
-
return doubleKnockInternal(redirectRequest, identity, {
|
|
1686
|
-
...options,
|
|
1687
|
-
body
|
|
1688
|
-
}, redirected + 1, visited);
|
|
1689
|
-
} else if (response.status === 400 || response.status === 401 || response.status > 401) {
|
|
1690
|
-
const logger = (0, _logtape_logtape.getLogger)([
|
|
1688
|
+
function isRedirectResponse(response) {
|
|
1689
|
+
return response.status >= 300 && response.status < 400 && response.headers.has("Location");
|
|
1690
|
+
}
|
|
1691
|
+
/**
|
|
1692
|
+
* Starts cancelling the body of a response that is not passed to the caller,
|
|
1693
|
+
* without waiting for it to settle. The cancellation of a branch of a tee
|
|
1694
|
+
* (e.g., a body cloned by a fetch mock) settles only after the other branch
|
|
1695
|
+
* is cancelled too, per the Streams standard, so awaiting it could block
|
|
1696
|
+
* forever. Failures are only logged.
|
|
1697
|
+
*/
|
|
1698
|
+
function cancelResponseBody(response, url) {
|
|
1699
|
+
response.body?.cancel().catch((error) => {
|
|
1700
|
+
(0, _logtape_logtape.getLogger)([
|
|
1691
1701
|
"fedify",
|
|
1692
1702
|
"sig",
|
|
1693
1703
|
"http"
|
|
1694
|
-
])
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1704
|
+
]).debug("Failed to cancel the response body from {url}: {error}", {
|
|
1705
|
+
url,
|
|
1706
|
+
error
|
|
1707
|
+
});
|
|
1708
|
+
});
|
|
1709
|
+
}
|
|
1710
|
+
async function doubleKnockCore(request, identity, options, openHop) {
|
|
1711
|
+
const { specDeterminer, log, tracerProvider, signal } = options;
|
|
1712
|
+
const maximumRedirection = options.maxRedirection ?? DEFAULT_MAX_REDIRECTION;
|
|
1713
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1714
|
+
const body = options.body !== void 0 ? options.body : request.method !== "GET" && request.method !== "HEAD" ? await request.clone().arrayBuffer() : null;
|
|
1715
|
+
let session = await openHop(request.url);
|
|
1716
|
+
try {
|
|
1717
|
+
for (let redirected = 0;; redirected++) {
|
|
1718
|
+
visited.add(request.url);
|
|
1719
|
+
const origin = new URL(request.url).origin;
|
|
1720
|
+
const firstTrySpec = specDeterminer == null ? "rfc9421" : await specDeterminer.determineSpec(origin);
|
|
1721
|
+
let signedRequest = await signRequest(request, identity.privateKey, identity.keyId, {
|
|
1722
|
+
spec: firstTrySpec,
|
|
1723
|
+
tracerProvider,
|
|
1724
|
+
body
|
|
1725
|
+
});
|
|
1726
|
+
log?.(signedRequest);
|
|
1727
|
+
let response = await fetchDoubleKnockRequest(session, request, signedRequest, signal);
|
|
1728
|
+
const firstRedirected = isRedirectResponse(response);
|
|
1729
|
+
if (!firstRedirected && (response.status === 400 || response.status === 401 || response.status > 401)) {
|
|
1730
|
+
const logger = (0, _logtape_logtape.getLogger)([
|
|
1731
|
+
"fedify",
|
|
1732
|
+
"sig",
|
|
1733
|
+
"http"
|
|
1734
|
+
]);
|
|
1735
|
+
const acceptSigHeader = response.headers.get("Accept-Signature");
|
|
1736
|
+
if (acceptSigHeader != null) {
|
|
1737
|
+
const entries = validateAcceptSignature(parseAcceptSignature(acceptSigHeader));
|
|
1738
|
+
const localKeyId = identity.keyId.href;
|
|
1739
|
+
const localAlg = "rsa-v1_5-sha256";
|
|
1740
|
+
let fulfilled = false;
|
|
1741
|
+
let challengeRequest;
|
|
1742
|
+
for (const entry of entries) {
|
|
1743
|
+
const rfc9421 = fulfillAcceptSignature(entry, localKeyId, localAlg);
|
|
1744
|
+
if (rfc9421 == null) continue;
|
|
1745
|
+
logger.debug("Received Accept-Signature challenge; accumulating label {label} and components {components}.", {
|
|
1746
|
+
label: rfc9421.label,
|
|
1747
|
+
components: rfc9421.components
|
|
1748
|
+
});
|
|
1749
|
+
try {
|
|
1750
|
+
challengeRequest = await signRequest(challengeRequest ?? request, identity.privateKey, identity.keyId, {
|
|
1751
|
+
spec: "rfc9421",
|
|
1752
|
+
tracerProvider,
|
|
1753
|
+
body,
|
|
1754
|
+
rfc9421
|
|
1755
|
+
});
|
|
1756
|
+
fulfilled = true;
|
|
1757
|
+
} catch (error) {
|
|
1758
|
+
logger.debug("Failed to fulfill Accept-Signature challenge entry {label}: {error}", {
|
|
1759
|
+
label: entry.label,
|
|
1760
|
+
error
|
|
1761
|
+
});
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
if (fulfilled && challengeRequest != null) {
|
|
1765
|
+
cancelResponseBody(response, request.url);
|
|
1766
|
+
signedRequest = challengeRequest;
|
|
1767
|
+
log?.(signedRequest);
|
|
1768
|
+
response = await session.fetch(signedRequest, {
|
|
1769
|
+
redirect: "manual",
|
|
1770
|
+
signal
|
|
1771
|
+
});
|
|
1772
|
+
}
|
|
1773
|
+
if (fulfilled && !isRedirectResponse(response)) {
|
|
1774
|
+
if (response.status < 300) {
|
|
1775
|
+
await specDeterminer?.rememberSpec(origin, "rfc9421");
|
|
1776
|
+
return {
|
|
1777
|
+
response,
|
|
1778
|
+
session
|
|
1779
|
+
};
|
|
1780
|
+
}
|
|
1781
|
+
if (response.status !== 400 && response.status !== 401) return {
|
|
1782
|
+
response,
|
|
1783
|
+
session
|
|
1784
|
+
};
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
if (!isRedirectResponse(response)) {
|
|
1788
|
+
const spec = firstTrySpec === "draft-cavage-http-signatures-12" ? "rfc9421" : "draft-cavage-http-signatures-12";
|
|
1789
|
+
(0, _logtape_logtape.getLogger)([
|
|
1790
|
+
"fedify",
|
|
1791
|
+
"sig",
|
|
1792
|
+
"http"
|
|
1793
|
+
]).debug("Failed to verify with the spec {spec} ({status} {statusText}); retrying with spec {secondSpec}... (double-knocking)", {
|
|
1794
|
+
spec: firstTrySpec,
|
|
1795
|
+
secondSpec: spec,
|
|
1796
|
+
status: response.status,
|
|
1797
|
+
statusText: response.statusText
|
|
1715
1798
|
});
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1799
|
+
cancelResponseBody(response, request.url);
|
|
1800
|
+
signedRequest = await signRequest(request, identity.privateKey, identity.keyId, {
|
|
1801
|
+
spec,
|
|
1802
|
+
tracerProvider,
|
|
1803
|
+
body
|
|
1721
1804
|
});
|
|
1805
|
+
log?.(signedRequest);
|
|
1806
|
+
response = await fetchDoubleKnockRequest(session, request, signedRequest, signal);
|
|
1807
|
+
if (!isRedirectResponse(response) && response.status !== 400 && response.status !== 401) await specDeterminer?.rememberSpec(origin, spec);
|
|
1722
1808
|
}
|
|
1723
|
-
}
|
|
1724
|
-
if (
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
});
|
|
1731
|
-
if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) return doubleKnock(await createRedirectRequest(request, response.headers.get("Location"), body, options.validateRedirect), identity, {
|
|
1732
|
-
...options,
|
|
1733
|
-
body
|
|
1734
|
-
});
|
|
1735
|
-
}
|
|
1736
|
-
if (fulfilled && response.status < 300) {
|
|
1737
|
-
await specDeterminer?.rememberSpec(origin, "rfc9421");
|
|
1738
|
-
return response;
|
|
1739
|
-
}
|
|
1740
|
-
if (fulfilled && response.status !== 400 && response.status !== 401) return response;
|
|
1741
|
-
}
|
|
1742
|
-
const spec = firstTrySpec === "draft-cavage-http-signatures-12" ? "rfc9421" : "draft-cavage-http-signatures-12";
|
|
1743
|
-
logger.debug("Failed to verify with the spec {spec} ({status} {statusText}); retrying with spec {secondSpec}... (double-knocking)", {
|
|
1744
|
-
spec: firstTrySpec,
|
|
1745
|
-
secondSpec: spec,
|
|
1746
|
-
status: response.status,
|
|
1747
|
-
statusText: response.statusText
|
|
1748
|
-
});
|
|
1749
|
-
signedRequest = await signRequest(request, identity.privateKey, identity.keyId, {
|
|
1750
|
-
spec,
|
|
1751
|
-
tracerProvider,
|
|
1752
|
-
body
|
|
1753
|
-
});
|
|
1754
|
-
log?.(signedRequest);
|
|
1755
|
-
response = await fetchDoubleKnockRequest(request, signedRequest, signal);
|
|
1756
|
-
if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
|
|
1809
|
+
} else if (!firstRedirected) await specDeterminer?.rememberSpec(origin, firstTrySpec);
|
|
1810
|
+
if (!isRedirectResponse(response)) return {
|
|
1811
|
+
response,
|
|
1812
|
+
session
|
|
1813
|
+
};
|
|
1814
|
+
cancelResponseBody(response, request.url);
|
|
1815
|
+
await session.close();
|
|
1757
1816
|
if (redirected >= maximumRedirection) throw new _fedify_vocab_runtime.FetchError(request.url, `Too many redirections (${redirected + 1})`);
|
|
1758
|
-
const
|
|
1817
|
+
const location = response.headers.get("Location");
|
|
1818
|
+
const redirectRequest = await createRedirectRequest(request, location, body, options.validateRedirect);
|
|
1759
1819
|
if (visited.has(redirectRequest.url)) throw new _fedify_vocab_runtime.FetchError(request.url, `Redirect loop detected: ${redirectRequest.url}`);
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1820
|
+
request = redirectRequest;
|
|
1821
|
+
session = await openHop(request.url);
|
|
1822
|
+
}
|
|
1823
|
+
} catch (error) {
|
|
1824
|
+
try {
|
|
1825
|
+
await session.close();
|
|
1826
|
+
} catch (closeError) {
|
|
1827
|
+
(0, _logtape_logtape.getLogger)([
|
|
1828
|
+
"fedify",
|
|
1829
|
+
"sig",
|
|
1830
|
+
"http"
|
|
1831
|
+
]).debug("Failed to close the session for {url}: {error}", {
|
|
1832
|
+
url: request.url,
|
|
1833
|
+
error: closeError
|
|
1834
|
+
});
|
|
1835
|
+
}
|
|
1836
|
+
throw error;
|
|
1837
|
+
}
|
|
1767
1838
|
}
|
|
1768
1839
|
/**
|
|
1769
1840
|
* Performs a timing-safe equality comparison between two `Uint8Array` values.
|
|
@@ -1793,10 +1864,10 @@ function timingSafeEqual(a, b) {
|
|
|
1793
1864
|
return result === 0;
|
|
1794
1865
|
}
|
|
1795
1866
|
//#endregion
|
|
1796
|
-
Object.defineProperty(exports, "
|
|
1867
|
+
Object.defineProperty(exports, "doubleKnockScoped", {
|
|
1797
1868
|
enumerable: true,
|
|
1798
1869
|
get: function() {
|
|
1799
|
-
return
|
|
1870
|
+
return doubleKnockScoped;
|
|
1800
1871
|
}
|
|
1801
1872
|
});
|
|
1802
1873
|
Object.defineProperty(exports, "exportJwk", {
|