Resolves safe CORS origins and credentials from env variable for FastAPI.
# Source: https://github.com/yusufkaraaslan/Skill_Seekers | License: MIT | Copyright 2025 Yusuf Karaaslan
# Provided via justclaw.it.com; keep this notice with the code.
"""Shared CORS configuration resolver.
Browsers reject ``Access-Control-Allow-Credentials: true`` combined with a
wildcard ``Access-Control-Allow-Origin: *``. This module resolves a safe
``(allow_origins, allow_credentials)`` pair from the ``CORS_ORIGINS`` env var
so every FastAPI/Starlette server in the project shares one policy.
"""
from __future__ import annotations
import os
DEFAULT_CORS_ORIGINS = "*"
def resolve_cors_config(raw: str | None = None) -> tuple[list[str], bool]:
"""Resolve ``(allow_origins, allow_credentials)`` from a CORS_ORIGINS value.
- unset / empty / ``"*"`` (or any list containing ``"*
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key