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

Unchecked Return Value

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

Unchecked Return Value

The product does not check the return value from a method or function, which can prevent it from detecting unexpected states and conditions.

When return values are not checked, the program may continue execution in an error state or with incorrect data, potentially leading to security vulnerabilities.

普遍性
覆盖 2 种语言
影响
1 条严重级别为高的规则
预防
已记录
2 个修复示例
2 预防
2 预防

如何修复此漏洞

基于 2 条 Shoulder 检测规则的 Unchecked Return Value 预防策略。

Unchecked Error Return Values MEDIUM

Replace blank identifier _ with err and check error return values

+4 -1 go
- data, _ := ioutil.ReadFile(path)
+ data, err := ioutil.ReadFile(path)
+ if err != nil {
+     return fmt.Errorf("failed to read %s: %w", path, err)
+ }
  process(data)
  
Unchecked Return Value from Critical Operations HIGH

Always check return values from critical operations like password comparison and database writes

+4 -2 javascript
- bcrypt.compare(req.body.password, user.passwordHash);
- // Proceeds without checking the result
+ const isValid = await bcrypt.compare(req.body.password, user.passwordHash);
+ if (!isValid) {
+   return res.status(401).json({ error: 'Invalid credentials' });
+ }
  const token = generateToken(user);
  
4 警告信号
4 警告信号

代码审查中需要关注的内容

这些模式表明潜在的Unchecked Return Value漏洞。在代码审查和安全审计中注意查找。

🟠
Return value from ... at ... is not checked javascript-unchecked-return-value
🟠
critical operations (file system, database, authentication) whose return values are not checked javascript-unchecked-return-value
🔍

扫描你的代码库: Unchecked Return Value

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