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.
So behebst du diese Schwachstelle
Präventionsstrategien für Improper Authentication basierend auf 2 Shoulder-Erkennungsregeln.
Use jwt.verify() instead of jwt.decode() when assigning user identity
- const decoded = jwt.decode(token); + const decoded = jwt.verify(token, process.env.JWT_SECRET, { + algorithms: ['HS256'] + }); req.user = decoded;
Use early returns for authentication failures and constant-time comparison
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)})
Finden Sie Schwachstellen in Ihrem Code
Verwenden Sie Shoulder, um Ihren Code nach Improper Authentication-Mustern zu scannen. 2 Regeln.
# Scan with Shoulder CLI npx @shoulderdev/cli trust --cwe=287 # Or scan entire project npx @shoulderdev/cli trust .
Erkennungsregeln (2)
Worauf bei Code-Reviews zu achten ist
Diese Muster weisen auf potenzielle Improper Authentication-Schwachstellen hin. Achten Sie bei Code-Reviews und Sicherheitsaudits darauf.
Scanne deine Codebasis nach Improper Authentication
Shoulder CLI findet anfällige Muster in deiner gesamten Codebasis.