Skip to content

Build your personal knowledge base with Trilium Notes

fix(server): refuse AWS's IPv6 metadata endpoint on the operator path

Elian Doranc4b2cd70170e
diff --git a/SECURITY.md b/SECURITY.md
index e66309d36d..f6b09f0292 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -85,7 +85,7 @@ An LLM provider's base URL is not note content, and the same rule cannot apply t
Reports that reduce to "an authenticated user can point the LLM base URL at a host on the local network, and the server connects to it" are therefore out of scope, including the reachability and port information that connecting necessarily reveals.
-Carrier-grade NAT (`100.64.0.0/10`) is permitted on the same terms, because a Tailscale tailnet assigns its nodes addresses there. What stays refused is what no model server is ever served on: link-local (`169.254.0.0/16`, which is where a cloud instance answers with its own credentials) and the metadata endpoint inside carrier-grade NAT (`100.100.100.200`). Redirects are not followed on these requests at all, since the hop would carry the configured API key to whoever the endpoint named. Defects in **those** guards are in scope, as is any path that reaches them without authentication.
+Carrier-grade NAT (`100.64.0.0/10`) is permitted on the same terms, because a Tailscale tailnet assigns its nodes addresses there. What stays refused is what no model server is ever served on: link-local (`169.254.0.0/16`, which is where a cloud instance answers with its own credentials) and the metadata endpoints inside the permitted ranges (`100.100.100.200` in carrier-grade NAT, `fd00:ec2::254` in unique-local). Redirects are not followed on these requests at all, since the hop would carry the configured API key to whoever the endpoint named. Defects in **those** guards are in scope, as is any path that reaches them without authentication.
#### Denial of Service via Resource Exhaustion
Creating extremely large notes or performing many operations is expected user behavior in a note-taking application.
diff --git a/apps/server/src/services/safe_fetch.spec.ts b/apps/server/src/services/safe_fetch.spec.ts
index 96e30d3cbd..dd3f231b6b 100644
--- a/apps/server/src/services/safe_fetch.spec.ts
+++ b/apps/server/src/services/safe_fetch.spec.ts
@@ -187,6 +187,8 @@ describe("validateHostResolution, for a destination the operator configured", ()
await expect(validateHostResolution("169.254.1.1", true)).rejects.toThrow("link-local");
await expect(validateHostResolution("100.100.100.200", true)).rejects.toThrow("metadata endpoint");
await expect(validateHostResolution("::ffff:100.100.100.200", true)).rejects.toThrow("metadata endpoint");
+ await expect(validateHostResolution("fd00:ec2::254", true)).rejects.toThrow("metadata endpoint");
+ await expect(validateHostResolution("FD00:0EC2:0:0:0:0:0:0254", true)).rejects.toThrow("metadata endpoint");
await expect(validateHostResolution("fe80::1", true)).rejects.toThrow("link-local");
await expect(validateHostResolution("0.0.0.0", true)).rejects.toThrow("link-local");
await expect(validateHostResolution("224.0.0.1", true)).rejects.toThrow("link-local");
diff --git a/apps/server/src/services/safe_fetch.ts b/apps/server/src/services/safe_fetch.ts
index 6adfb22e35..9992689811 100644
--- a/apps/server/src/services/safe_fetch.ts
+++ b/apps/server/src/services/safe_fetch.ts
@@ -26,8 +26,12 @@ const ALLOWED_IP_RANGES = new Set(["unicast"]);
*/
const ALLOWED_IP_RANGES_INCLUDING_PRIVATE = new Set(["unicast", "loopback", "private", "uniqueLocal", "carrierGradeNat"]);
-/** Cloud metadata endpoints inside an allowed range, refused under every policy. */
-const METADATA_ADDRESSES = new Set(["100.100.100.200"]);
+/**
+ * Cloud metadata endpoints inside an allowed range, refused under every policy: Alibaba Cloud's
+ * in carrier-grade NAT and AWS's IPv6 one in unique-local. Listed in `ipaddr.js` `toString()`
+ * form, which `isBlockedIP` compares against.
+ */
+const METADATA_ADDRESSES = new Set(["100.100.100.200", "fd00:ec2::254"]);
/** How hard an address is vetted, and how long the caller is prepared to wait for it. */
export interface SafeFetchPolicy {