[object Object]

← back to Api Token Dashboard

creds-safe fetch guard: resolve relative fetch vs credential-free location (creds-in-URL trap)

eb04cf870ecb5a0a1582521d86eb0202f7c7c53d · 2026-08-25 10:53:20 -0700 · Steve

Fleet inoculation (server.mjs app, missed by the server.js sweep). Ref: creds-in-url-fetch-guard-fleet-pattern.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Files touched

Diff

commit eb04cf870ecb5a0a1582521d86eb0202f7c7c53d
Author: Steve <steve@designerwallcoverings.com>
Date:   Tue Aug 25 10:53:20 2026 -0700

    creds-safe fetch guard: resolve relative fetch vs credential-free location (creds-in-URL trap)
    
    Fleet inoculation (server.mjs app, missed by the server.js sweep). Ref: creds-in-url-fetch-guard-fleet-pattern.
    
    Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---
 public/index.html | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/public/index.html b/public/index.html
index bf99d8c..090d1b0 100644
--- a/public/index.html
+++ b/public/index.html
@@ -1,6 +1,30 @@
 <!doctype html>
 <html lang="en">
 <head>
+<script>
+// Credential-safe fetch guard (fleet drop-in) — if this page is opened with
+// credentials in the URL (a saved bookmark / Chrome-remembered basic-auth:
+// https://user:pass@host/…), the browser poisons document.baseURI, so any
+// relative or root-relative fetch('/api/…') throws "Request cannot be constructed
+// from a URL that includes credentials" and callers silently fall to an empty
+// state. Resolve every non-absolute request URL against the credential-free
+// location instead of baseURI. Placed first so it wraps window.fetch before any
+// app script runs. Ref: creds-in-url-fetch-guard-fleet-pattern.
+(function () {
+  var _fetch = window.fetch.bind(window);
+  var cleanBase = function () { return location.origin + location.pathname; };
+  window.fetch = function (input, init) {
+    try {
+      if (typeof input === 'string' && !/^[a-z]+:\/\//i.test(input) && input.indexOf('//') !== 0) {
+        input = new URL(input, cleanBase()).href;
+      } else if (input instanceof Request && !/^[a-z]+:\/\//i.test(input.url)) {
+        input = new Request(new URL(input.url, cleanBase()).href, input);
+      }
+    } catch (_) { /* fall through to native */ }
+    return _fetch(input, init);
+  };
+})();
+</script>
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <title>API &amp; Token Connections</title>

← ae39b00 nav-agent: sync v1.3 (host left-sidebar collapse on load)  ·  back to Api Token Dashboard  ·  (newest)