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

Improper Authentication

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

Improper Authentication

When an actor claims to have a given identity, the product does not prove or insufficiently proves that the claim is correct.

Authentication is the process of determining if a claimed identity is correct. When authentication is insufficient or incorrect, attackers can assume the identity of legitimate users.

普遍性
频繁被利用
影响
关键
2 条严重级别为关键的规则
预防
已记录
2 个修复示例
2 预防
2 预防

如何修复此漏洞

基于 2 条 Shoulder 检测规则的 Improper Authentication 预防策略。

JWT Decode Used for User Identity (Authentication Bypass) CRITICAL

Use jwt.verify() instead of jwt.decode() when assigning user identity

+3 -1 javascript
- const decoded = jwt.decode(token);
+ const decoded = jwt.verify(token, process.env.JWT_SECRET, {
+   algorithms: ['HS256']
+ });
  req.user = decoded;
  
Authentication Bypass Vulnerability CRITICAL

Use early returns for authentication failures and constant-time comparison

+8 -7 python
  from flask import request, jsonify
- 
- @app.route('/login', methods=['POST'])
- def login():
-     user = User.query.filter_by(username=request.json['username']).first()
-     if user and user.password == request.json['password']:
-         return jsonify({'token': generate_token(user)})
-     return jsonify({'error': 'Invalid'}), 401
+ from werkzeug.security import check_password_hash
+ 
+ @app.route('/login', methods=['POST'])
+ def login():
+     user = User.query.filter_by(username=request.json['username']).first()
+     if not user or not check_password_hash(user.password_hash, request.json['password']):
+         return jsonify({'error': 'Invalid credentials'}), 401
+     return jsonify({'token': generate_token(user)})
  
4 警告信号
4 警告信号

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

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

🔴
authentication checks that can be bypassed due to missing return statements or weak boolean logic python-authentication-bypass
🔍

扫描你的代码库: Improper Authentication

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