Skip to content

fix(security): disable debug mode defaults and conditional docs [#2036]#2038

Merged
utksh1 merged 2 commits into
utksh1:mainfrom
namann5:fix/debug-mode-sensitive-data-exposure
Jul 20, 2026
Merged

fix(security): disable debug mode defaults and conditional docs [#2036]#2038
utksh1 merged 2 commits into
utksh1:mainfrom
namann5:fix/debug-mode-sensitive-data-exposure

Conversation

@namann5

@namann5 namann5 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

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:

  1. Full tracebacks as HTML on any unhandled exception — exposing internal file paths, database schema, library versions
  2. OpenAPI docs always accessible at /docs, /redoc, /openapi.json — giving attackers a complete endpoint map
  3. Uvicorn hot-reload enabled — watching all source files, exploitable for side-channel timing attacks

The .env.example also reinforced this with SECUSCAN_DEBUG=true.

Fix (3 files)

1. backend/secuscan/config.py

# Before
debug: bool = True

# After
debug: bool = False  # must be explicitly enabled

2. backend/secuscan/main.py

Conditionally disable docs endpoints when debug is off:

app = FastAPI(
    ...,
    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,
    ...
)

The /api/docs, /api/redoc, and /api/openapi.json redirect routes are also only registered when settings.debug is True.

3. .env.example

# Before
SECUSCAN_DEBUG=true

# After
SECUSCAN_DEBUG=false

Impact

  • Before: Tracebacks leaked on errors, OpenAPI schema always exposed, reload always active
  • After: Generic "Internal Server Error" in production, docs endpoints return 404, no reload unless explicitly enabled

Labels

type:security, level:critical, priority:high, area:backend

…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)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread backend/secuscan/main.py
Comment on lines +170 to +172
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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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

utksh1 commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Rebased with main to pick up test fixes from #2040 and #2041. The backend-unit test failures should be resolved now.

@utksh1 utksh1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@utksh1
utksh1 merged commit 0fdc994 into utksh1:main Jul 20, 2026
19 of 20 checks passed
@utksh1 utksh1 added type:security Security work category bonus label area:backend Backend API, database, or service work level:critical 80 pts difficulty label for critical or high-impact PRs gssoc:approved Admin validation: approved for GSSoC scoring labels Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend Backend API, database, or service work gssoc:approved Admin validation: approved for GSSoC scoring level:critical 80 pts difficulty label for critical or high-impact PRs type:security Security work category bonus label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CRITICAL] Sensitive Data Exposure: Debug Mode Defaults to True with Full Traceback Leakage

2 participants