FIX: Add destination allowlist before forwarding Bearer credential to Graph in EntraAuthMiddleware#2183
Open
jsong468 wants to merge 1 commit into
Open
FIX: Add destination allowlist before forwarding Bearer credential to Graph in EntraAuthMiddleware#2183jsong468 wants to merge 1 commit into
jsong468 wants to merge 1 commit into
Conversation
| } | ||
|
|
||
| # Hosts the user's Bearer token may be forwarded to | ||
| _GRAPH_HOSTS: ClassVar[set[str]] = {"graph.microsoft.com"} |
Contributor
There was a problem hiding this comment.
could we avoid sending the request to the endpoint supplied in the JWT? Entra adds _claim_sources when a user belongs to too many groups for all group IDs to fit in the token (typically more than 200). Since the Graph API path is known, constructing it from a trusted, deployment-configured base URL would prevent token data from controlling the request path or port. something like :
class EntraAuthMiddleware(BaseHTTPMiddleware):
_GRAPH_HOSTS: ClassVar[set[str]] = {"graph.microsoft.com"}
_GRAPH_MEMBER_OBJECTS_URL: ClassVar[str] = (
"https://graph.microsoft.com/v1.0/me/getMemberObjects"
)
...
claim_name = claims.get("_claim_names", {}).get("groups")
claim_sources = claims.get("_claim_sources", {})
# Confirm that Entra indicated the groups list did not fit in the token.
if not claim_name or claim_name not in claim_sources:
logger.debug("No group overage claim source found")
return []
endpoint = self._GRAPH_MEMBER_OBJECTS_URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
EntraAuthMiddleware._resolve_excess_groups_asyncforwards the user's Bearer credential to a host derived from token claims (_claim_sources.src1.endpoint) and from the response body (@odata.nextLink) without an explicit allowlist. There is no check that these values resolve tograph.microsoft.combefore the credentialed request is made. This adds an explicit host + scheme allowlist before each request.This is not an exploitable bug today: the endpoint originates from a signature-validated JWT and pagination links come from a TLS-authenticated Graph response. The allowlist makes the safety property local and robust against future changes and hardens the currently-dead path before it is re-enabled (see the existing
NOTEabout the Graph audience migration).Changes
pyrit/backend/middleware/auth.py_GRAPH_HOSTSclass constant ({"graph.microsoft.com"}_is_trusted_graph_url()helper usingurlparse(...).hostname(correctly handles userinfo/port, sograph.microsoft.com@evil.com-style spoofs are rejected).POSTendpoint: refuse + log + return[]if untrusted.@odata.nextLinkin the pagination loop: refuse + log + break if untrusted.Tests
tests/unit/backend/test_auth_middleware.py_is_trusted_graph_url(legit Graph URLs vs.http://, wrong host, suffix-spoof, userinfo-spoof, empty).[]and makes no HTTP request (token is never forwarded).