Skip to content

Tighten CORS origin validation in AccessControlAllowOriginHeader #150

@coderabbitai

Description

@coderabbitai

Summary

Improve the AccessControlAllowOriginHeader class to enforce stricter validation of origin values and handle the CORS literal null value properly.

Background

During review of PR #146, it was identified that the current implementation could benefit from:

  1. Stricter origin validation: Origins should have scheme and host, but no path, query, fragment, or userInfo
  2. CORS null literal support: The literal string "null" is a valid CORS origin value that should be supported

Proposed Solution

Create a special class (possibly an extension type on Uri) to represent CORS origins with proper validation:

  • Add constructor assertions to ensure origins are valid (scheme + host present, no path/query/fragment/userInfo)
  • Support parsing and encoding the literal "null" value per CORS specification
  • Ensure proper round-trip behavior for all valid CORS origin values

Context

Acceptance Criteria

  • Create a dedicated CORS origin type with proper validation
  • Support literal "null" value parsing and encoding
  • Add comprehensive tests for valid/invalid origins
  • Ensure backward compatibility
  • Update AccessControlAllowOriginHeader to use the new type

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: headersIssues related to headers.enhancementNew feature or request

    Type

    No type

    Projects

    Status

    Backlog 🗂️

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions