Overview
Zarna implements OAuth 2.0 for third-party service integrations (Gmail, Outlook, Drive) with enterprise-grade security.Security Features
State Token Protection
Purpose: Prevent CSRF attacks in OAuth flow Implementation:- Cryptographically random: Uses secrets module (CSPRNG)
- Time-limited: 15-minute expiration
- Single-use: Deleted after validation
- Server-side storage: Can’t be tampered with
- User-specific: Tied to user_id
State Validation
Token Storage
Backend Storage
What to Store:- ✅ Composio account ID
- ✅ User ID
- ✅ Provider name
- ✅ Email address
- ❌ Never store raw OAuth tokens (Composio handles this)
Frontend Storage
Development: Not needed (Composio manages tokens) Production: Only store connection status, not tokensRedirect URI Validation
Strict Matching
Production Configuration
Scope Management
Minimal Scopes
Only request necessary permissions:Scope Escalation
Request additional scopes separately:Token Refresh
Automatic Refresh
Composio handles token refresh automatically:Webhook Security
Signature Verification
Best Practices
Use state parameter always
Use state parameter always
State parameter is REQUIRED for CSRF protection
Validate redirect URIs strictly
Validate redirect URIs strictly
No wildcards, exact matches only
Store minimal data
Store minimal data
Only store account IDs, not raw tokens
Implement token refresh
Implement token refresh
Handle token expiration gracefully
Use HTTPS in production
Use HTTPS in production
OAuth must use HTTPS for redirect URIs
Time-limit state tokens
Time-limit state tokens
15 minutes maximum
Verify webhook signatures
Verify webhook signatures
Always validate webhook authenticity
Common Vulnerabilities
CSRF Attack
Attack: Malicious site initiates OAuth without state parameter Defense: Always use and validate state parameterToken Leakage
Attack: Tokens exposed in logs, URLs, or client-side Defense:- Never log full tokens
- Use POST for token exchange (not GET)
- Store server-side only
Redirect URI Manipulation
Attack: Attacker changes redirect URI to steal authorization code Defense: Strict redirect URI validationCompliance
GDPR
- Users can disconnect OAuth accounts
- Data deleted when account disconnected
- Export OAuth connection data
SOC 2
- Audit all OAuth events
- Monitor for suspicious OAuth activity
- Regular token rotation
