API Security
Secure API communication
This guide covers how to securely interact with the CodePlanet API, manage your API keys, and follow best practices for safe data access.
Authentication
All authenticated API endpoints require a valid session cookie. The API uses Supabase Auth with cookie-based sessions.
Session-Based Authentication
When you log in via the web app, a secure httpOnly session cookie is set. API routes automatically read this cookie to identify you.
For server-to-server communication, use the API key system described below.
API Keys
For programmatic access, CodePlanet supports API keys:
- Generate a key in Settings → API Keys
- Include the key in your request headers:
| Key Type | Rate Limit | Access |
|---|---|---|
| Personal | 100 req/min | Your own data |
| Read-only | 60 req/min | Public data only |
Key Management
- Rotate keys regularly — generate new keys and revoke old ones periodically
- Never share keys — each key is tied to your account
- Revoke compromised keys immediately — go to Settings → API Keys → Revoke
Rate Limiting
All API endpoints are rate-limited to prevent abuse:
| Tier | Requests/Minute | Requests/Hour |
|---|---|---|
| Free | 30 | 500 |
| Pro | 100 | 3,000 |
| Developer | 300 | 10,000 |
When you exceed the limit, the API returns:
Headers returned:
X-RateLimit-Limit: Your rate limitX-RateLimit-Remaining: Remaining requestsX-RateLimit-Reset: Time when the limit resets (Unix timestamp)
Security Best Practices
For Frontend Applications
- Never expose API keys in client-side code — use server-side proxying
- Use HTTPS exclusively — all API requests must use
https:// - Validate responses — check
successfield before using data - Handle errors gracefully — don't expose raw error messages to users
For Backend Integrations
- Store keys in environment variables — never hardcode in source code
- Use the minimum scope needed — read-only keys for read-only operations
- Implement retry logic — handle 429 (rate limit) with exponential backoff
- Log API usage — monitor for unusual patterns
Example: Safe API Call
Data Protection
What Data Is Public
These endpoints return data visible to anyone:
- Problem listings and details
- Public leaderboards
- Public user profiles (if enabled by the user)
- Course catalog and lesson content
- Certificate verification
What Data Is Private
These require authentication and only return your own data:
- Submission history
- Progress and statistics
- Notes and bookmarks
- Payment information
- Profile settings
Data Isolation
- You can only access your own private data — there is no way to access another user's private information through the API
- All write operations verify ownership server-side
- Admin endpoints require explicit admin role verification
Reporting Security Issues
If you discover a security vulnerability in the CodePlanet API:
- Do not exploit or publicize the vulnerability
- Email security@acodeplanet.tech with details
- Include steps to reproduce
- We will acknowledge receipt within 48 hours
- We aim to fix critical issues within 7 days