Skip to content

Commit a67a3b9

Browse files
Vamsi-kluclaude
andcommitted
Make CORS allow_credentials configurable instead of hardcoded True
Add [api] access_control_allow_credentials config option (default: False) to replace the hardcoded allow_credentials=True in CORSMiddleware. Also log a warning when credentials are enabled with wildcard origins, as this creates CSRF risk. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7d29a78 commit a67a3b9

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

airflow/api_fastapi/core_api/app.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,18 @@ def init_config(app: FastAPI) -> None:
147147
allow_origins = conf.getlist("api", "access_control_allow_origins")
148148
allow_methods = conf.getlist("api", "access_control_allow_methods")
149149
allow_headers = conf.getlist("api", "access_control_allow_headers")
150+
allow_credentials = conf.getboolean("api", "access_control_allow_credentials", fallback=False)
150151

151152
if allow_origins or allow_methods or allow_headers:
153+
if allow_credentials and "*" in allow_origins:
154+
log.warning(
155+
"CORS allow_credentials is True with wildcard (*) in allow_origins. "
156+
"This is a security risk. Consider specifying explicit origins."
157+
)
152158
app.add_middleware(
153159
CORSMiddleware,
154160
allow_origins=allow_origins,
155-
allow_credentials=True,
161+
allow_credentials=allow_credentials,
156162
allow_methods=allow_methods,
157163
allow_headers=allow_headers,
158164
)

airflow/config_templates/config.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,16 @@ api:
14341434
version_added: 2.2.0
14351435
example: ~
14361436
default: ""
1437+
access_control_allow_credentials:
1438+
description: |
1439+
Indicates whether the response to the request can be exposed when the credentials flag is true.
1440+
When used as part of a response to a preflight request, this indicates whether or not the
1441+
actual request can be made using credentials. Setting this to True with a wildcard (*) in
1442+
access_control_allow_origins is a security risk.
1443+
type: boolean
1444+
version_added: 3.0.0
1445+
example: ~
1446+
default: "False"
14371447
enable_xcom_deserialize_support:
14381448
description: |
14391449
Indicates whether the **xcomEntries** endpoint supports the **deserialize**

0 commit comments

Comments
 (0)