Security & Rate Limiting
Relevant source files
The following files were used as context for generating this wiki page:
The OS Chat platform implements a multi-layered security architecture designed to protect user data, ensure fair resource allocation, and maintain service integrity. This system encompasses data encryption, secure authentication via Convex Auth, server-side validation, and a sophisticated rate-limiting engine that distinguishes between anonymous, authenticated, and premium users.
Security measures are integrated directly into the Convex backend and the TanStack-powered frontend, ensuring that data isolation and access controls are enforced at both the infrastructure and application levels. Rate limiting serves as a critical defense mechanism against abuse while providing a tiered usage model.
Sources: src/routes/security.tsx:15-32, convex/users.ts:251-300
Data Protection & Encryption
OS Chat employs industry-standard cryptographic practices to secure sensitive information. API keys provided by users are never stored in plain text and are protected using high-iteration key derivation functions.
Encryption Standards
- API Keys: Encrypted using AES-GCM 256-bit encryption. The system utilizes PBKDF2 key derivation with 100,000 iterations to ensure robust protection against brute-force attacks.
- Data in Transit: All communications between the client and server are encrypted using HTTPS/TLS 1.3.
- User Isolation: Data is isolated using user-specific encryption keys and server-side authorization checks.
Sources: src/routes/security.tsx:34-45, src/routes/privacy.tsx:105-115
Access Control Flow
Authentication is managed via Convex Auth with Google OAuth integration. The system enforces strict row-level security where users can only access data associated with their unique userId.
Rate Limiting Architecture
The rate-limiting system is built using the @convex-dev/rate-limiter component. It tracks usage across different time windows (daily and monthly) and enforces limits based on the user's account status and the type of AI model being accessed.
Usage Limits Table
| User Tier | Limit Type | Quota |
|---|---|---|
| Anonymous | Daily Messages | 5 messages |
| Authenticated | Daily Messages | 20 messages |
| Standard (All) | Monthly Messages | Defined in RATE_LIMITS |
| Premium | Premium Credits | Enhanced limits via subscription |
| Sources: src/routes/terms.tsx:75-85, convex/users.ts:316-325, convex/lib/rateLimitConstants.ts |
Rate Limit Verification Logic
Before processing a chat request, the system executes an assertion check to ensure the user has not exceeded their allocated quota. This logic distinguishes between standard credits and premium credits.
Infrastructure Security
The application leverages managed infrastructure to reduce the attack surface and ensure high availability.
Technology Stack Security Features
- Convex Backend: Provides a managed serverless environment with built-in security features and automatic scaling.
- Vercel Hosting: Includes DDoS protection and global edge distribution.
- TanStack Start: Utilizes a modern, type-safe framework that follows security best practices for SSR and hydration.
- TypeScript: Enforces type safety to prevent common runtime vulnerabilities and bugs.
Sources: src/routes/security.tsx:55-71
Third-Party Service Integration
- AI Providers (OpenAI, Anthropic, etc.): API calls are made over encrypted connections, and only necessary message data is transmitted.
- Payment Processing: Handled by Polar, which is PCI compliant. OS Chat does not store raw payment card information.
- Object Storage: Files are stored in Cloudflare R2, managed via secure access keys.
Sources: src/routes/security.tsx:75-95, convex/users.ts:545-560
Implementation Details
Rate Limit Status Retrieval
The getRateLimitStatus query provides the frontend with real-time visibility into the user's remaining quota and reset times.
// Example of rate limit status calculation
const effectiveRemaining = isPremium
? monthlyRemaining
: Math.min(dailyRemaining, monthlyRemaining);
return {
isPremium,
dailyRemaining,
monthlyRemaining,
premiumRemaining,
effectiveRemaining,
dailyReset,
monthlyReset
};
Sources: convex/users.ts:442-530
Security Incident Response
In the event of a security vulnerability or incident, the platform follows a structured response plan:
- Investigation: Promptly identify the scope and impact of the issue.
- Containment: Apply immediate fixes to prevent further compromise.
- Notification: Affected users are notified if their data is potentially compromised.
- Prevention: Update security policies and practices to prevent recurrence.
Sources: src/routes/security.tsx:120-128
Conclusion
Security and rate limiting in OS Chat are not merely bolt-on features but are foundational to the system's architecture. By combining robust encryption for API keys, strict authentication through Convex, and a granular rate-limiting system, the platform ensures that resources are protected from abuse while maintaining user privacy and data integrity.
Sources: src/routes/security.tsx, convex/users.ts, src/routes/api.chat.ts