Repository navigation
fix(bigquery-jdbc): use loopback binding, PKCE, and state verification in user account OAuth flow - #15241
Merged
Conversation
…n in user account OAuth flow
Contributor
There was a problem hiding this comment.
Code Review
This pull request significantly enhances the OAuth user authentication flow in the BigQuery JDBC driver by introducing a custom PKCE provider (Rfc7636PkceProvider) to comply with RFC 7636 and implementing a robust local HTTP callback server. The new server handles timeouts, drains headers, validates state parameters, and sanitizes error codes, backed by comprehensive unit tests. The review feedback highlights a robustness issue where catching any HttpCallbackException immediately aborts the authentication flow (which makes it fragile to local port probes) and recommends preserving the original exception as the cause when throwing BigQueryJdbcRuntimeException.
keshavdandeva
marked this pull request as draft
November 25, 2026 16:06
keshavdandeva
marked this pull request as ready for review
November 25, 2026 16:46
Neenu1995
reviewed
Nov 26, 2026
- Extract loopback callback socket/HTTP handling into package-private BigQueryJdbcOAuthCallbackServer and lower per-socket read timeout to 1000ms - Preserve literal '+' in callback query decoding and handle malformed '%' sequences as HttpCallbackException - Propagate explicit universeDomain override onto UserCredentials in getCredentialsFromCode and merge origin/main - Request Google Drive scope at authorization consent time when RequestGoogleDriveScope is enabled for OAuthType=1 - Raise callback header drain limit to 64 KiB, call shutdownOutput() after flushing responses, and add nosniff and CSP response headers - Document Desktop app OAuth client requirement in docs/USER_GUIDE.md
Neenu1995
approved these changes
Nov 27, 2026
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.
b/584840384
Summary
Aligns interactive user-account authentication (
OAuthType=1) inBigQueryJdbcOAuthUtilitywith RFC 8252 and RFC 7636, extracts the local loopback HTTP callback listener intoBigQueryJdbcOAuthCallbackServer, and ensuresRequestGoogleDriveScopeand explicituniverseDomainsettings apply to user-account credentials.What Changed & Why
getGoogleUserAccountCredentialschecksisDesktopBrowseSupported()(GraphicsEnvironment.isHeadless(),Desktop.isDesktopSupported(), andDesktop.Action.BROWSE) before opening a local socket, and wrapsBigQueryJdbcOAuthCallbackServerand acceptedSocketinstances intry-with-resourcesso the listener closes prior to token exchange and on any error or timeout.BigQueryJdbcOAuthCallbackServer):openLoopbackServerSocket()binds127.0.0.1(falling back to::1on IPv6-only hosts,backlog = 8) usingjava.net.ServerSocket(java.base, avoiding ajdk.httpservermodule dependency in customjlink/ OSGi runtimes) andbuildLoopbackCallbackUri()formatshttp://127.0.0.1:<port>orhttp://[::1]:<port>forgetUserAuthorizer. Matching the bound IP family avoidsConnection Refusederrors when the browser and JVM resolvelocalhostto different address families. (The 9-argumentgetGoogleUserAccountCredentialsand 1-argumentopenLoopbackServerSocketpackage-private overloads are deterministic test seams to which the production entry points delegate.)S256PKCE, OAuthstate, &RequestGoogleDriveScope: ConfiguredUserAuthorizerwithRfc7636PkceProvider(used instead ofDefaultPKCEProvider, which ingoogle-auth-library-oauth2-http1.58.0emits a 172-character=-paddedcode_verifieroutside RFC 7636 Section 4.1's 43–128 unreserved-character range), addedstategeneration and callback verification, and wiredRequestGoogleDriveScope(BIGQUERY_WITH_DRIVE_SCOPESvs.DEFAULT_BIGQUERY_SCOPES) at authorization consent time.universeDomainpropagation:getCredentialsFromCodepropagatesUNIVERSE_DOMAIN_OVERRIDE_PROPERTY_NAMEfromoverridePropertiesontoUserCredentials.Builder, matching non-JSON credential handling for custom universe domains.1000 msper-socket read timeout within the120 scallback window, skipping empty browser TCP preconnects, returning404 Not Foundfor secondary requests such as/favicon.ico, and continuing to listen after malformed or unverified HTTP requests (responding400 Bad Requestand recording the last rejected request reason in case the callback window times out).URI, UTF-8 URL-decodes query parameters while preserving literal+characters per RFC 3986 (code,state,error), and immediately aborts when astate-verified callback reports an OAutherror=or omitscode.64 KiBof request headers (accommodating127.0.0.1cookies) and callssocket.shutdownOutput()after flushing\r\n-formatted HTTP/1.1 responses (200 OK,400 Bad Request,404 Not Found) withCache-Control: no-store,X-Content-Type-Options: nosniff,Content-Security-Policy: default-src 'none',Connection: close, and exact UTF-8 byteContent-Length.docs/USER_GUIDE.md): Documented that customOAuthClientIdvalues used withOAuthType=1must be configured as a Desktop app OAuth 2.0 client.Compatibility Notes
OAuthType=1flows already used ephemeral ports (ServerSocket(0)), which require a Google Desktop app OAuth 2.0 client (default or customOAuthClientId). Google Desktop OAuth clients natively supporthttp://127.0.0.1:<port>andhttp://[::1]:<port>redirect URIs andS256PKCE without Cloud Console changes.Testing
BigQueryJdbcOAuthUtilityTestcoversS256PKCE challenge/verifier exchange,RequestGoogleDriveScopeconsent scope selection, default vs. explicituniverseDomainpropagation (including ignoringGOOGLE_CLOUD_UNIVERSE_DOMAINfor non-JSON credentials), IPv4/IPv6 loopback binding without mocking JDK networking classes, RFC 3986+and%2Bquery decoding and malformed%handling,stateanderror=callback validation,> 16 KiBand> 64 KiBheader draining, resilience to browser TCP preconnects //favicon.ico/ unverified local HTTP probes, timeout diagnostics and socket cleanup paths, and non-desktop environment fast-fail.OAuthType=1requires desktop user interaction.