Skip to content

Retry a signed GET/HEAD unsigned when it fails before a response (#33) - #34

Merged
jjohare merged 1 commit into
mainfrom
fix-33-unsigned-retry
Nov 28, 2026
Merged

jjohare merged 1 commit into
mainfrom
fix-33-unsigned-retry

Conversation

@melvincarvalho

Copy link
Copy Markdown
Contributor

Fixes #33.

Podkey's Authorization header turns a cross-origin GET into a non-simple request, so the browser sends a CORS preflight. Static hosts such as GitHub Pages don't answer it, the fetch rejects with a TypeError, and public files stop loading once the user is logged in (seen on mindstr.org loading a map from github.io).

Change

The fetch wrapper tries once more without its own header when all of these hold:

  • Podkey signed the request (never when the page set its own Authorization)
  • the method is GET or HEAD
  • the failure is a TypeError, not an abort

Writes and the existing 401 retry are unchanged. If the caller passed no headers, the retry drops the key again, so a Request input keeps its own headers.

shouldRetryUnsigned and withoutAuthorization live in src/auth-header-utils.js, with a copy in the interceptor as for the existing helpers (#7). XHR is left as it is: its errors arrive asynchronously, so it would need a different approach.

Tests

test/unsigned-retry.test.js: 13 tests, covering the helpers and the real interceptor in a vm sandbox whose fake network rejects any request carrying Authorization. The two interceptor retry tests fail without the fix. npm test: 242 of 242 pass, and eslint src/ is clean.

Not yet checked in a real browser with the extension loaded.

Podkey's Authorization header turns a cross-origin GET into a non-simple
request, so the browser sends a CORS preflight. Static hosts such as GitHub
Pages don't answer it, the fetch rejects with a TypeError, and public files
stop loading once the user is logged in.

The fetch wrapper now tries once more without its own header when Podkey
signed the request, the method is GET or HEAD, and the failure is a
TypeError rather than an abort. Page-set auth, writes and the 401 retry
are unchanged. XHR is left as it is: its errors are asynchronous.

The helpers live in auth-header-utils.js with a copy in the interceptor,
as for the existing ones (#7).
@jjohare
jjohare merged commit 7e5923c into main Nov 28, 2026
2 checks passed
@jjohare

jjohare commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Merged. Reviewed as part of a re-audit of main at bd39ce8; the PR tree passes 242/242 and lint, and the two interceptor retry tests fail against main's interceptor, so they do test the fix.

Checked and sound: a Request input keeps its own headers, cache and credentials on the unsigned retry; a GET Request is reusable for the retry; the signal is carried over; AbortSignal.timeout (TimeoutError) is not retried; an unsigned 401 is returned with no loop; other network failures cost one extra failing request and nothing else. Forcing the downgrade gets an attacker only the public view of a resource.

Follow-ups, none blocking:

  1. The wrapper writes into the caller's init. options = options || {} keeps the caller's object, so Authorization is added to it in place (pre-existing on main). A page that reuses one init for two GETs to a static host gets a 200 on the first and a throw on the second: the leftover header makes the second call look page-authenticated, so it is neither re-signed nor retried. Copying init and its headers before signing fixes it; PR to follow.
  2. Tests. The fake fetch in test/unsigned-retry.test.js reads only init.headers, so a Request's own headers are never observed; building new Request(url, init) in the fake would. "keeps the page's other headers" does not assert that Accept survives. Worth adding a Request-input case and an aborted-signal case at interceptor level.
  3. Visibility. The fallback logs only under DEBUG. A pod whose CORS fails only for signed requests will quietly serve the public view; a console.warn once per origin would make that diagnosable.
  4. Cost. Every GET to such a host pays signing, a failed preflight and a retry for the life of the page. A per-origin in-memory set of hosts that failed preflight (about four lines) would send later GETs unsigned first, and would cover XHR too, which is still unfixed.

Still not exercised in a real browser, as the description says.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Signed fetches to static hosts fail CORS preflight; retry unsigned on network error

2 participants