Skip to content

feat: add support for x-gateway-id #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 10, 2025
Merged

Conversation

chriswessels
Copy link
Member

@chriswessels chriswessels commented May 30, 2025

Add configurable gateway support via header-based gateway IDs

Summary

Enables users to specify alternative Graph Protocol gateways using a secure gateway ID system instead of hardcoded URLs. This provides flexibility for users who need to use different gateway endpoints while maintaining security.

Core Implementation

  • Gateway Registry: Added GATEWAY_REGISTRY HashMap mapping gateway IDs to whitelisted URLs:
  • Header-based Selection: Users can specify gateway via x-gateway-id header
  • Secure Validation: Only whitelisted gateway IDs are accepted, preventing SSRF attacks

Enhanced Error Handling

  • Descriptive Errors: Invalid gateway IDs return helpful messages listing valid options
  • New Error Type: Added InvalidGatewayId variant to SubgraphError enum

API Updates

  • Method Signatures: Updated all internal methods to accept gateway_url parameter
  • Error Propagation: All endpoints now handle gateway validation errors with clear messaging

Security Considerations

✅ SSRF Prevention: Only whitelisted gateways can be used
✅ API Key Protection: Keys are never sent to untrusted endpoints
✅ Input Validation: All gateway IDs are validated against registry

Usage

  # Default gateway (Edge & Node)
  curl -H "Authorization: Bearer YOUR_API_KEY" ...

  # GraphOps gateway
  curl -H "x-gateway-id: graphops" -H "Authorization: Bearer YOUR_API_KEY" ...

  # Invalid gateway returns helpful error
  curl -H "x-gateway-id: invalid" -H "Authorization: Bearer YOUR_API_KEY" ...
  # Error: Invalid gateway ID 'invalid'. Valid gateway IDs are: edgeandnode, graphops

@sahra-karakoc sahra-karakoc self-requested a review June 10, 2025 14:06
Copy link
Member

@sahra-karakoc sahra-karakoc left a comment

Choose a reason for hiding this comment

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

ty sir

@sahra-karakoc sahra-karakoc merged commit 5e750ce into main Jun 10, 2025
3 checks passed
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