Security¶
Security considerations for ChostPulse.
Token Security¶
Secret Tokens¶
Secret tokens follow the format sk_live_<uuid>:
- Never expose secret tokens in public repositories
- Never log secret tokens
- Rotate tokens if compromised
- Use unique tokens per server/application
Public IDs¶
Public IDs are derived from secret tokens via SHA-256:
- Cannot be reversed to obtain the secret token
- Safe to display publicly in badges
- 12-character hex prefix provides adequate collision resistance
Derivation Process¶
- Strip prefix:
sk_live_550e8400-...→550e8400-... - SHA-256 hash:
550e8400-...→a1b2c3d4e5f6... - Take first 12 chars:
a1b2c3d4e5f6 - Add prefix:
srv_pub_a1b2c3d4e5f6
Data Validation¶
Input Validation¶
All heartbeat requests are validated:
- Token format: Must match
sk_live_+ UUID pattern - Required fields:
token,data,status,players,maxPlayers,tps,version - Type checking: All fields must be correct type
- Public ID format: Badge requests validate
srv_pub_format
Sanitization¶
- JSON parsing handles malformed input safely
- Type assertions prevent type confusion attacks
- No user input is executed or evaluated
CORS Policy¶
The worker uses a permissive CORS policy:
{
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type'
}
Why? - Badges need to be embedded in various websites - Heartbeats may come from different origins
Considerations: - This allows any website to call the API - Rate limiting should be implemented if abuse occurs - Consider restricting origins for production deployments
Data Privacy¶
Storage¶
- Data stored in KV store with 5-minute TTL
- No personally identifiable information (PII) is collected
- IP addresses are not logged or stored
- Only server status metrics are stored
Retention¶
- Automatic expiration after 5 minutes
- No long-term data retention
- No historical metrics stored
Rate Limiting¶
Current Implementation¶
None - The worker does not implement rate limiting.
Recommendations¶
Implement rate limiting to prevent abuse:
- Per-token limiting: Limit heartbeats per secret token
- Per-IP limiting: Use Cloudflare's built-in rate limiting
- Global limiting: Cap total requests per minute
Example with Cloudflare Rate Limiting API:
// Pseudo-code
const rateLimit = await checkRateLimit(secretToken);
if (rateLimit.exceeded) {
return new Response('Too many requests', { status: 429 });
}
DDoS Protection¶
Cloudflare provides automatic DDoS protection:
- Layer 3/4 protection
- Layer 7 (HTTP) protection
- Automatic mitigation
No additional configuration needed.
Authentication¶
Current Implementation¶
Secret tokens provide basic authentication:
- Possession of valid token allows heartbeat submission
- No additional authentication mechanisms
Future Enhancements¶
Consider implementing:
- API Keys: Separate authentication from public ID derivation
- JWT: Stateless authentication with expiration
- OAuth: For third-party integrations
- Webhooks: Signature verification for callbacks
Encryption¶
In Transit¶
All communication uses HTTPS:
- TLS 1.2+ enforced by Cloudflare
- Automatic certificate management
- HTTP requests redirected to HTTPS
At Rest¶
Data in KV store:
- Encrypted at rest by Cloudflare
- No additional encryption needed
- Consider encrypting sensitive data before storage if needed
Content Security¶
XSS Prevention¶
Badges are SVG images:
- No JavaScript execution in SVG responses
- No user-controlled content in SVG
- Content-Type header correctly set
Injection Prevention¶
- No SQL database (using KV store)
- No command execution
- No template injection (badges use library)
Monitoring¶
Recommended Practices¶
- Monitor errors: Track 4xx/5xx responses
- Alert on anomalies: Unusual traffic patterns
- Review logs: Regular security audits
- Track token usage: Detect compromised tokens
Cloudflare Analytics¶
Use Cloudflare's built-in analytics:
- Request volume and patterns
- Error rates
- Geographic distribution
- Cache hit rates
Best Practices¶
For Developers¶
- Keep dependencies updated:
npm auditregularly - Review code changes: Use pull requests
- Test thoroughly: Run tests before deployment
- Monitor production: Set up alerts
- Document changes: Security-relevant updates
For Users¶
- Protect secret tokens: Never commit to git
- Use environment variables: Store tokens securely
- Rotate tokens: If compromised or periodically
- Monitor usage: Check for unexpected activity
- Report issues: Security vulnerabilities responsibly
Vulnerability Reporting¶
If you discover a security vulnerability:
- Do not create a public issue
- Email security concerns privately
- Include detailed reproduction steps
- Allow time for a fix before disclosure
Compliance¶
GDPR¶
The worker does not collect or process personal data:
- No user identification
- No behavioral tracking
- No PII storage
Other Regulations¶
Check your local regulations regarding:
- Data retention
- Cross-border data transfer
- Security standards
Cloudflare Security Features¶
The worker benefits from Cloudflare's security:
- WAF: Web Application Firewall
- DDoS Protection: Automatic mitigation
- Bot Management: Identify and block bots (paid feature)
- SSL/TLS: Automatic certificate management
- Rate Limiting: Configurable rate limits (paid feature)
Future Security Enhancements¶
Planned improvements:
- Token rotation mechanism
- Rate limiting per token
- Webhook signature verification
- Audit logging
- IP allowlisting option