Add a typed, explicit CORS policy evaluator

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

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

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

Direzione di ricerca

Inizia dal contratto richiesto e dalle sezioni CORS collegate del WHATWG Fetch Standard, quindi individua i tipi request/response di Roc del repository e la configurazione dei test con real-listener. Definisci i confini della policy e del risultato prima dell'implementazione. Il lavoro è completo quando i test con real-listener coprono i casi effettivi e preflight, la normalizzazione, wildcard/credential, Vary, la disabilitazione predefinita e le varianti memorizzate nella cache.

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

Descrizione

Summary

Add a pure Cors module that evaluates actual and preflight requests against an immutable policy.

Illustrative flow:

match Cors.evaluate(policy, request) {
    NotCors => handle(request)
    Preflight(response) => Ok(Server.respond(response))
    Rejected(response) => Ok(Server.respond(response))
    Allowed(cors_headers) => {
        response = handle(request)?
        Ok(Server.respond(Cors.apply(cors_headers, response)?))
    }
}

Why this belongs in the platform

CORS is widely supplied by web-framework middleware, including tower-http. Its header interactions are sufficiently subtle that applications should not independently reproduce them.

It should remain an explicit Roc request/response transformation. It does not require a new middleware runtime or host callback.

Required contract

  • CORS is disabled unless an application constructs and invokes a policy.
  • Exact serialized origins—scheme, host, and port—are the initial allowlist mechanism.
  • Treat the special null origin as denied unless explicitly allowed.
  • Validate requested methods and header names for preflight requests.
  • Support configured exposed headers, credential permission, and bounded preflight max age.
  • Reject policy construction that combines credentialed requests with wildcard origin.
  • Dynamic origin responses merge Vary: Origin case-insensitively without discarding existing Vary values.
  • Access-Control-Allow-Credentials must serialize as lowercase true.
  • Preflight responses do not depend on receiving credentials; browsers do not attach credentials to the preflight itself.
  • Malformed or conflicting Origin fields produce a deterministic denial.
  • The result distinguishes non-CORS, allowed actual, successful preflight, and rejected requests.

Documentation must emphasize that CORS is not CSRF protection. A "simple" cross-origin request can still perform a server-side action even when the browser refuses to expose its response.

Non-goals

  • Regex or suffix origin matching in the first version
  • Guessing trusted origins from Host or forwarded headers
  • CSRF protection
  • Authentication or authorization
  • Applying CORS automatically to native file or operational routes
  • A generic middleware stack

Acceptance criteria

  • Actual and preflight requests are handled from the same validated policy.
  • Wildcard/credentials and Vary behavior follow the Fetch Standard.
  • Origin, method, and header matching have explicit case and normalization rules.
  • No CORS behavior is enabled by default.
  • Real-listener tests cover allowed, denied, credentialed, and cached variants.

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.