urlRewriteRuntime rewrites Origin to "http://127.0.0.1" (port dropped) for ALL requests to 127.0.0.1:* — breaks local web apps on other ports (default settings)

Author: leiyin321Created Aug 14, 2026Updated Aug 16, 2026
Labelsbug

Describe the bug

When Page Assist is enabled, every request to any URL whose hostname is 127.0.0.1 (any port) gets its Origin request header forcibly rewritten to http://127.0.0.1the port is dropped — by the "Automatic Ollama CORS Fix" feature (default: ON).

Example: a web app served at http://127.0.0.1:3080 makes requests to its own backend. With the extension enabled, DevTools shows the outgoing Origin header as http://127.0.0.1 instead of http://127.0.0.1:3080. Disabling the extension fixes it immediately.

Related to #245 and #794, but those were "fixed" by adding the auto-CORS-fix toggle; this bug still exists with default settings because the rewrite itself is wrong.

Steps to reproduce

  1. Install Page Assist 1.5.78 with default settings (CORS fix ON, Ollama URL = http://127.0.0.1:11434).
  2. Serve any local web app on http://127.0.0.1:3080 that sends a request (e.g. a POST) to its own origin.
  3. DevTools → Network → inspect request headers.
  4. Observe Origin: http://127.0.0.1 (port lost) — expected http://127.0.0.1:3080.

Root cause

src/libs/runtime.ts, urlRewriteRuntime (still present on main):

typescript
const url = new URL(domain)                      // e.g. "http://127.0.0.1:11434"
const domains = [url.hostname]                   // ["127.0.0.1"] — port stripped
let origin = `${url.protocol}//${url.hostname}`  // "http://127.0.0.1" — port lost!

Two problems:

  1. url.hostname never includes the port (url.host / url.origin do), so the rewritten Origin value is http://127.0.0.1 even though the real origin is http://127.0.0.1:11434.
  2. The DNR rule condition requestDomains: [url.hostname] matches all requests to that hostname on any port (domain matching ignores ports), with no requestMethods / initiatorDomains restriction — so every request to 127.0.0.1:* (e.g. 3080, 8188, …) from any page gets Origin overwritten to http://127.0.0.1.

Impact

Any local web app on 127.0.0.1:<port> / localhost:<port> that validates the Origin header (CORS/CSRF) breaks while the extension is enabled with defaults. Same mechanism as #245 (Intel DSA) and #794 (ComfyUI); those were only worked around via the toggle.

Suggested fix

  • Use the full origin: let origin = url.origin (keeps the port), and
  • Scope the rule to the actual endpoint (e.g. add requestMethods and a port-bearing urlFilter), optionally restrict initiatorDomains, so unrelated ports on the same hostname are not affected.

Environment

  • Extension: 1.5.78 · Browser: Chrome · OS: macOS