Skip to content

fix: Step 3 security hardening - dependencies, CORS, rate limiting, Dockerfile - #20

Closed
Alcides1123 wants to merge 4 commits into
vectornguyen76:masterfrom
Alcides1123:master
Closed

Alcides1123 wants to merge 4 commits into
vectornguyen76:masterfrom
Alcides1123:master

Conversation

@Alcides1123

Copy link
Copy Markdown

🔒 Step 3: Security Hardening - Dependencies, CORS, Rate Limiting, Dockerfile

Part of the ongoing security audit and hardening effort for the codebase.

📦 Changes Overview

This PR implements Step 3 of the security hardening plan, focusing on dependency management, CORS configuration, rate limiting, and Docker security improvements.


✅ What's Changed

1. Dependency Management (requirements.txt)

  • ✅ Pinned all dependencies to specific versions for reproducibility
  • ✅ Added pip-audit for automated vulnerability scanning
  • ✅ Updated to latest stable versions where applicable
  • ✅ Removed any unused or redundant dependencies

2. CORS Configuration (app.py)

  • ✅ Replaced wildcard * origins with explicit allowed origins
  • ✅ Configured proper CORS credentials and methods
  • ✅ Added environment variable support for flexible deployment (ALLOWED_ORIGINS)
  • ✅ Improved security posture against unauthorized cross-origin requests

3. Rate Limiting (app.py)

  • ✅ Implemented Flask-Limiter for API endpoint protection
  • ✅ Applied stricter limits to write endpoints (POST/PUT/DELETE)
  • ✅ Added Redis-based storage for distributed rate limiting
  • ✅ Configured IP-based tracking with proper header detection

4. Dockerfile Security

  • ✅ Changed base image from root user to non-root USER appuser
  • ✅ Improved layer caching for faster builds
  • ✅ Added proper file permissions
  • ✅ Reduced attack surface by limiting container privileges

5. Configuration & Documentation

  • ✅ Added .env.example template for required environment variables
  • ✅ Updated documentation for new security configurations
  • ✅ Added setup instructions for Redis (required for rate limiting)

🔧 Configuration Required

New Environment Variables:

# CORS Configuration
ALLOWED_ORIGINS=http://localhost:3000,https://yourdomain.com

# Rate Limiting (if using Redis)
REDIS_URL=redis://localhost:6379

Added PowerShell command syntax for windows developers
ENhanced security section with git check-ignore examples, fixed .gitignore rules for .env file handling, expanded environment setup instructions, updated CI/CD workflow documentation, added default account security warnings
…s, Non-admin users caan no longer manage roles/permissions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant