Add a typed, explicit CORS policy evaluator

オープン
#201 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
静か
領域
api, backend

調査の方向性

必要な契約とリンク先の WHATWG Fetch Standard の CORS セクションから始め、次にリポジトリの Roc request/response 型と real-listener のテストセットアップを見つけます。実装前に policy と result の境界を定義します。real-listener テストで、実際のケースと preflight ケース、正規化、wildcard/credential、Vary、デフォルト無効、キャッシュされたバリアントがカバーされれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
HTML
スター
110
フォーク
25
平均マージ
18時間 28分
マージ済み PR(30日)
16

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

roc-lang/basic-webserver のほかの issue

roc-lang/basic-webserver の issue をすべて見る

似ている issue

Backend & API Design の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。