Add typed request-cookie parsing and Set-Cookie rendering

Aperta
#199 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@lukewilliamboswell ci sta già lavorando.

Dal 31/7/2026.

  • #207 di @lukewilliamboswell — aperta

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
42/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Ambito
api, backend, security

Direzione di ricerca

Inizia individuando l’accesso all’header della richiesta utilizzato da request.headers() e la rappresentazione dell’header della risposta per campi Set-Cookie separati. Definisci il modulo Cookie puro attorno alle API parse_request e set_header illustrate, quindi aggiungi i test indicati per il parsing, la validazione, i prefissi, SameSite, l’eliminazione e gli header duplicati. Il lavoro è completo quando tutti i criteri di accettazione sono soddisfatti senza modificare l’ABI dell’host.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

Add a pure Cookie module for:

  1. Parsing all Cookie request header fields while preserving duplicates.
  2. Strictly rendering one Set-Cookie header from typed attributes.
  3. Rendering a deletion cookie with matching Path and Domain.

Illustrative API:

cookies = Cookie.parse_request(request.headers())?

header = Cookie.set_header({
    name: "session",
    value: session_id,
    path: Present("/"),
    domain: Absent,
    max_age_seconds: Present(3600),
    secure: True,
    http_only: True,
    same_site: Present(Lax),
})?

Why this belongs in the platform

Cookies are a conventional HTTP primitive needed by sessions, authentication, CSRF protection, and browser-facing applications. Hand-building cookie strings is error-prone because Set-Cookie has unusual header semantics and security-sensitive attribute combinations.

The current cookie specification permits multiple Set-Cookie fields and forbids combining them with commas. Servers must also tolerate multiple request Cookie fields, particularly because HTTP/2 and HTTP/3 intermediaries may split them.

Required contract

  • Parse every case-insensitive Cookie header field.
  • Preserve cookie order and duplicate names as a List, not a dictionary.
  • Treat names as case-sensitive.
  • Provide an explicit get_unique helper that reports duplicates instead of silently choosing one.
  • Validate names and values against the cookie grammar and reject control characters or header injection.
  • Do not implicitly percent-encode, Base64-encode, or reinterpret values.
  • Render each cookie as its own Set-Cookie header.
  • Support Path, Domain, Max-Age, Secure, HttpOnly, and SameSite.
  • Reject SameSite=None without Secure.
  • Enforce the __Secure- and __Host- prefix requirements.
  • A deletion helper must accept the original Path and Domain scope and emit an empty value with Max-Age=0.
  • Header resource use remains bounded by the server's existing header limits.

Expires, Partitioned, cookie priority, and browser cookie-jar behavior can be follow-ups. Max-Age provides the initial persistent-expiry and deletion contract without introducing a general calendar API.

Tests

Include multiple header fields, duplicate names, case-sensitive names, whitespace, empty values, invalid bytes, commas, CR/LF injection, prefix rules, SameSite=None, and multiple independent Set-Cookie response headers.

Non-goals

  • A browser cookie jar with domain/path matching
  • Signed or encrypted cookies
  • Sessions or authentication
  • Public-suffix-list processing
  • Automatic mutation of every request or response
  • Selecting one duplicate cookie based on serialization order

Acceptance criteria

  • Applications can parse all request cookie fields without losing duplicates.
  • Applications can render security-sensitive cookie attributes through typed values.
  • Multiple response cookies remain multiple Set-Cookie fields.
  • Invalid values and unsafe attribute combinations produce typed errors.
  • The implementation is pure Roc and requires no host ABI change.

References

Lingua principale
HTML
Stelle
110
Fork
25
Merge medio
18h 28m
PR unite (30g)
16

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di roc-lang/basic-webserver

Tutte le issue di roc-lang/basic-webserver

Issue simili

Altre issue su Backend & API Design

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.