# Generation of Error Message Containing Sensitive Information (CWE-209) The product generates an error message that includes sensitive information about its environment, users, or associated data. **Stack:** JavaScript - Prevalence: Medium 3 languages covered - Impact: Medium Review recommended - Prevention: Documented 5 fix examples **OWASP:** Insecure Design (A04:2021-Insecure Design) - #4 ## Description The sensitive information may be valuable information on its own, or it may be useful for launching other, more serious attacks. The error message may be created in different ways, and the information that is included can range widely. ## Prevention Prevention strategies for Error Message Information Leak based on 2 Shoulder detection rules. ### JavaScript Return generic error messages to users and log detailed errors server-side Configure errorFormatter to strip stack traces in production and use TRPCError with generic messages ## Warning Signs - [MEDIUM] exposure of sensitive error information (error - [MEDIUM] Error handling exposes implementation details. Use error formatter to sanitize errors in production. ## Consequences - Read Application Data - Read Files or Directories ## Mitigations - Handle exceptions internally and do not display errors to the user - Create default error pages for HTTP errors such as 404 and 500 - Implement proper error handling that logs detailed errors server-side but shows generic messages to users ## Detection - Total rules: 5 - Languages: go, javascript, typescript, python ## Rules by Language ### Javascript (2 rules) - **Information Exposure Through Error Messages** [MEDIUM]: Detects exposure of sensitive error information (error.message, error.stack, raw error objects) in HTTP responses. This can leak: - Internal file paths and directory structure - Database schema and query details - Third-party API endpoints and credentials - Software versions and technology stack - Business logic and validation rules Attackers use this information to: - Map internal architecture - Identify vulnerable dependencies - Craft targeted attacks - Bypass security controls - Remediation: Return generic error messages to users and log detailed errors server-side. ```javascript } catch (error) { logger.error('Failed', { error: error.message }); res.status(500).json({ error: 'An error occurred' }); } ``` Learn more: https://shoulder.dev/learn/javascript/cwe-209/error-message-exposure - **tRPC Error Information Disclosure** [MEDIUM]: Exposing raw errors, stack traces, or database details to clients aids attackers in reconnaissance and exploitation. - Remediation: Use errorFormatter to sanitize errors in production. ```typescript export const t = initTRPC.context().create({ errorFormatter({ shape }) { return { ...shape, data: { ...shape.data, stack: process.env.NODE_ENV === 'production' ? undefined : shape.data.stack } }; } }); ``` Learn more: https://shoulder.dev/learn/typescript/cwe-209/error-information-leak ### Typescript (2 rules) - **Information Exposure Through Error Messages** [MEDIUM]: Detects exposure of sensitive error information (error.message, error.stack, raw error objects) in HTTP responses. This can leak: - Internal file paths and directory structure - Database schema and query details - Third-party API endpoints and credentials - Software versions and technology stack - Business logic and validation rules Attackers use this information to: - Map internal architecture - Identify vulnerable dependencies - Craft targeted attacks - Bypass security controls - Remediation: Return generic error messages to users and log detailed errors server-side. ```javascript } catch (error) { logger.error('Failed', { error: error.message }); res.status(500).json({ error: 'An error occurred' }); } ``` Learn more: https://shoulder.dev/learn/javascript/cwe-209/error-message-exposure - **tRPC Error Information Disclosure** [MEDIUM]: Exposing raw errors, stack traces, or database details to clients aids attackers in reconnaissance and exploitation. - Remediation: Use errorFormatter to sanitize errors in production. ```typescript export const t = initTRPC.context().create({ errorFormatter({ shape }) { return { ...shape, data: { ...shape.data, stack: process.env.NODE_ENV === 'production' ? undefined : shape.data.stack } }; } }); ``` Learn more: https://shoulder.dev/learn/typescript/cwe-209/error-information-leak