# Unchecked Return Value (CWE-252) The product does not check the return value from a method or function, which can prevent it from detecting unexpected states and conditions. - Prevalence: Média 2 linguagens cobertas - Impact: Alto 1 regras de severidade alta - Prevention: Documentada 2 exemplos de correção **OWASP:** Insecure Design (A04:2021-Insecure Design) - #4 ## Description When return values are not checked, the program may continue execution in an error state or with incorrect data, potentially leading to security vulnerabilities. ## Prevention Estratégias de prevenção para Unchecked Return Value baseadas em 2 regras de detecção do Shoulder. ### Go Replace blank identifier _ with err and check error return values ### JavaScript Always check return values from critical operations like password comparison and database writes ## Warning Signs - [HIGH] Return value from ... at ... is not checked - [HIGH] critical operations (file system, database, authentication) whose return values are not checked ## Consequences - DoS - Executar código não autorizado - Modificar dados da aplicação ## Mitigations - Sempre verifique os valores de retorno das funções - Use avisos do compilador para detectar valores de retorno não verificados - Trate condições de erro de forma adequada ## Detection - Total rules: 2 - Languages: go, javascript, typescript ## Rules by Language ### Go (1 rules) - **Unchecked Error Return Values** [MEDIUM]: Error return value ignored using blank identifier (_). - Remediation: Check all error return values and handle appropriately. ```go data, err := ioutil.ReadFile(path) if err != nil { return fmt.Errorf("failed to read file: %w", err) } ``` Learn more: https://shoulder.dev/learn/go/cwe-252/unchecked-errors ### Javascript (1 rules) - **Unchecked Return Value from Critical Operations** [HIGH]: Detects critical operations (file system, database, authentication) whose return values are not checked. Ignoring return values can lead to silent failures, data corruption, and security vulnerabilities. Critical operations that must have their return values checked include: - File system operations (write, delete, chmod) - Database operations (insert, update, delete) - Authentication/authorization checks - Cryptographic operations - Remediation: Always check return values from critical operations: ```javascript // ✅ SAFE - Check return value const result = await fs.writeFile(path, data); if (!result.success) { logger.error('Write failed'); throw new Error('Failed to write file'); } ``` ### Typescript (1 rules) - **Unchecked Return Value from Critical Operations** [HIGH]: Detects critical operations (file system, database, authentication) whose return values are not checked. Ignoring return values can lead to silent failures, data corruption, and security vulnerabilities. Critical operations that must have their return values checked include: - File system operations (write, delete, chmod) - Database operations (insert, update, delete) - Authentication/authorization checks - Cryptographic operations - Remediation: Always check return values from critical operations: ```javascript // ✅ SAFE - Check return value const result = await fs.writeFile(path, data); if (!result.success) { logger.error('Write failed'); throw new Error('Failed to write file'); } ```