Skip to content

Conversation

@Mirrowel
Copy link
Owner

@Mirrowel Mirrowel commented Jan 16, 2026

  • Integrate PKCE (Proof Key for Code Exchange) into the OAuth flow in GoogleOAuthBase, including state parameter validation for enhanced security.
  • Implement robust endpoint fallback chains (Production ↔ Daily Sandbox) in AntigravityAuthBase for project discovery and user onboarding.
  • Update User-Agent and X-Goog-Api-Client headers to align with recent Node.js client versions.
  • Refactor project ID extraction and onboarding polling logic to handle variable API response formats and errors more gracefully.

Important

Implement PKCE security in OAuth flow, add endpoint fallback strategies, update headers, and refactor project ID extraction in AntigravityAuthBase and GoogleOAuthBase.

  • Security:
    • Implement PKCE in GoogleOAuthBase for OAuth flow, including state parameter validation.
    • Add _generate_pkce(), _encode_oauth_state(), and _decode_oauth_state() for PKCE support.
  • Endpoint Fallback:
    • Add endpoint fallback strategies in AntigravityAuthBase for loadCodeAssist and onboardUser.
    • Use ANTIGRAVITY_LOAD_ENDPOINT_ORDER and ANTIGRAVITY_ENDPOINT_FALLBACKS for fallback logic.
  • Headers:
    • Update User-Agent and X-Goog-Api-Client headers in antigravity_auth_base.py and google_oauth_base.py.
  • Refactoring:
    • Refactor project ID extraction in AntigravityAuthBase to handle variable API response formats.
    • Improve onboarding polling logic for better error handling.

This description was created by Ellipsis for fa4d94b. You can customize this summary. It will automatically update as commits are pushed.

- Integrate PKCE (Proof Key for Code Exchange) into the OAuth flow in `GoogleOAuthBase`, including state parameter validation for enhanced security.
- Implement robust endpoint fallback chains (Production ↔ Daily Sandbox) in `AntigravityAuthBase` for project discovery and user onboarding.
- Update `User-Agent` and `X-Goog-Api-Client` headers to align with recent Node.js client versions.
- Refactor project ID extraction and onboarding polling logic to handle variable API response formats and errors more gracefully.
@Mirrowel Mirrowel self-assigned this Jan 16, 2026
Updates authentication and provider headers to strictly mimic the official Antigravity Electron client and VSCode Cloud Shell editor. This resolves issues with onboarding and specific model availability.

- Update `User-Agent` and `X-Goog-Api-Client` headers in `AntigravityAuthBase` and `AntigravityProvider` to match known working client signatures.
- Change `CALLBACK_PATH` from `/oauthcallback` to `/oauth-callback` to match the native flow.
- Set `ideType` to `IDE_UNSPECIFIED` in client metadata payloads for compatibility.
- Remove extraneous headers from the OAuth token exchange request in `GoogleOAuthBase` to align with the reference TypeScript implementation.
@Mirrowel Mirrowel marked this pull request as ready for review January 19, 2026 23:54
@mirrobot-agent
Copy link
Contributor

I'm starting my review of the PKCE security implementation and endpoint fallback strategies. I'll take a close look at the authentication flow and the new polling logic in AntigravityAuthBase. Report coming soon! 🚀

Copy link
Contributor

@mirrobot-agent mirrobot-agent bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall Assessment

This PR introduces significant improvements to the authentication security and robustness of the Antigravity provider. The implementation of PKCE (RFC 7636) is a great security addition, and the endpoint fallback strategy for project discovery and onboarding makes the provider much more resilient to environment-specific issues.

The code is well-structured and includes helpful comments explaining the importance of specific headers and endpoint behaviors.

Architectural Feedback

  • PKCE Implementation: The use of S256 code challenge method and the generation of the code_verifier using secrets are correct and follow best practices.
  • Endpoint Fallback: Moving constants to gemini_shared_utils and implementing a consistent retry/fallback logic across loadCodeAssist and onboardUser is a solid architectural choice.

Key Suggestions

  • State Validation: I recommend aborting the flow if the returned OAuth state doesn't match the expected verifier, rather than falling back to the original verifier. This ensures the CSRF protection remains effective.
  • Onboarding Timeout: Please verify if 60 seconds is sufficient for all onboarding scenarios, as some server-side operations can be slower depending on the region or project state.

Questions for the Author

  • Was the reduction of the onboarding timeout from 5 minutes to 60 seconds driven by any specific performance metrics?

This review was generated by an AI assistant.

# Poll for onboarding completion (up to 5 minutes)
for i in range(150): # 150 × 2s = 5 minutes
# Poll for onboarding completion (up to 60 seconds)
for i in range(30): # 30 × 2s = 60 seconds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The onboarding timeout has been reduced from 5 minutes (150 attempts) to 60 seconds (30 attempts). While 60 seconds is often enough, some Long Running Operations (LROs) for onboarding can occasionally take longer. Was this reduction based on specific telemetry or observed behavior?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More than enough to verify

Comment on lines +1114 to +1118
if decoded_verifier != code_verifier:
lib_logger.warning(
"OAuth state verifier mismatch - possible CSRF attempt. "
"Using original verifier."
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the received_state decodes to a verifier that doesn’t match the original code_verifier, this is a strong indicator of a CSRF attempt or a session mismatch. Instead of falling back to the original verifier and proceeding, it would be safer to raise an exception and abort the authentication flow.

Comment on lines +123 to +140
def _encode_oauth_state(self, code_verifier: str) -> str:
"""
Encode OAuth state parameter containing PKCE verifier.
The state parameter provides CSRF protection and carries the PKCE verifier
so it can be recovered after the OAuth callback.
Args:
code_verifier: The PKCE code verifier to encode
Returns:
Base64url-encoded state string
"""
import base64

state_data = {"v": code_verifier} # Minimal - just verifier
json_bytes = json.dumps(state_data, separators=(",", ":")).encode("utf-8")
return base64.urlsafe_b64encode(json_bytes).decode("ascii").rstrip("=")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Encoding the code_verifier directly into the state parameter is an interesting approach to avoid local state management. However, since the state is not signed or encrypted, it doesn’t provide much beyond what PKCE already provides. Usually, state should be a random nonce validated against a local store. If local storage is not an option, consider adding a signature to the state to ensure it wasn’t tampered with, although PKCE itself mitigates authorization code injection.

@Mirrowel Mirrowel merged commit 74216fd into dev Jan 20, 2026
3 of 4 checks passed
@Mirrowel Mirrowel deleted the antigraivty-onboarding-fix branch January 20, 2026 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants