Security Best Practices
Ensuring security when integrating with the Riyadh Parking API is crucial to protect sensitive data and prevent unauthorized access. Follow these best practices to safeguard your system.1️⃣ Secure API Credentials
-
🔒 Use environment variables to store sensitive credentials (
Client ID,Client Secret). - 🔒 Restrict access to API keys by implementing role-based access control (RBAC).
- 🔒 Rotate API keys regularly to minimize the risk of exposure.
- Good Example
- Bad Example
Storing credentials securely in a
.env file:2️⃣ Enforce HTTPS for All Requests
Ensure all API requests use HTTPS to encrypt communication and protect against man-in-the-middle (MITM) attacks.- Secure
- Insecure
✅ Use HTTPS:
3️⃣ Implement Token Expiry Handling
Access tokens expire after a set duration. Always implement logic to refresh tokens before they expire. Recommended Flow:- Store token expiration timestamp when receiving an access token.
- Refresh the token when it’s about to expire.
- Retry failed requests due to expired tokens.
Use the Refresh Token API to obtain a new token without requiring user credentials.
Refreshing Tokens
4️⃣ Protect Against API Abuse
- Rate Limiting: Limit API requests per user to prevent abuse.
- Monitor API usage: Keep logs of failed login attempts and suspicious behavior.
- Restrict IP Access: Use allowlists to block unauthorized IPs.
5️⃣ Secure User Input
Validate all incoming requests to prevent SQL injection, XSS, and request forgery (CSRF).- Safe
- Unsafe
✅ Sanitize user input before processing: