BerriAI/litellm · error · HTTPException

SAML assertion did not contain an email address, but ALLOWED

Error message

SAML assertion did not contain an email address, but ALLOWED_EMAIL_DOMAINS restricts sign-in by email domain.

What it means

_result_from_auth enforces ALLOWED_EMAIL_DOMAINS: the deployment restricts sign-in by email domain, but the assertion supplies no email address to check, so access is denied with 401. At-fault condition is an IdP assertion lacking email attributes while domain restriction is active.

Source

Thrown at litellm/proxy/management_endpoints/sso/saml_sso.py:424

            key=consumed_key, value=1, ttl=SAMLAuthHandler._replay_guard_ttl(auth)
        )
        if consumed_count is not None and consumed_count > 1:
            raise HTTPException(
                status_code=status.HTTP_401_UNAUTHORIZED,
                detail="SAML assertion has already been used (replay detected).",
            )

    @staticmethod
    def _result_from_auth(auth: "OneLogin_Saml2_Auth") -> CustomOpenID:
        attributes: Final = cast(dict[str, list[str]], auth.get_attributes())  # cast-ok: untyped python3-saml
        name_id: Final = cast(str | None, auth.get_nameid())  # cast-ok: untyped python3-saml

        email = SAMLAuthHandler._attribute_value(attributes, "SAML_ATTRIBUTE_EMAIL", _EMAIL_ATTRIBUTE_CANDIDATES)
        if email is None and name_id is not None and "@" in name_id:
            email = name_id

        if email is None and SAMLAuthHandler._env("ALLOWED_EMAIL_DOMAINS") is not None:
            raise HTTPException(
                status_code=status.HTTP_401_UNAUTHORIZED,
                detail=(
                    "SAML assertion did not contain an email address, but ALLOWED_EMAIL_DOMAINS "
                    "restricts sign-in by email domain."
                ),
            )

        user_id: Final = SAMLAuthHandler._attribute_value(attributes, "SAML_ATTRIBUTE_USER_ID", ()) or name_id or email
        if user_id is None:
            raise HTTPException(
                status_code=status.HTTP_401_UNAUTHORIZED,
                detail="SAML assertion did not contain a usable subject (NameID) or email.",
            )

        first_name: Final = SAMLAuthHandler._attribute_value(
            attributes, "SAML_ATTRIBUTE_FIRST_NAME", _FIRST_NAME_ATTRIBUTE_CANDIDATES
        )
        last_name: Final = SAMLAuthHandler._attribute_value(

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Configure the IdP to send the email attribute, or remove ALLOWED_EMAIL_DOMAINS restriction.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/proxy/management_endpoints/sso/saml_sso.py:424 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/794fedf933eca532. Report an issue: GitHub.