Frontend Security

Authentication

JWT Tokens

  • Implementation: JWT tokens provided by Supabase
  • Transport: Passed via Authorization header in GraphQL requests
  • Context: The user’s session is added to the GraphQL context on the server, making it available to all resolvers for authorization checks

Session Management

  • Tokens are stored securely in the Apollo Client context
  • Automatic token refresh handled by Supabase client
  • Logout clears all client-side authentication state

API Security

Resolver-level Authorization

  • Permissions are checked inside each resolver before fetching data
  • User context is validated for every GraphQL operation
  • Role-based access control enforced at the data layer

Query Security

  • Query Depth/Cost Analysis: Implement limits to prevent malicious or expensive queries
  • Rate Limiting: Prevent abuse through request throttling
  • Input Validation: Use GraphQL’s type system for basic validation, with additional checks in resolvers

Data Protection

  • Field-level Security: Sensitive fields are filtered based on user permissions
  • Organization Isolation: Users can only access data from their own organization
  • Audit Logging: All mutations are logged with user context

Client-Side Security

Input Sanitization

  • All user inputs are validated both client-side and server-side
  • XSS protection through proper React rendering practices
  • File upload validation for type and size limits

State Management Security

  • Sensitive data is not stored in local storage
  • Apollo Client cache is cleared on logout
  • Real-time subscriptions are authenticated per connection

Security Best Practices

Development Guidelines

  • Never log sensitive data in console or debug outputs
  • Use HTTPS for all API communications
  • Implement proper error handling that doesn’t leak system information
  • Regular security audits of dependencies

Deployment Security

  • Content Security Policy (CSP) headers
  • Secure cookie configuration
  • CORS properly configured for production domains
  • Regular security updates for all dependencies