This document outlines essential security practices for implementing the Zarban SDK in your applications. Following these guidelines will help ensure the security of your integration and protect your users' assets.
- Enforce strong password policies:
- Minimum length: 12 characters
- Must include a combination of:
- Uppercase letters (A-Z)
- Lowercase letters (a-z)
- Numbers (0-9)
- Special characters (!@#$%^&*)
- Avoid common patterns and sequences
- Prevent use of previously compromised passwords
# DON'T store passwords in plain text
password = "userPassword123" # Incorrect
# DON'T store passwords in configuration files
config = {
"user_password": "secretPassword" # Incorrect
}
# DO use environment variables for sensitive data
import os
api_key = os.environ.get('ZARBAN_API_KEY')
- Never hardcode API keys in your source code
- Use environment variables or secure credential management systems
- Implement key rotation policies
- Use different API keys for development and production environments
from zarban.wallet.openapi_client.configuration import Configuration
# DO verify SSL certificates
configuration = Configuration(
host="https://api.zarban.io",
verify_ssl=True # Default is True, explicitly shown for emphasis
)
# DON'T disable SSL verification in production
configuration = Configuration(
host="https://api.zarban.io",
verify_ssl=False # INCORRECT for production
)
- Always use HTTPS endpoints
- Validate SSL certificates
- Implement certificate pinning for additional security
- Monitor for certificate expiration
from zarban.wallet.openapi_client.exceptions import ApiException
try:
api_response = api_instance.auth_signup_post(signup_request)
except ApiException as e:
# DO log errors securely
logger.error(f"API Error Code: {e.status}")
# DON'T expose sensitive information in error messages to users
# Incorrect:
print(f"Failed to authenticate with credentials {signup_request.email}")
# Correct:
print("Authentication failed. Please check your credentials and try again.")
- Never log sensitive information such as:
- Passwords
- API keys
- Private keys
- Personal identifying information
- Use appropriate log levels
- Implement secure log rotation
- Monitor logs for security events
from datetime import datetime, timedelta
from collections import deque
class RateLimiter:
def __init__(self, max_requests, time_window):
self.max_requests = max_requests
self.time_window = time_window
self.requests = deque()
def can_make_request(self):
now = datetime.now()
while self.requests and now - self.requests[0] >= self.time_window:
self.requests.popleft()
if len(self.requests) < self.max_requests:
self.requests.append(now)
return True
return False
# Usage
rate_limiter = RateLimiter(max_requests=100, time_window=timedelta(minutes=1))
def validate_email(email):
import re
pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
return bool(re.match(pattern, email))
def create_user(email, password):
# DO validate input before processing
if not validate_email(email):
raise ValueError("Invalid email format")
if len(password) < 12:
raise ValueError("Password too short")
- Sanitize all data before displaying to users
- Use proper encoding for different contexts (HTML, JSON, etc.)
- Implement content security policies
- Use secure session tokens
- Implement proper session timeouts
- Invalidate sessions on logout
- Monitor for suspicious session activities
# Example session configuration
session_config = {
'session_lifetime': timedelta(hours=1),
'refresh_token_lifetime': timedelta(days=7),
'max_active_sessions': 3
}
- SSL/TLS properly configured
- API keys securely stored
- Rate limiting implemented
- Error handling configured
- Logging properly set up
- Input validation implemented
- Output sanitization in place
- Session management configured
- Security headers implemented
- Set up monitoring for:
- Failed authentication attempts
- Unusual API usage patterns
- Rate limit violations
- Error rate spikes
- Configure alerts for security events
- Implement audit logging
- Update SDK to latest version
- Rotate API keys periodically
- Review and update security configurations
- Audit system logs
- Update SSL certificates before expiration
- Review and test error handling
- Update password policies as needed
- Immediately revoke compromised credentials
- Document and investigate the incident
- Notify affected users if required
- Implement additional security measures
- Update security procedures based on lessons learned
Remember: Security is an ongoing process, not a one-time implementation. Regularly review and update your security practices to maintain the highest level of protection for your users.