测试版 Shoulder 目前处于测试阶段 — 结果有时可能不正确。您的反馈塑造我们接下来要修复的内容。 分享反馈

Unchecked Error Condition

🛡️ 3 条规则检测到此问题

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 预防策略。

Empty Error Handling LOW

Log or return errors instead of silently swallowing them

+2 -0 go
  _, err := db.Exec("DELETE FROM sessions WHERE expired = true")
  if err != nil {
+     log.Printf("session cleanup failed: %v", err)
+     return err
  }
  
Unhandled Promise Rejection HIGH

Always handle promise rejections with .catch() or try/catch in async functions

+7 -2 javascript
  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' });
+   }
  });
  
Empty Exception Handler MEDIUM

Log exceptions or handle them explicitly instead of silently swallowing with pass

+11 -6 python
- 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
  
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
🔍

扫描你的代码库: Unchecked Error Condition

Shoulder CLI 在整个代码库中找到易受攻击的模式。