fix(security): disable debug mode defaults and conditional docs [#2036]#2038
Conversation
…h1#2036) The application defaulted to debug=True, causing: 1. Full Python tracebacks returned as HTML on unhandled exceptions 2. OpenAPI docs always exposed at /docs and /openapi.json 3. Uvicorn hot-reload enabled in production Fix: - Change debug default from True to False in config.py - Conditionally disable docs/redoc/openapi endpoints when debug=False - Conditionally skip /api/docs redirect routes when debug=False - Update .env.example to reflect safe default (SECUSCAN_DEBUG=false)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bbc7c4ea4e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| docs_url="/docs" if settings.debug else None, | ||
| redoc_url="/redoc" if settings.debug else None, | ||
| openapi_url="/openapi.json" if settings.debug else None, |
There was a problem hiding this comment.
Preserve OpenAPI docs for dev startup
When using the documented dev workflow, start.sh invokes python -m uvicorn backend.secuscan.main:app --reload and advertises /docs, but it never exports SECUSCAN_DEBUG and Settings does not load .env automatically. With the new default False, these routes are not registered at import time, so the advertised local Swagger/ReDoc/OpenAPI URLs 404 unless developers know to set SECUSCAN_DEBUG=true manually; use a separate production/docs flag or have the dev launcher explicitly enable debug/docs.
Useful? React with 👍 / 👎.
The dev workflow in start.sh advertises /docs, /redoc, and /openapi.json but never sets SECUSCAN_DEBUG. With the new default of debug=False, these routes 404 unless developers manually set the env var. Export SECUSCAN_DEBUG=true before launching uvicorn so the dev server has full API docs and hot-reload.
utksh1
left a comment
There was a problem hiding this comment.
Excellent security fix addressing the debug mode information disclosure vulnerability (#2036).
Changes:
- ✅ Debug defaults to False (was True)
- ✅ OpenAPI docs disabled in production (conditionally enabled only when debug=True)
- ✅ .env.example updated with safe defaults
This prevents:
- Full traceback exposure in production
- OpenAPI endpoint mapping leakage
- Uvicorn hot-reload in production
Rebased with main to include test fixes. Approving for merge.
Summary
Disable debug mode by default and conditionally hide API documentation endpoints in production to prevent sensitive data exposure.
Closes #2036
Problem
The application defaulted to
debug: bool = True, causing three critical information disclosure issues:/docs,/redoc,/openapi.json— giving attackers a complete endpoint mapThe
.env.examplealso reinforced this withSECUSCAN_DEBUG=true.Fix (3 files)
1.
backend/secuscan/config.py2.
backend/secuscan/main.pyConditionally disable docs endpoints when debug is off:
The
/api/docs,/api/redoc, and/api/openapi.jsonredirect routes are also only registered whensettings.debugis True.3.
.env.exampleImpact
Labels
type:security,level:critical,priority:high,area:backend