Unchecked Error Condition
The product does not properly check when a function or operation returns a value that is associated with an error condition.
When error conditions are not checked, the application may continue with invalid or unexpected state, potentially leading to crashes, data corruption, or security vulnerabilities.
普遍性
中
覆盖 3 种语言
影响
高
1 条严重级别为高的规则
预防
已记录
3 个修复示例
2 预防
2 预防
如何修复此漏洞
基于 3 条 Shoulder 检测规则的 Unchecked Error Condition 预防策略。
Go
查看全部 Go 详情 →
Empty Error Handling
LOW
Log or return errors instead of silently swallowing them
_, err := db.Exec("DELETE FROM sessions WHERE expired = true") if err != nil { + log.Printf("session cleanup failed: %v", err) + return err }
JavaScript
查看全部 JavaScript 详情 →
Unhandled Promise Rejection
HIGH
Always handle promise rejections with .catch() or try/catch in async functions
app.post('/create', async (req, res) => { - const user = await User.create(req.body); - res.json(user); + try { + const user = await User.create(req.body); + res.json(user); + } catch (error) { + logger.error('User creation failed:', error); + res.status(500).json({ error: 'Could not create user' }); + } });
Python
查看全部 Python 详情 →
Empty Exception Handler
MEDIUM
Log exceptions or handle them explicitly instead of silently swallowing with pass
- def get_data(): - try: - data = fetch_sensitive_data() - return {'data': data} - except: - pass + import logging + + logger = logging.getLogger(__name__) + + def get_data(): + try: + data = fetch_sensitive_data() + return {'data': data} + except Exception as e: + logger.error(f"Failed to fetch data: {e}", exc_info=True) + return {'error': 'Data unavailable'}, 500
3 检测
3 检测
查找代码中的漏洞
使用Shoulder扫描代码中的Unchecked Error Condition模式。 3 规则.
# Scan with Shoulder CLI npx @shoulderdev/cli trust --cwe=391 # Or scan entire project npx @shoulderdev/cli trust .
检测规则 (3)
4 警告信号
4 警告信号
代码审查中需要关注的内容
这些模式表明潜在的Unchecked Error Condition漏洞。在代码审查和安全审计中注意查找。
Promise at ... lacks rejection handler (.catch or try-catch)
javascript-unhandled-promise-rejection
promises that are created or called without proper rejection handlers
javascript-unhandled-promise-rejection
empty except blocks that silently swallow exceptions
python-empty-except-block