fix: Add JWT signature validation for OAuth connectors#1956
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Build successful! ✅ |
- Add jwt_verification.py with Google ID token and Microsoft access token validation - Add GOOGLE_OAUTH_CLIENT_ID and MICROSOFT_GRAPH_OAUTH_CLIENT_ID to settings - Implements signature verification using JWKS from OAuth providers Part of JWT validation security enhancement (cherry-picked from f0c1108)
- Add JWT verification to Google Drive oauth.py for ID tokens - Add JWT verification to OneDrive oauth.py for access tokens - Add JWT verification to SharePoint oauth.py for access tokens - Validates tokens when acquired to ensure authenticity and integrity This integrates the JWT validation security enhancements from PR #1907 into the release-cpd-0.1 OAuth implementation.
- Add 'from e' to all exception re-raises in jwt_verification.py - Replace deprecated typing.Dict/Optional with dict/| None in sharepoint/oauth.py - Remove unused typing imports - Fix B904 error in sharepoint exception handling
…udience, fix v1/v2 JWKS endpoint, fix issuer validation algorithm
Summary
Introduces cryptographic JWT token verification for the Google Drive, OneDrive, and SharePoint OAuth connectors. A new
src/utils/jwt_verification.pyutility validates tokens against their respective JWKS endpoints following Microsoft's documented multi-tenant token validation algorithm (RFC 7519 / RFC 8725 / Microsoft identity platform docs). OAuth connections that return a token with an invalid signature, expired expiry, or mismatched issuer are now rejected at the point of token acquisition rather than silently passed through.Motivation
IBM security compliance requires cryptographic verification of OAuth tokens received from external identity providers (Microsoft Entra ID, Google). Previously, tokens obtained via MSAL and Google OAuth were accepted without any signature or claims validation.
Changes
src/utils/jwt_verification.py(new file)verify_google_id_token()— RS256 signature, expiry, audience, issuer hardcoded toaccounts.google.comverify_microsoft_access_token()— implements Microsoft's documented algorithm:audis a resource we don't own (e.g. MS Graph00000003-…) are not signature-verified — per MS docs "you can't validate tokens for Microsoft Graph". Full verification only applies whenaud == MICROSOFT_GRAPH_OAUTH_CLIENT_IDiss = sts.windows.net/…) use/discovery/keys; v2 tokens use/discovery/v2.0/keysissuerproperty from the matched key entry in the JWKS document, substitutes the{tenantid}placeholder with the token'stid, requires exact match againstiss— per Microsoft's published pseudo-codeMICROSOFT_ALLOWED_TENANT_IDSis set, the verifiedtidmust be in the listJWTVerificationError,InvalidSignatureError,ExpiredTokenError,InvalidAudienceError,InvalidIssuerErrorsrc/connectors/google_drive/oauth.py_verify_id_token()raises on failure instead of silently returningNoneload_credentials()and athandle_authorization_callback()— connection rejected before credentials are persistedsrc/connectors/sharepoint/oauth.pyandsrc/connectors/onedrive/oauth.py_verify_access_token()raises on failure across all token acquisition paths (get_access_token,get_access_token_for_resource)MICROSOFT_ALLOWED_TENANT_IDSthrough to the verification functionsrc/utils/env_utils.py— newget_env_set()helper (comma-separated env var →set[str] | None,Nonemeans unset/skip check)src/config/settings.py— addsMICROSOFT_ALLOWED_TENANT_IDS = get_env_set("MICROSOFT_ALLOWED_TENANT_IDS")src/tui/config_fields.pyandsrc/tui/managers/env_manager.py— surfacesMICROSOFT_ALLOWED_TENANT_IDSin the TUI wizard with descriptive helper textSecurity compliance
Behaviour changes
No breaking change for existing deployments. MS Graph access tokens (the majority of MSAL-issued tokens in this flow) have
aud = 00000003-0000-0000-c000-000000000000and are passed through per the Microsoft docs.MICROSOFT_ALLOWED_TENANT_IDSis unset by default.Failure mode change: a token that previously produced a warning log and was silently returned now raises
JWTVerificationError, propagating as a 401 at the API layer. This is the intended behaviour.