Skip to content

ensureSessionID() doesn't validate session cookie value before using it as storage key #17718

Description

@wildfiremedia

Astro Info

Astro                    v7.2.2
Node                     v26.7.0
System                   macOS (arm64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations

If this issue only occurs in one browser, which browser is a problem?

NA

Describe the Bug

While going through the sessions module (runtime.ts), full disclosure, I was using Claude to help dig through the code, so flagging that upfront rather than presenting it as pure manual review — I found that #ensureSessionID() takes the session cookie value directly from the client and uses it as the storage key, with no format validation. This is inconsistent with the cookie name, which is checked against VALID_COOKIE_REGEX.

If the client-supplied session ID happens to collide with an existing key in the storage backend whose value isn't a valid session Map, it triggers destroy(). The request pipeline's finally block still flushes this as a real storage.removeItem() call, even though the request itself throws/500s.

Severity note: I checked the Node, Cloudflare, and Netlify adapter defaults — all give sessions their own isolated store out of the box, so this isn't exploitable under default config. It only matters if someone points the session driver at a storage backend shared with other data, without a key prefix.

Confirmed by a maintainer as low severity, filing per their request.

Suggested fix: Add a validation check on the session ID (mirroring VALID_COOKIE_REGEX used for the cookie name) as a safety net, so malformed/colliding values are rejected before being used as a storage key.

What's the expected result?

Session IDs supplied by the client should be validated against an expected format before being used as a storage key, so they can't collide with unrelated keys in a shared storage backend.

Link to Minimal Reproducible Example

NA

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P2: has workaroundAn edge case that only affects very specific usage, but has a trivial workaround (priority)pkg: astroRelated to the core `astro` package (scope)triage: fix pendingReporter needs to verify the triage bot fix works

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions