Skip to content

NIP-98 interceptor: correctness bugs found in re-audit (sync XHR, Request headers, relative URLs) #35

Done

Description

@jjohare

From a re-audit of main at bd39ce8. All in src/nip98-interceptor.js unless noted; each was reproduced in a vm-sandbox probe or confirmed by reading. Ordered by how many users are affected. #9 and #5 belong to the same family and stay tracked on their own issues.

  • Synchronous XHR is broken on every site (:237-252). send is an async function, so the native send runs only after the signing round trip. open('GET', u, false); send() returns at once with status 0 and an empty responseText. This affects every page, whether or not the user has a key, because the round trip always happens. Also: send() returns a Promise, and an abort() before the deferred send leaves an unhandled InvalidStateError. Fix: record the async flag in open; pass synchronous requests straight to the native send, unsigned.
  • The wrapper writes into the caller's init (:160-181, and the 401 path at :205-206). See follow-up 1 on Retry a signed GET/HEAD unsigned when it fails before a response (#33) #34 and the second case on Don't overwrite existing Authorization headers (breaks Solid-OIDC/DPoP) #5. Fix: copy init and its headers before writing to them.
  • A signed Request input loses all its own headers (:61-62 with :181). fetch(new Request(url, { headers: { Accept: 'text/turtle' } })) becomes fetch(req, { headers: { Authorization } }), and per the fetch spec init.headers replaces the Request's. Accept, Content-Type and If-Match are gone from the wire, which breaks content negotiation and conditional writes. Fix: when the input is a Request and init has no headers, seed with new Headers(input.headers).
  • Relative URLs are never signed (:87, :240, src/background.js:693). fetch('/profile/card') reaches the service worker unresolved, new URL() throws, the error is caught and no token is produced; the 401 retry fails the same way. Apps served from the pod itself get no NIP-98. A #fragment is also passed into the u tag. Fix: new URL(x, document.baseURI), clear the hash, send .href.
  • Every request on every site waits for the extension, and bodies are hashed before trust is known (:98-116, :148, :179). Each fetch and XHR does a page → content script → service worker round trip, with a 2 s fallback if the worker is slow to wake. A Blob body is read fully into memory and SHA-256 hashed first, on any site. Fix: ask "will you sign for this target?" first and hash only after a yes.
  • Method case (:82, :88). { method: 'get' } signs a method tag of get while the wire method is GET; strict servers reject the token. Fix: .toUpperCase().
  • XHR has no unsigned fallback for the Signed fetches to static hosts fail CORS preflight; retry unsigned on network error #33 case. A per-origin memo of hosts that failed preflight (follow-up 4 on Retry a signed GET/HEAD unsigned when it fails before a response (#33) #34) would cover both fetch and XHR.

Test gap behind several of these: the fake fetch in the sandbox tests reads init.headers only and never builds a real Request, so header replacement and Request-input behaviour are invisible to the suite.

Activity

  1. added
    bug
    on Nov 28, 2026
  2. jjohare commented on Nov 28, 2026

    @jjohare
    CollaboratorAuthor

    Fixed in 0.0.13 (a2265b7): synchronous XHR passes straight through, the caller's options and headers are never written to, a Request keeps its own headers, relative URLs are signed with the fragment left out, bodies are hashed only once the worker has decided to sign, and hosts that refuse signed requests are remembered for XHR as well as fetch. The method tag was fixed in 0.0.12. What is left is in #47.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions