Security
Hyperscape implements multiple layers of security to protect player data and prevent exploits.Security code lives in
packages/client/src/auth/, packages/server/src/infrastructure/auth/, and packages/server/src/systems/ServerNetwork/services/.Authentication
Privy Integration
Hyperscape uses Privy for secure authentication with support for:- Email/SMS — Passwordless login
- Social OAuth — Google, Twitter, Discord, etc.
- Wallet Connect — Ethereum and Solana wallets
- Farcaster — Farcaster Frame integration
Configurable Auth Storage
Auth tokens can be stored in different locations based on security requirements:Async Token Provider
The API client supports async token refresh for fresh tokens:Fresh Tokens: The async token provider ensures API requests always use fresh tokens from Privy, not stale cached tokens.
URL Parameter Validation
Embedded Mode Security
Embedded mode (iframe integration) now validates all URL parameters to prevent injection attacks:Secure Token Delivery
Auth tokens are now delivered via postMessage instead of URL parameters:Content Security Policy
CSP Headers
Hyperscape implements Content Security Policy headers to mitigate XSS attacks:unsafe-inline and unsafe-eval?
- Privy SDK: Injects inline styles for modal/popup UI and uses eval for authentication flows
- React: Some styled-components patterns use inline styles
- Three.js: Shader compilation may use inline scripts
- Webpack/Vite: Hot module replacement in development
Future Improvement: Consider migrating to CSP nonces when Privy SDK adds support.
CSP Violation Monitoring
CSP violations are monitored and reported:Throttling: CSP violation reports are throttled to prevent flooding the server with duplicate reports.
Input Validation
Server-Side Validation
All client inputs are validated server-side to prevent exploits:Combat Request Validation
Combat requests require timestamp validation to prevent replay attacks:Type Guards
Event payloads use type guards for runtime validation:Rate Limiting
Combat Rate Limiting
Combat actions are rate-limited to prevent spam:Global Rate Limits
Anti-Cheat Measures
Server-Authoritative Validation
All game state changes are validated server-side:Never Trust the Client: All calculations (distance, equipment, ammunition) are performed server-side. Client requests are treated as untrusted input.
Movement Anti-Cheat
Movement is validated to prevent teleportation and speed hacks:Secure Storage
Client-Side Storage
ThesecureStorage utility provides safe browser storage access:
Error Handling: All storage operations are wrapped in try-catch to handle private browsing mode, quota exceeded, and other storage failures.
Error Reporting
Unhandled Error Tracking
Unhandled errors and promise rejections are tracked:CSP Violation Reporting
CSP violations are reported to the server for security monitoring:Database Security
Parameterized Queries
All database queries use Drizzle ORM with parameterized queries to prevent SQL injection:Transaction Isolation
Critical operations use database transactions for atomicity:Audit Logging
Activity Log
Player actions are logged for audit trails:- Player login/logout
- Item trades
- Bank transactions
- Combat kills
- Admin actions
Best Practices
Client-Side
- Never trust client data — Validate everything server-side
- Use secure storage — Prefer
sessionStorageoverlocalStorage - Validate URL parameters — Use schema-based validation
- Report errors — Send CSP violations and unhandled errors to server
- Use type guards — Validate event payloads at runtime
Server-Side
- Parameterized queries — Always use Drizzle ORM, never raw SQL
- Rate limiting — Apply to all player actions
- Timestamp validation — Prevent replay attacks
- Server-authoritative — Calculate all game state server-side
- Audit logging — Log critical actions for investigation