@fedify/fedify 1.3.2 → 1.3.4

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.
@@ -2,7 +2,9 @@ import { getLogger } from "@logtape/logtape";
2
2
  import { SpanKind, SpanStatusCode, trace, } from "@opentelemetry/api";
3
3
  import metadata from "../deno.js";
4
4
  import { getUserAgent, } from "../runtime/docloader.js";
5
+ import { validatePublicUrl } from "../runtime/url.js";
5
6
  const logger = getLogger(["fedify", "webfinger", "lookup"]);
7
+ const MAX_REDIRECTION = 5; // TODO: Make this configurable.
6
8
  /**
7
9
  * Looks up a WebFinger resource.
8
10
  * @param resource The resource URL to look up.
@@ -60,9 +62,11 @@ async function lookupWebFingerInternal(resource, options = {}) {
60
62
  }
61
63
  let url = new URL(`${protocol}//${server}/.well-known/webfinger`);
62
64
  url.searchParams.set("resource", resource.href);
65
+ let redirected = 0;
63
66
  while (true) {
64
67
  logger.debug("Fetching WebFinger resource descriptor from {url}...", { url: url.href });
65
68
  let response;
69
+ await validatePublicUrl(url.href);
66
70
  try {
67
71
  response = await fetch(url, {
68
72
  headers: {
@@ -80,7 +84,23 @@ async function lookupWebFingerInternal(resource, options = {}) {
80
84
  }
81
85
  if (response.status >= 300 && response.status < 400 &&
82
86
  response.headers.has("Location")) {
83
- url = new URL(response.headers.get("Location"), response.url == null || response.url === "" ? url : response.url);
87
+ redirected++;
88
+ if (redirected >= MAX_REDIRECTION) {
89
+ logger.error("Too many redirections ({redirections}) while fetching WebFinger " +
90
+ "resource descriptor.", { redirections: redirected });
91
+ return null;
92
+ }
93
+ const redirectedUrl = new URL(response.headers.get("Location"), response.url == null || response.url === "" ? url : response.url);
94
+ if (redirectedUrl.protocol !== url.protocol) {
95
+ logger.error("Redirected to a different protocol ({protocol} to " +
96
+ "{redirectedProtocol}) while fetching WebFinger resource " +
97
+ "descriptor.", {
98
+ protocol: url.protocol,
99
+ redirectedProtocol: redirectedUrl.protocol,
100
+ });
101
+ return null;
102
+ }
103
+ url = redirectedUrl;
84
104
  continue;
85
105
  }
86
106
  if (!response.ok) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/fedify",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "description": "An ActivityPub server framework",
5
5
  "keywords": [
6
6
  "ActivityPub",
@@ -1 +1 @@
1
- {"version":3,"file":"contexts.d.ts","sourceRoot":"","sources":["../../src/runtime/contexts.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAikI9C,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
1
+ {"version":3,"file":"contexts.d.ts","sourceRoot":"","sources":["../../src/runtime/contexts.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAkmI9C,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../src/runtime/url.ts"],"names":[],"mappings":"AAIA,qBAAa,QAAS,SAAQ,KAAK;gBACrB,OAAO,EAAE,MAAM;CAI5B;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAqClE;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CASjE;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,WASvD;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAWzD"}
1
+ {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../src/runtime/url.ts"],"names":[],"mappings":"AAKA,qBAAa,QAAS,SAAQ,KAAK;gBACrB,OAAO,EAAE,MAAM;CAI5B;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA0ClE;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CASjE;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,WASvD;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAWzD"}
@@ -1 +1 @@
1
- {"version":3,"file":"lookup.d.ts","sourceRoot":"","sources":["../../src/webfinger/lookup.ts"],"names":[],"mappings":";AACA,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAInD;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,mBAAmB,GAAG,MAAM,CAAC;IAEzC;;;OAGG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,GAAG,GAAG,MAAM,EACtB,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAmCpC"}
1
+ {"version":3,"file":"lookup.d.ts","sourceRoot":"","sources":["../../src/webfinger/lookup.ts"],"names":[],"mappings":";AACA,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAMnD;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,mBAAmB,GAAG,MAAM,CAAC;IAEzC;;;OAGG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,GAAG,GAAG,MAAM,EACtB,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAmCpC"}