diff --git a/src/google/adk/cli/trigger_routes.py b/src/google/adk/cli/trigger_routes.py index 2468f8306b1..722c37fb0fe 100644 --- a/src/google/adk/cli/trigger_routes.py +++ b/src/google/adk/cli/trigger_routes.py @@ -256,7 +256,7 @@ async def __call__(self, request: Request) -> None: ) if self._allowed_emails: if ( - not claims.get("email_verified") + claims.get("email_verified") is not True or claims.get("email") not in self._allowed_emails ): raise HTTPException( diff --git a/tests/unittests/cli/test_trigger_routes.py b/tests/unittests/cli/test_trigger_routes.py index d48e8c051bb..2b823a76afd 100644 --- a/tests/unittests/cli/test_trigger_routes.py +++ b/tests/unittests/cli/test_trigger_routes.py @@ -544,6 +544,69 @@ def _ok(token, request, audience): ) assert resp.status_code == 403 + @pytest.mark.parametrize("endpoint,payload", _TRIGGER_ENDPOINTS_AND_PAYLOADS) + @pytest.mark.parametrize("email_verified", ["false", "true", 1]) + def test_rejects_non_boolean_email_verified( + self, client_oidc_emails, monkeypatch, endpoint, payload, email_verified + ): + """The claim must be the boolean True; a truthy non-boolean is not verified.""" + + def _ok(token, request, audience): + return { + "aud": audience, + "email": "allowed@project.iam", + "email_verified": email_verified, + } + + monkeypatch.setattr( + trigger_routes_module.google_id_token, + "verify_oauth2_token", + _ok, + ) + resp = client_oidc_emails.post( + endpoint, + json=payload, + headers={"Authorization": "Bearer some.jwt.value"}, + ) + assert resp.status_code == 403 + assert "Untrusted token principal" in resp.json()["detail"] + + @pytest.mark.parametrize("endpoint,payload", _TRIGGER_ENDPOINTS_AND_PAYLOADS) + @pytest.mark.parametrize( + "email_verified_claim", + [{}, {"email_verified": None}], + ids=["missing", "none"], + ) + def test_rejects_missing_or_null_email_verified( + self, + client_oidc_emails, + monkeypatch, + endpoint, + payload, + email_verified_claim, + ): + """An absent or null email_verified claim is not verified.""" + + def _ok(token, request, audience): + return { + "aud": audience, + "email": "allowed@project.iam", + **email_verified_claim, + } + + monkeypatch.setattr( + trigger_routes_module.google_id_token, + "verify_oauth2_token", + _ok, + ) + resp = client_oidc_emails.post( + endpoint, + json=payload, + headers={"Authorization": "Bearer some.jwt.value"}, + ) + assert resp.status_code == 403 + assert "Untrusted token principal" in resp.json()["detail"] + @pytest.mark.parametrize("endpoint,payload", _TRIGGER_ENDPOINTS_AND_PAYLOADS) def test_accepts_allowed_email( self, client_oidc_emails, monkeypatch, endpoint, payload