| name | cwe-347-jwt-signature-bypass |
| description | Use this skill when you need to remediate CWE-347 (JWT Signature Bypass) vulnerabilities in Java code. Triggers on SAST findings, security reviews, or when fixing jwt signature bypass issues. |
| version | 1.0.0 |
| license | MIT |
| tags | ["security","java","cwe-347","remediation","sast"] |
CWE-347 JWT Signature Bypass
Description
JWT Signature Bypass
Reference:
https://cwe.mitre.org/data/definitions/347.html
OWASP Category: A02:2021 – Cryptographic Failures
Vulnerable Pattern
❌ Example 1: Vulnerable Pattern
DecodedJWT jwt = JWT.decode(token);
String userId = jwt.getClaim("userId").asString();
Algorithm algorithm = Algorithm.HMAC256(secret);
JWTVerifier verifier = JWT.require(algorithm).build();
Why it's vulnerable: This pattern is vulnerable to JWT Signature Bypass
Deterministic Fix
✅ Secure Implementation: Secure Implementation
try {
Algorithm algorithm = Algorithm.HMAC256(secret);
JWTVerifier verifier = JWT.require(algorithm)
.withIssuer("your-issuer")
.acceptLeeway(60)
.build();
DecodedJWT jwt = verifier.verify(token);
if ("none".equalsIgnoreCase(jwt.getAlgorithm())) {
throw new JWTVerificationException("Algorithm 'none' not allowed");
}
String userId = jwt.getClaim("userId").asString();
} catch (JWTVerificationException e) {
throw new AuthenticationException("Invalid token", e);
}
Why it's secure: Implements proper protection against JWT Signature Bypass
Detection Pattern
Look for these patterns in your codebase:
grep -rn "JWT.decode(" --include="*.java"
grep -rn "DecodedJWT\\|JWTVerifier" --include="*.java"
Remediation Steps
-
Replace JWT.decode() with verifier.verify()
-
Explicitly reject 'alg: none' tokens
-
Validate issuer, audience, and expiration claims
-
Use strong secret keys (256+ bits for HMAC)
Key Imports
import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
Verification
After remediation:
-
Run SAST scanner to confirm vulnerability is resolved
-
Review all instances of the vulnerable pattern
-
Add unit tests that verify the secure implementation
-
Check for similar patterns in related code
Trigger Examples
Fix CWE-347 vulnerability
Resolve JWT Signature Bypass issue
Secure this Java code against jwt signature bypass
SAST reports CWE-347
Common Vulnerable Locations
| Controller | *Controller.java | User input handling |
| Service | *Service.java | Business logic |
| Repository | *Repository.java | Data access |
References
Source: Generated by Java CWE Security Skills Generator
Last Updated: 2026-03-07