Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Broken-User-Authentication/JWTSigningAlgHS256.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
id: JWT_SIGNING_ALG_HS256
info:
name: JWT signed using HS256 algorithm
description: "The JSON Web Token (JWT) is signed using the HS256 algorithm. This symmetric algorithm is vulnerable to brute-force attacks if the secret key lacks sufficient complexity, allowing attackers to forge tokens."
details: |
"The application uses the HS256 (HMAC using SHA-256) algorithm to sign JWTs. This is a symmetric algorithm, meaning the same secret key is used to both create and validate the token's signature. This setup is vulnerable because the secret key can potentially be reverse-engineered using brute-force methods, especially if it is not long or complex enough. Unlike asymmetric algorithms like RS256, which use a private/public key pair, HS256 relies on a single shared secret. If an attacker discovers this secret through brute-forcing or other means, they can forge valid tokens at will. This completely undermines the integrity of the authentication process."
impact: |
"If an attacker successfully cracks the HS256 secret key, they can forge valid JWTs with any payload they choose. This could lead to a full account takeover by allowing them to impersonate other users, including administrators. For example, an attacker could escalate their privileges and gain unauthorized access to sensitive data and functions."
category:
name: NO_AUTH
shortName: Broken User Authentication
displayName: Broken User Authentication (BUA)
subCategory: JWT_SIGNING_ALG_HS256
severity: MEDIUM
tags:
- Business logic
- OWASP top 10
- HackerOne top 10
references:
- https://portswigger.net/web-security/jwt#brute-forcing-secret-keys
- https://auth0.com/blog/brute-forcing-hs256-is-possible-the-importance-of-using-strong-keys-to-sign-jwts/
attributes:
nature: NON_INTRUSIVE
plan: FREE
duration: FAST
api_selection_filters:
response_code:
gte: 200
lt: 300
request_headers:
for_one:
value:
jwt_signing_alg: HS256
execute:
type: passive
requests:
- req: []
validate:
response_code:
gte: 200
lt: 300
28 changes: 28 additions & 0 deletions remediation/JWT_SIGNING_ALG_HS256.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@


## Remediation Steps for JWT signed using HS256 algorithm Vulnerability
The JWT HS256 algorithm vulnerability arises because HS256 is a symmetric algorithm, meaning it uses the same secret key to both sign and verify a token. If this secret key is weak or exposed, an attacker can brute-force it to forge valid tokens and gain unauthorized access.
### Step 1: Use Strong Asymmetric Algorithms
The most effective remediation is to switch from a symmetric algorithm (like HS256) to an asymmetric algorithm (like RS256 or ES256). Asymmetric algorithms use a private key to sign the token and a separate public key to verify it. Since the private key never leaves the server, it cannot be intercepted and used by an attacker to forge tokens.
```javascript
// BAD: Using a shared secret with a symmetric algorithm
const token = jwt.sign(payload, 'my-weak-secret', { algorithm: 'HS256' });

// GOOD: Using a private key to sign with an asymmetric algorithm
const privateKey = fs.readFileSync('path/to/private.key');
const token = jwt.sign(payload, privateKey, { algorithm: 'RS256' });
```
In the good example, a private key is used for signing. Only the corresponding public key, which can be shared safely, is needed for verification.
### Step 2: Enforce a Strong, High-Entropy Secret Key
If you must continue using HS256, it is critical to use a secret key that is long, random, and has high entropy to make brute-force attacks impractical.
* DO NOT use common words, simple phrases, or predictable patterns.
* DO use a cryptographically secure random string with a recommended length of at least 32 characters (256 bits).
```javascript
// BAD: Weak, guessable secret
const weakSecret = 'password123';

// GOOD: Strong, randomly generated secret
const strongSecret = 'D8A6F7B4E29C1D05G3H6I9J2K5L8M1N4P7Q0R3S6T9U2';
```
### Step 3: Implement Key Rotation
Regularly rotating your secret keys (or private keys) is a crucial security practice. Key rotation limits the time an attacker has to exploit a compromised key. If a key is leaked, it will only be valid until the next rotation cycle, minimizing the potential damage.