# 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: Media 3 lenguajes cubiertos - Impact: Medio Se recomienda revisión - Prevention: Documentada 5 ejemplos de corrección **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 Estrategias de prevención para Error Message Information Leak basadas en 2 reglas de detección de Shoulder. ### 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 - Leer datos de la aplicación - Leer archivos o directorios ## Mitigations - Maneja las excepciones internamente y no muestres errores al usuario - Crea páginas de error predeterminadas para errores HTTP como 404 y 500 - Implementa un manejo de errores adecuado que registre los detalles en el servidor pero muestre mensajes genéricos a los usuarios ## 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