Skip to content

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

Open
melvincarvalho wants to merge 1 commit into
mainfrom
fix-33-unsigned-retry
Open

melvincarvalho wants to merge 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).

This branch has not been deployed

No deployments
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

1 participant