This document outlines security considerations and best practices for the Prema Review Intelligence application.
- Never commit
.envfiles to version control. The.envfile is already in.gitignore. - Always use
.env.exampleas a template for configuration. - Use environment variables or a secrets management service (e.g., AWS Secrets Manager, HashiCorp Vault) for production deployments.
- Rotate API keys regularly, especially if they are exposed or suspected to be compromised.
- File Type Validation: Only
.csv,.json, and.ndjsonfiles are accepted. - File Size Limits: Maximum upload size is configurable via
MAX_UPLOAD_SIZE(default: 10MB). - Row Limit Protection: Maximum rows processed per file is configurable via
MAX_INGESTION_ROWS(default: 50,000) to prevent DoS attacks. - Input Validation: JSON parsing includes error handling and size limits.
- Content Sanitization: Text normalization is applied to review content.
- Monitor file upload patterns for abuse.
- Consider implementing virus scanning for uploaded files in production.
- Add rate limiting per IP address for file uploads.
- Log all file upload attempts for security auditing.
- Development: CORS allows all origins (
*) for local development. - Production: Must configure
CORS_ALLOWED_ORIGINSwith a comma-separated list of allowed origins. - Never use wildcard (
*) in production whenallow_credentials=True. - Regularly review and update the list of allowed origins.
- SQLite is suitable for development but not recommended for production.
- File-based database can be vulnerable to:
- File system attacks
- Concurrent write issues
- Limited scalability
- Use PostgreSQL or MySQL for production deployments.
- Connection Pooling: Configured to prevent connection exhaustion.
- Connection Timeouts: Set to prevent hanging connections.
- Use Connection String Environment Variables: Never hardcode database credentials.
- Enable SSL/TLS: Use encrypted connections for database access.
- Regular Backups: Implement automated backup strategies.
- Access Control: Limit database access to application servers only.
- SQLite:
sqlite:///./data/app.db - PostgreSQL:
postgresql://user:password@host:port/database - MySQL:
mysql://user:password@host:port/database
- API keys are validated on client creation.
- Keys are stored in environment variables, never in code.
- Keys are validated for proper format before use.
- Rate limiting is implemented to prevent API abuse and cost overruns.
- Default: 60 requests per minute (configurable via
LLM_RATE_LIMIT_RPM). - Monitor API usage and adjust limits based on your provider's quotas.
- Set up billing alerts with your LLM provider.
- Monitor API usage patterns for anomalies.
- Use separate API keys for development and production.
- Implement per-user rate limiting if multi-tenant.
- File uploads are validated for type and size.
- JSON parsing includes error handling.
- Text normalization sanitizes input.
- SQL injection protection via SQLModel/SQLAlchemy ORM.
- Implement request timeout limits.
- Add input length validation for form fields.
- Sanitize all user-generated content before storage.
- Use parameterized queries (handled by ORM).
Current Status: Not implemented. The API is currently open.
- Implement Authentication: Use JWT tokens or OAuth2.
- API Key Authentication: For programmatic access.
- Role-Based Access Control (RBAC): Different permissions for different users.
- Rate Limiting: Per-user/per-IP rate limits.
- Audit Logging: Log all API access and modifications.
- Regularly run
poetry auditor use tools likesafetyto check for vulnerabilities. - Keep dependencies up to date.
- Review changelogs before upgrading major versions.
- Subscribe to security advisories for your dependencies.
# Check for known vulnerabilities
poetry audit
# Or use safety (requires installation)
pip install safety
safety check- Structured logging is configured via
app.core.logging. - Log level is configurable via
LOG_LEVEL.
- Log Sensitive Operations: File uploads, API key usage, database changes.
- Monitor for Anomalies: Unusual request patterns, failed authentications, errors.
- Alert on Security Events: Failed login attempts, rate limit violations, suspicious uploads.
- Avoid Logging Secrets: Never log API keys, passwords, or tokens.
- Replace SQLite with PostgreSQL/MySQL
- Configure
CORS_ALLOWED_ORIGINSfor production - Set strong, unique API keys for LLM providers
- Enable HTTPS/TLS for all connections
- Implement authentication and authorization
- Configure proper firewall rules
- Set up automated backups
- Enable security monitoring and alerting
- Review and configure rate limiting
- Set up log aggregation and monitoring
- Run security audits on dependencies
- Configure environment-specific settings
- Identify: Detect and confirm the security issue.
- Contain: Limit the impact (revoke keys, disable features, etc.).
- Eradicate: Remove the threat (patch vulnerabilities, update dependencies).
- Recover: Restore services with security fixes.
- Review: Post-mortem analysis and improvements.
If you discover a security vulnerability, please report it responsibly:
- Do not create public issues for security vulnerabilities.
- Contact the maintainers directly.
- Provide detailed information about the vulnerability.
- Allow time for the issue to be addressed before public disclosure.