This is an automated email from the ASF dual-hosted git repository.
jason810496 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new d9e5446aaac Avoid logging Execution API bearer credentials (#67059)
d9e5446aaac is described below
commit d9e5446aaac4bf1b39d28a3245a3d39bcfbfb113
Author: leon.jeon <[email protected]>
AuthorDate: Wed May 27 23:39:51 2026 +0900
Avoid logging Execution API bearer credentials (#67059)
* Avoid logging Execution API bearer credentials
* Add newsfragment for Execution API bearer logging
* Avoid exposing JWT validation details
---
.../airflow/api_fastapi/execution_api/security.py | 6 ++--
.../api_fastapi/execution_api/test_security.py | 42 ++++++++++++++++++++++
2 files changed, 45 insertions(+), 3 deletions(-)
diff --git a/airflow-core/src/airflow/api_fastapi/execution_api/security.py
b/airflow-core/src/airflow/api_fastapi/execution_api/security.py
index df3b7993a08..98aee04cf33 100644
--- a/airflow-core/src/airflow/api_fastapi/execution_api/security.py
+++ b/airflow-core/src/airflow/api_fastapi/execution_api/security.py
@@ -123,9 +123,9 @@ class JWTBearer(HTTPBearer):
try:
claims = await validator.avalidated_claims(creds.credentials,
dict(self.required_claims))
- except Exception as err:
- log.warning("Failed to validate JWT", exc_info=True,
token=creds.credentials)
- raise HTTPException(status_code=status.HTTP_403_FORBIDDEN,
detail=f"Invalid auth token: {err}")
+ except Exception:
+ log.warning("Failed to validate JWT", exc_info=True)
+ raise HTTPException(status_code=status.HTTP_403_FORBIDDEN,
detail="Invalid auth token")
claims.setdefault("scope", "execution")
diff --git a/airflow-core/tests/unit/api_fastapi/execution_api/test_security.py
b/airflow-core/tests/unit/api_fastapi/execution_api/test_security.py
index 22b7f58a959..e98d9183859 100644
--- a/airflow-core/tests/unit/api_fastapi/execution_api/test_security.py
+++ b/airflow-core/tests/unit/api_fastapi/execution_api/test_security.py
@@ -20,9 +20,12 @@ from unittest.mock import MagicMock, patch
from uuid import UUID
import pytest
+import svcs
from fastapi import APIRouter, FastAPI, Request, Security
from fastapi.testclient import TestClient
+from structlog.testing import capture_logs
+from airflow.api_fastapi.auth.tokens import JWTValidator
from airflow.api_fastapi.execution_api.datamodels.token import TIClaims,
TIToken, TokenScope
from airflow.api_fastapi.execution_api.security import (
ExecutionAPIRoute,
@@ -158,6 +161,45 @@ class TestTokenTypeScopeEnforcement:
assert run.status_code == 200
+class TestJWTBearerLogging:
+ @pytest.fixture
+ def app(self):
+ app = FastAPI()
+ app.state.svcs_registry = svcs.Registry()
+
+ @app.get("/protected")
+ def protected(token: TIToken = Security(require_auth)):
+ return {"id": str(token.id)}
+
+ return app
+
+ @pytest.mark.parametrize(
+ "bearer_credential",
+ [
+ pytest.param("eyJ.invalid.jwt", id="jwt-looking-token"),
+ pytest.param("opaque-token-value", id="opaque-token"),
+ ],
+ )
+ def test_validation_failure_does_not_log_supplied_credential(self, app,
bearer_credential):
+ validator = MagicMock(spec=JWTValidator)
+ validator.avalidated_claims.side_effect = ValueError("invalid token")
+ app.state.svcs_registry.register_value(JWTValidator, validator)
+ client = TestClient(app)
+
+ with capture_logs() as logs:
+ response = client.get(
+ "/protected",
+ headers={"Authorization": f"Bearer {bearer_credential}"},
+ )
+
+ assert response.status_code == 403
+ assert response.json() == {"detail": "Invalid auth token"}
+
validator.avalidated_claims.assert_awaited_once_with(bearer_credential, {})
+ assert any(log["event"] == "Failed to validate JWT" for log in logs)
+ assert bearer_credential not in repr(logs)
+ assert "invalid token" not in response.text
+
+
class TestTiSelfScopeEnforcement:
"""Routes with the ``ti:self`` scope reject mismatched JWT subjects."""