# Cwe 347 JWT Signature Bypass

> 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.

- Skill: `developerscoffee/cwe-347-jwt-signature-bypass` (Agent Skill)
- Install (CLI): `npx skillmds@latest add developerscoffee/cwe-347-jwt-signature-bypass`
- Raw SKILL.md: https://api.skillmd.com/api/skills/developerscoffee/cwe-347-jwt-signature-bypass/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Security
- License: MIT
- Author: DevelopersCoffee (https://skillmd.com/u/developerscoffee)
- Updated: 2026-09-10
- Page: https://skillmd.com/skills/developerscoffee/cwe-347-jwt-signature-bypass

---


# 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

```java
// VULNERABLE: Decoding JWT without signature verification
DecodedJWT jwt = JWT.decode(token);  // NO SIGNATURE CHECK!
String userId = jwt.getClaim("userId").asString();

// VULNERABLE: Not checking for 'none' algorithm
Algorithm algorithm = Algorithm.HMAC256(secret);
JWTVerifier verifier = JWT.require(algorithm).build();
// Attacker can send token with alg=none and skip verification
```


**Why it's vulnerable:** This pattern is vulnerable to JWT Signature Bypass




---

## Deterministic Fix


### ✅ Secure Implementation: Secure Implementation

```java
// SECURE: Always verify JWT signature
try {
    Algorithm algorithm = Algorithm.HMAC256(secret);
    JWTVerifier verifier = JWT.require(algorithm)
        .withIssuer("your-issuer")
        .acceptLeeway(60)  // 60 seconds leeway for clock skew
        .build();

    DecodedJWT jwt = verifier.verify(token);  // Throws if invalid

    // Additional check: Reject 'none' algorithm explicitly
    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:


```bash
# Find JWT.decode without verification
grep -rn "JWT.decode(" --include="*.java"
```


```bash
# Find JWT usage patterns
grep -rn "DecodedJWT\\|JWTVerifier" --include="*.java"
```



---

## Remediation Steps


1. Replace JWT.decode() with verifier.verify()

2. Explicitly reject 'alg: none' tokens

3. Validate issuer, audience, and expiration claims

4. Use strong secret keys (256+ bits for HMAC)


---

## Key Imports

```java

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

| Layer | Files | Patterns |
|-------|-------|----------|

| Controller | `*Controller.java` | User input handling |

| Service | `*Service.java` | Business logic |

| Repository | `*Repository.java` | Data access |


---

## References


- [CWE-347: Improper Verification of Cryptographic Signature](https://cwe.mitre.org/data/definitions/347.html)


---

**Source**: Generated by [Java CWE Security Skills Generator](https://github.com/DevelopersCoffee/java-cwe-security-skills)
**Last Updated**: 2026-03-07

