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
Rotate credentials periodically and immediately if you suspect a compromise. OAuth 2.0 credentials support zero-downtime rotation with a grace period in the Developer Console.
4
Use minimal permissions
Only request the OAuth scopes your app actually needs.
Rotating OAuth 2.0 credentials with a grace period
You can rotate long-lived OAuth 2.0 credentials in the Developer Console without downtime by keeping the previous credential valid during a bounded grace window while you deploy the replacement across your services:
When you click Rotate for one of these credentials, choose when the previous credential should expire:
- Now — immediately revokes the previous credential (recommended if a credential is compromised)
- In 1 hour, In 24 hours, In 3 days, or In 7 days — issues a new credential immediately while keeping the previous credential active until the selected time
- Both the new credential and the retiring credential authenticate requests until the grace window ends.
- Click Expire now in the Developer Console at any time to revoke the retiring credential early once your rollout completes.
- At most one grace-period rotation can be active per credential at a time. To start another grace-period rotation, expire the retiring credential first. Choosing Now always revokes both the active and retiring credentials immediately for emergencies.
Grace-period rotation applies to OAuth 2.0 App-only Bearer Tokens, OAuth 2.0 Client Secrets, and OAuth 2.0 Bot Tokens. OAuth 1.0a keys and tokens and short-lived OAuth 2.0 user access tokens are unchanged.
If credentials are compromised
- Rotate immediately in the Developer Console using the Now expiration option
- Revoke old tokens — rotating with Now immediately invalidates both the current and any retiring 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
OAuth security
State parameter
Always use thestate parameter in OAuth flows to prevent CSRF:
Token storage
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
Resources
IP allowlist
Restrict X API calls for your account to approved IP addresses and CIDR blocks.
Authentication guide
Implement OAuth correctly.
App permissions
Configure minimal required permissions.