Commit Graph

7 Commits

Author SHA1 Message Date
Maggie Chen 29fdb64fa0 fix: address critical security vulnerabilities — auth and path traversal
Two critical issues and several high/medium issues were identified during
a security review of the backend API.

**Critical fixes:**

1. Path traversal (CWE-22): user-supplied `simulation_id`, `report_id`,
   and `project_id` values were passed directly to `os.path.join()`
   without validation, allowing `../` sequences to escape intended
   directories.
   - Added `backend/app/utils/id_validator.py` with `validate_safe_id()`
     (rejects anything that isn't alphanumeric/underscore/hyphen) and
     `safe_join()` (resolves realpath and verifies containment).
   - Applied to all 3 path-construction sites in simulation.py, all 12
     relevant handlers in report.py, and 6 sites in graph.py.
   - Sanitized uploaded filenames with `os.path.basename()` in graph.py.

2. Missing authentication: all API endpoints were publicly accessible
   with no auth mechanism.
   - Added `backend/app/utils/auth.py` with an `X-Api-Key` middleware
     registered as a `before_request` hook.
   - Auth is opt-in: set `API_KEY` in `.env` to enforce it; if unset a
     startup warning is logged. This preserves local dev workflows.

**High fixes:**

3. Hardcoded `SECRET_KEY` fallback replaced with `os.urandom(32).hex()`
   so an unset key is never predictable.
4. `FLASK_DEBUG` now defaults to `False` instead of `True`.
5. Full Python tracebacks removed from all API error responses (51 total
   across graph.py, report.py, simulation.py) — tracebacks still go to
   the logger.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-05 19:35:50 -04:00
666ghj 9556854fbf refactor(.env.example): update LLM API configuration comments for clarity and add usage note 2026-01-20 18:05:36 +08:00
666ghj ca24ee09d1 chore(env.example): update LLM model configuration and clarify boost settings. 2026-01-15 23:11:26 +08:00
666ghj a47eb1eaef Refactor project structure by removing Docker support and updating environment configuration
- Deleted docker-compose.yml, backend Dockerfile, frontend Dockerfile, and nginx configuration to streamline project setup.
- Updated .env.example to reorganize LLM and ZEP API configurations for clarity and ease of use.
- Enhanced README.md to reflect changes in project structure and provide clearer setup instructions.
2025-12-19 13:58:35 +08:00
666ghj e432e223df Update project configuration and structure with Docker support and environment variable adjustments
- Updated .env.example to reflect new LLM configuration with Aliyun's API.
- Enhanced .gitignore to include additional files and directories for better exclusion of sensitive and build artifacts.
- Added docker-compose.yml for streamlined deployment of backend and frontend services.
- Introduced Dockerfiles for both backend and frontend to facilitate containerized builds.
- Created README.md to provide comprehensive project documentation and setup instructions.
- Established nginx configuration for frontend to support API proxying and static file serving.
2025-12-17 18:17:40 +08:00
666ghj 39253b3213 Update .env.example and enhance create_model function for dual LLM configuration
- Updated .env.example to include new keys for dual LLM configuration, allowing for both general and boost settings.
- Modified create_model function to support an optional use_boost parameter, enabling the selection of either general or boost LLM configurations based on availability.
- Improved logging to indicate which LLM configuration is being used during model creation, enhancing clarity for users.
2025-12-04 15:51:25 +08:00
666ghj 08f417f3b7 Introduce Project ID for context management, finalizing the stateful API pipeline from file submission to graph construction. 2025-11-28 17:21:08 +08:00