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)
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.1 — the 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
- Install Page Assist 1.5.78 with default settings (CORS fix ON, Ollama URL =
http://127.0.0.1:11434). - Serve any local web app on
http://127.0.0.1:3080that sends a request (e.g. a POST) to its own origin. - DevTools → Network → inspect request headers.
- Observe
Origin: http://127.0.0.1(port lost) — expectedhttp://127.0.0.1:3080.
Root cause
src/libs/runtime.ts, urlRewriteRuntime (still present on main):
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:
url.hostnamenever includes the port (url.host/url.origindo), so the rewrittenOriginvalue ishttp://127.0.0.1even though the real origin ishttp://127.0.0.1:11434.- The DNR rule condition
requestDomains: [url.hostname]matches all requests to that hostname on any port (domain matching ignores ports), with norequestMethods/initiatorDomainsrestriction — so every request to127.0.0.1:*(e.g. 3080, 8188, …) from any page getsOriginoverwritten tohttp://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
requestMethodsand a port-bearingurlFilter), optionally restrictinitiatorDomains, so unrelated ports on the same hostname are not affected.
Environment
- Extension: 1.5.78 · Browser: Chrome · OS: macOS
Source: n4ze3m/page-assist