Skip to content

Cross-realm detection of Headers/Request in content script #8

Not planned

Description

@melvincarvalho

Follow-up surfaced during #6 review.

Problem

src/injected.js runs in the content-script isolated world. Headers, Request, and Response constructors in the isolated world are different objects than the ones on the page. So:

  • headers instanceof Headers returns false for a Headers object the page created.
  • input instanceof Request returns false for a Request the page created.

The page's fetch is actually intercepted by nip98-interceptor.js (which runs in page realm), so the practical impact is limited — the injected.js fetch override only catches content-script-initiated fetches where objects share the isolated-world realm.

But the code is still technically incorrect and could misbehave if, for example, the extension ever intercepts a page-created Request via message passing or starts sharing objects across realms.

Proposed fix

Replace instanceof checks with cross-realm-safe alternatives:

  • Duck-typing: typeof headers?.has === 'function' && typeof headers?.get === 'function'
  • Or Symbol.toStringTag === 'Headers' / Object.prototype.toString.call(...)

Apply in hasAuthorizationHeader, fetchCallHasAuthorization, setAuthorizationOnOptions, normalizeFetchCall.

Scope note

Not fixing in #6 because that PR is scoped to the auth-overwrite bug and this is a correctness hardening that doesn't currently manifest in practice.

Activity

  1. jjohare commented on Nov 28, 2026

    @jjohare
    Collaborator

    Closing as moot. Re-audited against main at bd39ce8: src/injected.js no longer wraps fetch at all (the double interception was removed in #22, see the note at src/injected.js:5-8), so there are no instanceof Headers / instanceof Request checks left in the isolated world to get wrong.

    The page-realm equivalent was checked too. A Headers object built in an iframe's realm fails instanceof in src/nip98-interceptor.js, Object.keys on it returns [], and Podkey then simply does not sign; the page's own auth is kept. That fails safe, so nothing to fix there either.

    Reopen if a cross-realm path comes back.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions