Core requirements
TLS required
All API requests must use HTTPS. Plain HTTP is rejected.
Credential security
Never expose API keys or tokens in client-side code, logs, or repositories.
Protecting credentials
Your API keys and tokens are the keys to your app. Keep them secure:1
Use environment variables
Store credentials in environment variables, not in code.
2
Never commit secrets
Add credential files to
.gitignore. Use tools like git-secrets to prevent accidental commits.3
Rotate regularly
Regenerate keys periodically and immediately if you suspect a compromise.
4
Use minimal permissions
Only request the OAuth scopes your app actually needs.
If credentials are compromised
- Regenerate immediately in the Developer Console
- Revoke old tokens — regenerating automatically invalidates old credentials
- Audit usage — check for unauthorized API activity
- Update your app — deploy new credentials to all environments
Application security
Input validation
Never trust user input. Validate and sanitize all data before using it:Output encoding
Escape X API data before displaying in HTML to prevent XSS:Common vulnerabilities to prevent
| Vulnerability | Prevention |
|---|---|
| XSS | Escape all user-generated content before rendering |
| CSRF | Use anti-CSRF tokens in forms; verify OAuth state parameter |
| SQL Injection | Use parameterized queries, never concatenate user input |
| Open redirects | Validate callback URLs against an allowlist |
OAuth security
State parameter
Always use thestate parameter in OAuth flows to prevent CSRF:
Token storage
| Token type | Storage recommendation |
|---|---|
| Access tokens | Encrypted database or secure vault |
| Refresh tokens | Encrypted database with additional access controls |
| Bearer tokens | Environment variables or secure configuration |
Secure development practices
Security audits
Conduct regular security reviews and penetration testing.
Dependency scanning
Keep dependencies updated. Use tools to detect vulnerable packages.
Logging
Log security events but never log credentials or sensitive data.
Monitoring
Set up alerts for unusual API usage patterns.
Reporting security issues
If you discover a security vulnerability affecting X:X Bug Bounty
Report vulnerabilities in X’s systems through HackerOne.
Your app incident
If your app using X data is breached, report through the same channel.
Compliance checklist
Security requirements for X API developers
Security requirements for X API developers
- All API requests use TLS/HTTPS
- Credentials stored securely (not in code or logs)
- User tokens encrypted at rest
- Input validation on all user-supplied data
- Output encoding to prevent XSS
- CSRF protection on OAuth flows
- Security logging enabled (without sensitive data)
- Incident response plan documented
- Dependencies regularly updated
- Minimal OAuth scopes requested