Home / patterns

Debug or preview mode left on in production

A concerned developer in a small office looking at a laptop with a blurred settings panel and a bright red toggle switch, a server rack softly out of focus behind him, no brand logos
Quick answer: AI-generated apps often ship with Django DEBUG = True, Flask’s debugger, a development server, or an open preview playground still turned on. That leftover debug code is CWE-489. Django’s deployment checklist says you must never enable debug in production because error pages leak source excerpts, local variables, settings and installed libraries. Flask’s docs say not to run the development server or built-in debugger in production—the debugger can execute Python from the browser. Turn debug off, serve the production build, and keep verbose diagnostics in server-side logs.

Last updated November 13, 2026

Steps

  1. Search configuration and startup code for debug flags: DEBUG = True, app.run(debug=True), flask run --debug, NODE_ENV=development, Next.js next dev used as the production command, Express error handlers that dump stacks, an open GraphQL or API playground, profiler or __debug__ routes, and preview or staging middleware that is reachable on the live hostname.
  2. Set production so debug is off and cannot be flipped from a public request. In Django, DEBUG = False and a non-empty ALLOWED_HOSTS (Django will not run without ALLOWED_HOSTS when debug is off). Load the flag from an environment variable that is false in production.
  3. Do not run the framework’s development server on the public site. Use the production server your platform expects (for example a WSGI/ASGI server for Django or Flask, or next start / the host’s production build for Next.js).
  4. Confirm Flask/Werkzeug’s interactive debugger is off. Flask’s documentation warns that the debugger allows executing Python from the browser and that its PIN is not something to rely on for security.
  5. Close extra debug surfaces: verbose error pages (see the related pattern on leaking stack traces), source maps on the production hostname, unauthenticated preview or GraphiQL/Swagger UIs, and any “debug toolbar” package.
  6. Keep detailed errors in server logs or an error-tracking tool that only your team can see—not in the response sent to users.
  7. Retest by triggering a harmless error on production-like settings and confirming the user sees a generic message, not a traceback, source excerpt or debugger.

Why it matters

CWE-489, Active Debug Code (also called leftover debug code), is when a product is released with debugging code still enabled. MITRE notes it can lead to bypassing protections, reading application data or gaining privileges, depending on what the debug features expose. Django’s official deployment checklist is direct: never enable debug in production, because it leaks lots of information about your project. Flask’s debugging guide is equally direct: do not run the development server or enable the built-in debugger in production. The OWASP Django Security Cheat Sheet likewise treats turning DEBUG off as a production requirement. This is a configuration mistake to find in your own deployment, not a reason to probe someone else’s site.

Sources

MITRE CWE-489: Active Debug Code — https://cwe.mitre.org/data/definitions/489.html

Django documentation: Deployment checklist — https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/

Flask documentation: Debugging Application Errors — https://flask.palletsprojects.com/en/stable/debugging/

OWASP Cheat Sheet: Django Security — https://cheatsheetseries.owasp.org/cheatsheets/Django_Security_Cheat_Sheet.html

Checked at the source on November 8, 2026.

Related patterns

Found a problem you'd rather not fix yourself?

Tell us what's wrong. A StorenTech engineer reviews your app and replies with a fixed quote, so you know the cost before any work starts.

Get it fixed by StorenTech

Vibe Security Weekly

One email a week with new failure patterns and how to fix them.

By joining you agree we may email you this newsletter. See our privacy policy. Free. Unsubscribe anytime. We'll never sell your email.