Use __Host- prefixed names for the dashboard session and challenge cookies

Open
#76 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
fastapi, python

Research direction

Start by reading the cookie handling in server/orcaster_server/deps.py and server/orcaster_server/auth/router.py, then trace the session lookups in auth/factory.py and the Origin check in main.py. Run or add the tests named in the acceptance criteria for secure and insecure settings, migration, challenge cookies, and logout. Done means those behaviors pass and an Unreleased CHANGELOG entry explains the old-cookie removal and promoted-session window.

Written by the indexing model from the issue text.

Description

enhancement P3 server

Problem

The dashboard session cookie is named session (server/orcaster_server/deps.py:37, passed as cookie_name at server/orcaster_server/main.py:330). The passkey challenge cookie is named webauthn_challenge (server/orcaster_server/auth/router.py:33). It is set when a login or a registration begins (server/orcaster_server/auth/router.py:147-155, :341), read when it completes (:162, :359) and deleted after (:186, :420). Neither uses the __Host- prefix.

Without the prefix, a page on a sibling subdomain can set a cookie with the same name for the parent domain. That allows login CSRF or session fixation: the victim ends up signed in as another account. The Origin check (server/orcaster_server/auth/origin.py:103) does not cover this case, because it only runs when the session cookie is already present.

A browser accepts a __Host- cookie only when it is Secure, has Path=/ and has no Domain. The session and challenge cookies already use path="/" and no Domain (server/orcaster_server/auth/router.py:121-130, server/orcaster_server/auth/router.py:147-155, server/orcaster_server/auth/router.py:340-348). Secure follows SESSION_COOKIE_SECURE, which defaults to false (server/orcaster_server/config.py:117) and is set to true by the server installer (setup-scripts/debian13/03-app-install.sh:161).

Proposed change

  1. When SESSION_COOKIE_SECURE is true, set the session cookie as __Host-session and the challenge cookie as __Host-webauthn_challenge. When it is false (local http development), keep the current names, because a browser rejects a __Host- cookie without Secure.
  2. Read the session in one helper used by server/orcaster_server/deps.py:66, server/orcaster_server/auth/factory.py:39, server/orcaster_server/auth/router.py:193 and server/orcaster_server/auth/router.py:282. It prefers the new name and falls back to the old one.
  3. When a request authenticates with the old name, set the new cookie with the same token and delete the old one.
  4. Every challenge cookie set and delete (server/orcaster_server/auth/router.py:147-155, :186, :341, :420) uses the new name. The challenge reads (:162 for login, :359 for registration) prefer __Host-webauthn_challenge and fall back to webauthn_challenge. The delete after a completed ceremony also removes the old name.
  5. The Origin check middleware (server/orcaster_server/main.py:348-352) treats either name as "session present".
  6. Logout deletes both names.

Compatibility

  • Signed-in users are not logged out by the upgrade. The old session cookie is still accepted for one release and is replaced by __Host-session on the next request.
  • Deployments with SESSION_COOKIE_SECURE=false keep the current names and see no change.
  • The challenge cookie lives for minutes only (challenge_ttl_seconds, server/orcaster_server/auth/config.py:51). A login or registration that began before the upgrade still completes, because the challenge reads fall back to the old name (step 4).
  • Step 3 promotes any old-name session cookie, including one planted from a sibling subdomain. So the fixation risk lasts until the fallback is removed, plus up to session_ttl_seconds (30 days, server/orcaster_server/auth/config.py:48) for sessions promoted from the old name. The release that drops the old name also revokes sessions promoted from it, or the release note documents this residual window. That release is announced in the CHANGELOG.
  • The challenge cookie fallback only needs to cover challenge_ttl_seconds after the upgrade. It can be dropped earlier than the session fallback.
  • API clients that use a PAT bearer token are not affected.

Acceptance criteria

  • With SESSION_COOKIE_SECURE=true, login sets __Host-session with Secure, HttpOnly, Path=/ and no Domain (test).
  • With SESSION_COOKIE_SECURE=false, login sets session as today (test).
  • A request with only the old session cookie is authenticated, and the response sets __Host-session and deletes session (test).
  • When both cookies are present, the __Host- one wins (test).
  • The Origin check rejects a cross-origin unsafe request that carries either cookie name (test).
  • Logout clears both names (test).
  • With SESSION_COOKIE_SECURE=true, a login and a registration that began with the old webauthn_challenge cookie still complete, and the old cookie is deleted (tests).
  • Login and registration begin set __Host-webauthn_challenge, and the complete steps delete it (tests).
  • The old cookie is still accepted for one release, so existing sessions survive the upgrade.
  • CHANGELOG entry under Unreleased that names the new cookie names and the release that drops the old ones, and how sessions promoted from the old name are revoked or how long they can remain.
Dominant language
Python
Stars
0
Forks
0
Avg merge
1d 1h
Merged PRs (30d)
10

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from AInvirion/orcaster

All issues in AInvirion/orcaster

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.