Skip to content

[Bug]: requireAuth throws on missing/malformed Host header; token saves requested during an in-flight save are dropped #504

Closed

Description

@ArnabOPP

Describe the bug

Two small server-side bugs, both fixed in #503.

1. requireAuth can throw (src/server/signalling/utils.ts)
When a non-loopback request has no Authorization header, it falls back to ?token= by calling new URL(req.url, "http://" + req.headers.host). If the Host header is missing or malformed, new URL throws, so the caller gets an unhandled exception instead of a 401.

2. Token save can be dropped (src/server/tokenStore.ts)
save() returns early when isSaving is true, even for save(true). A forced save requested while another is in flight (new token, expiry purge) is silently lost until the next save. The window is narrow, so this is a hardening issue.

Steps to reproduce

  1. Send an unauthenticated request from a non-loopback address with no Host header and a ?token= query, to an endpoint that uses requireAuth.
  2. Observe an exception rather than a 401 response.

Expected behavior

requireAuth returns 401 (or authenticates via ?token=); every forced token save is persisted.

Additional context

Neither module has unit tests; #503 adds some. AI assistance (Claude) was used to find and fix these.

Activity

  1. github-actions commented on Nov 19, 2026

    @github-actions

    Discussions are carried on Discord.

    Instead of commenting here, go to the Discord channel.

    macOS and macOS-related issues are not supported at the moment. We are looking for funding to support macOS and would appreciate sponsorships.

    If you find this project useful, a GitHub star would be appreciated.

  2. gitcordapp commented on Nov 20, 2026

    @gitcordapp

    Link your account with Gitcord

    Thanks for opening this issue, @ArnabOPP!

    To receive Discord notifications and contributor tracking for this organization:

    1. Join Discord: https://discord.gg/hjUhu33uAn
    2. In Discord, run /link ArnabOPP
    3. Paste the verification code into your GitHub bio (or a public gist)
    4. Click Verify in Discord (or run /verify-link ArnabOPP)

    Once linked, Gitcord can notify you about assignments, mentions, and more.

    — Posted by Gitcord

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

    bugSomething isn't workingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions