Skip to content

[Daxia] [ FastAPI ] Add dynamic CORS origin validation#7234

Closed
daxia778 wants to merge 1 commit into
UnsafeLabs:mainfrom
daxia778:daxia/fastapi-dynamic-cors-763
Closed

[Daxia] [ FastAPI ] Add dynamic CORS origin validation#7234
daxia778 wants to merge 1 commit into
UnsafeLabs:mainfrom
daxia778:daxia/fastapi-dynamic-cors-763

Conversation

@daxia778

Copy link
Copy Markdown

/claim #763

Summary

  • Add an opt-in DynamicCORSMiddleware while preserving the existing Starlette CORSMiddleware export.
  • Support sync and async allow_origin_func callbacks for per-request origin decisions.
  • Fall back to static allow_origins behavior when no callback is supplied.
  • Add cors_max_age for preflight Access-Control-Max-Age configuration.

Demo

https://github.com/daxia778/Bounty-Hunters/releases/download/issue-763-demo-de0559bc/fastapi-dynamic-cors-763-demo-de0559bc.mp4

Validation

  • UV_PYTHON=<Python 3.12> uv run python -m pytest tests/test_dynamic_cors_middleware.py -q
  • UV_PYTHON=<Python 3.12> uv run ruff check fastapi/middleware/cors.py tests/test_dynamic_cors_middleware.py
  • UV_PYTHON=<Python 3.12> uv run ruff format --check fastapi/middleware/cors.py tests/test_dynamic_cors_middleware.py
  • git diff --check

@github-actions

Copy link
Copy Markdown
Contributor

Unfortunately the changes in this PR didn't fully resolve the issue. Please rework your solution and submit a new pull request.

Make sure to review the acceptance criteria in the linked issue and verify all conditions are met before resubmitting. See CONTRIBUTING.md for guidelines.

@github-actions github-actions Bot closed this Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant