# Active Debug Code (CWE-489) The product is deployed to unauthorized actors with debugging code still enabled or active, which can create unintended entry points or information leaks. - Prevalence: High Frequently exploited - Impact: Critical 1 critical-severity rules - Prevention: Documented 6 fix examples **OWASP:** Security Misconfiguration (A05:2021-Security Misconfiguration) - #5 ## Description Debug code is often written to allow easier testing and debugging. This code is not intended to be shipped to production but is sometimes inadvertently left in the product. Debug code often exposes information about the product's internal structure or creates additional attack surface. ## Prevention Prevention strategies for Active Debug Code based on 6 Shoulder detection rules. ### Python Load DEBUG from environment variables, defaulting to False in production Load Flask debug mode from environment variables, defaulting to False ### Go Disable Echo debug mode in production to prevent stack trace exposure Disable Fiber debug output and route printing in production Set Gin to release mode in production to suppress debug output ### Node.js Use environment variables for debug configuration instead of hardcoded flags ## Warning Signs - [HIGH] Flask applications running with debug mode enabled - [MEDIUM] Debug flag at line ... is hardcoded to true - [MEDIUM] hardcoded debug flags that expose sensitive information or enable debugging features in production - [CRITICAL] Django applications with DEBUG = True in settings ## Consequences - Read Application Data - Bypass Protection Mechanism - Execute Unauthorized Code ## Mitigations - Remove debugging code before deploying the product to production - Use build configurations that automatically exclude debug code from production builds - Audit code for debug endpoints and backdoors before release ## Detection - Total rules: 6 - Critical: 1 - Languages: python, go, javascript, typescript ## Rules by Language ### Go (3 rules) - **Echo Debug Mode in Production** [MEDIUM]: Echo debug mode exposes stack traces and verbose errors in production. - Remediation: Disable debug mode in production. ```go e := echo.New() e.Debug = false ``` Learn more: https://shoulder.dev/learn/go/cwe-489/debug-mode - **Fiber Debug Mode in Production** [MEDIUM]: Fiber debug configuration exposes route structure and stack traces. - Remediation: Use production configuration to disable debug output. ```go app := fiber.New(fiber.Config{ DisableStartupMessage: true, EnablePrintRoutes: false, }) ``` Learn more: https://shoulder.dev/learn/go/cwe-489/debug-mode - **Gin Debug Mode in Production** [MEDIUM]: Gin debug mode exposes routing info and verbose errors in production. - Remediation: Set release mode before creating the router. ```go gin.SetMode(gin.ReleaseMode) r := gin.Default() ``` Learn more: https://shoulder.dev/learn/go/cwe-489/debug-mode ### Python (2 rules) - **Django Debug Mode in Production** [CRITICAL]: Detects Django applications with DEBUG = True in settings. Debug mode exposes sensitive information including settings, environment variables, SQL queries, and stack traces. This must NEVER be enabled in production. - Remediation: Load DEBUG from environment variables, defaulting to False. ```python import os DEBUG = os.getenv('DJANGO_DEBUG', 'False').lower() == 'true' ALLOWED_HOSTS = ['example.com', 'www.example.com'] ``` Learn more: https://shoulder.dev/learn/python/cwe-489/debug-mode - **Flask Debug Mode in Production** [HIGH]: Detects Flask applications running with debug mode enabled. Debug mode exposes sensitive information, allows code execution through the interactive debugger, and should NEVER be enabled in production. - Remediation: Load debug mode from environment variables, defaulting to False. ```python import os from flask import Flask app = Flask(__name__) if __name__ == '__main__': debug = os.getenv('FLASK_DEBUG', 'False').lower() == 'true' app.run(debug=debug) ``` Learn more: https://shoulder.dev/learn/python/cwe-489/debug-mode ### Javascript (1 rules) - **Debug Mode Enabled in Production** [MEDIUM]: Detects hardcoded debug flags that expose sensitive information or enable debugging features in production. - Remediation: Use environment variables for debug/development mode configuration. ### Typescript (1 rules) - **Debug Mode Enabled in Production** [MEDIUM]: Detects hardcoded debug flags that expose sensitive information or enable debugging features in production. - Remediation: Use environment variables for debug/development mode configuration.