Add a typed, explicit CORS policy evaluator

Đang mở
#201 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Lĩnh vực
api, backend

Hướng nghiên cứu

Bắt đầu với contract bắt buộc và các phần CORS được liên kết của WHATWG Fetch Standard, sau đó tìm các kiểu request/response của Roc trong repository và thiết lập test với real-listener. Xác định ranh giới của policy và result trước khi triển khai. Được xem là hoàn tất khi các test với real-listener bao phủ các trường hợp thực tế và preflight, việc normalization, wildcard/credential, Vary, trạng thái disabled-by-default và các biến thể đã được cache.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
HTML
Star
110
Fork
25
Merge trung bình
18 giờ 28 phút
Pull request đã merge (30 ngày)
16

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của roc-lang/basic-webserver

Tất cả issue của roc-lang/basic-webserver

Issue tương tự

Thêm issue về Backend & API Design

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.