# Unchecked Error Condition (CWE-391) The product does not properly check when a function or operation returns a value that is associated with an error condition. **Stack:** Python - Prevalence: 中 覆盖 3 种语言 - Impact: 高 1 条严重级别为高的规则 - Prevention: 已记录 3 个修复示例 **OWASP:** Insecure Design (A04:2021-Insecure Design) - #4 ## Description When error conditions are not checked, the application may continue with invalid or unexpected state, potentially leading to crashes, data corruption, or security vulnerabilities. ## Prevention 基于 1 条 Shoulder 检测规则的 Unchecked Error Condition 预防策略。 ### Python Log exceptions or handle them explicitly instead of silently swallowing with pass ## Warning Signs - [MEDIUM] empty except blocks that silently swallow exceptions ## Consequences - 拒绝服务 (DoS) - 执行未授权代码 - 修改应用程序数据 ## Mitigations - 检查所有返回值与错误条件 - 在适当的地方使用异常处理 - 实现适当的错误恢复机制 ## Detection - Total rules: 3 - Languages: go, javascript, typescript, python ## Rules by Language ### Python (1 rules) - **Empty Exception Handler** [MEDIUM]: Detects empty except blocks that silently swallow exceptions. This can hide security-critical errors, authentication failures, or data validation issues. - Remediation: Log exceptions or handle them explicitly instead of using empty except blocks. ```python import logging logger = logging.getLogger(__name__) try: risky_operation() except Exception as e: logger.error(f"Operation failed: {e}", exc_info=True) return {'error': 'Operation failed'}, 500 ``` Learn more: https://shoulder.dev/learn/python/cwe-391/empty-except