Back to Blog
Engineering12 min read

JWT Forging, Replay, and the alg=none Trick — Validated, Not Speculated

P

Pentestas Team

Security Analyst

5/7/2026
JWT Forging, Replay, and the alg=none Trick — Validated, Not Speculated
TL;DR · Key insight

Explore JWT forging, replay attacks, and the infamous alg=none trick through validated methods rather than speculation. Learn how Pentestas implements these techniques to confirm role escalation vulnerabilities in a controlled environment.

Introduction to JWT and Its Vulnerabilities

JSON Web Tokens (JWT) are a compact and self-contained way of transmitting information between parties as a JSON object. They are commonly used for authentication and information exchange in web applications, offering a stateless mechanism for session management. Typically, a JWT comprises three parts: a header, a payload, and a signature, which are concatenated with periods. The header usually specifies the type of token and the signing algorithm being used, while the payload contains the claims or data being transmitted. The signature is used to verify the sender's authenticity and ensure the message wasn't altered.

Despite their widespread adoption, JWTs are not immune to security vulnerabilities. One of the most infamous is the alg=none vulnerability, which allows an attacker to bypass signature verification entirely. This occurs when a server does not properly validate the token's algorithm, accepting any JWT with alg=none as valid. Furthermore, replay attacks pose a significant threat, as attackers can capture valid tokens and reuse them to gain unauthorized access to protected resources.

Understanding JWT forging and replay attacks is crucial for developers and security professionals alike. These vulnerabilities have been exploited in real-world scenarios, leading to data breaches and unauthorized access. For instance, in 2022, several online platforms were compromised due to poorly implemented JWT handling, resulting in unauthorized data access and financial losses. By delving into these vulnerabilities, we aim to equip our readers with the knowledge to secure their applications against such attacks.

What Readers Will Learn

This post will provide a comprehensive understanding of JWT vulnerabilities, including JWT forging and replay attacks. Readers will learn how to identify these threats and implement robust security measures to protect their applications. By the end, you will have actionable insights to strengthen your JWT-based authentication systems.

JWT Forging: The Basics

JWT forging involves the creation of fake JSON Web Tokens that appear valid to a server. These tokens are typically used in authentication systems to verify user identities. The process of forging a JWT often exploits vulnerabilities in how tokens are verified, bypassing normal security checks. Attackers can modify the token payload, headers, or signature to manipulate claims and gain unauthorized access. Understanding the mechanics of JWT forging is crucial for developers aiming to secure their applications against such attacks.

Several techniques can be employed to forge JWTs. One common method is brute-forcing the secret key used to sign the token. Another approach involves exploiting weak signing algorithms, such as RS256, if the server mistakenly trusts a public key without proper validation. A notorious example is the alg=none trick, where an attacker sets the algorithm to "none" in the JWT header, tricking poorly configured servers into accepting an unsigned token.

Cryptographic keys play an integral role in maintaining JWT integrity. Each JWT is signed with a private key known only to the issuer, ensuring that any tampering with the token's content results in a signature mismatch. When cryptographic keys are compromised, the entire authentication mechanism is at risk, allowing attackers to forge tokens with valid signatures. Ensuring the security of these keys, including rotation and proper storage, is paramount to preventing JWT forgery.

Real-World Example

In 2021, a security breach in a popular platform was traced back to JWT forgery, where attackers exploited the alg=none vulnerability. This allowed unauthorized access to sensitive user data, highlighting the importance of proper JWT validation and cryptographic practices.

The "none" algorithm trick is a particularly egregious vulnerability because it subverts the entire premise of JWTs, which is to provide a verifiable claim of identity. When a server does not properly check that the token is signed with a valid algorithm, it may accept a token that has no signature at all. It's a stark reminder that even simple oversights can lead to significant security breaches. Implementing strict validation for JWTs and ensuring that only supported algorithms are used can mitigate such risks.

Replay Attacks Explained

Replay attacks occur when a valid data transmission is maliciously or fraudulently repeated. This type of attack leverages the fact that many systems do not adequately check the freshness of the data they receive. In the context of JWTs (JSON Web Tokens), this can happen if a token, once captured, is resent to a service without being expired or invalidated. Attackers exploit this by intercepting a token during transmission and then using it to gain unauthorized access to a system repeatedly.

JWT vulnerabilities are a fertile ground for replay attacks. The situations where JWTs are stored or transmitted insecurely provide attackers with opportunities to capture them. Once an attacker has a JWT, they can replay it to impersonate the original user. The stateless nature of JWTs means that many systems might not even be aware that a token is being reused, especially if the token is valid and has not expired. This contrasts with other attacks, like session fixation or man-in-the-middle, which involve different mechanisms of exploiting sessions.

The implications of a successful replay attack can be severe, ranging from unauthorized access to sensitive data to full account takeovers. For instance, if a JWT is used to authorize financial transactions, replaying the token could allow an attacker to duplicate transactions or access financial information. This makes robust token management crucial for security. Systems must ensure that each token is used only once and that any attempt to reuse a token is detected and blocked immediately.

Common Defenses Against Replay Attacks

To mitigate replay attacks, implementing nonce values or timestamps is crucial. Nonces ensure that each token is unique, even if the payload is the same, while timestamps can help detect and reject tokens that are being reused outside of their valid timeframe.

The Infamous alg=none Trick

In the early days of JSON Web Tokens (JWTs), security researchers stumbled upon a rather alarming oversight in the JWT specification: the alg=none trick. This trick was discovered around 2015 and exploits the flexibility of JWTs in specifying the algorithm used for signing. By setting the signing algorithm to "none," attackers could bypass signature verification entirely, essentially tricking the system into accepting unsigned tokens as valid.

Technically, the alg=none trick works by manipulating the JWT header. The header, which is a base64-encoded JSON object, typically specifies the algorithm type. When set to "none," it signals the application to treat the token as already verified. Consider the following JWT header:

{
  "alg": "none",
  "typ": "JWT"
}

The impact of this trick on JWT security is severe. It undermines the entire purpose of token verification, allowing attackers to forge tokens with arbitrary claims. This can lead to unauthorized access and privilege escalation. Multiple case studies have shown real-world applications vulnerable to this trick, including popular web applications and APIs, which were exploited until patched.

At Pentestas, we identify this vulnerability through rigorous token analysis and header inspection. Our automated tools flag any occurrence of alg=none and perform checks against a library of known secure algorithms such as HS256 or RS256. Mitigation involves enforcing strict algorithm policies and rejecting tokens with "none" as the algorithm.

Implementing JWT Forging and Replay in Pentestas

In our exploration of JWT vulnerabilities, Pentestas employs a multi-faceted approach that allows us to effectively assess and exploit potential weaknesses. Our strategy involves a blend of automated tools and manual testing techniques to uncover security gaps in JWT implementations. Key to our approach is ensuring that the tests are comprehensive and reflect real-world scenarios, which helps us identify vulnerabilities that are often overlooked. We leverage our platform's ability to simulate various attack vectors, ensuring that we cover all possible angles when testing for JWT vulnerabilities.

The tools and technologies integrated into the Pentestas platform are crucial to our testing process. We utilize open-source libraries such as jwt-tool and jwt-cli to forge and decode tokens. Additionally, our platform integrates with AI-driven vulnerability scanners, which enhance our ability to identify potential JWT flaws efficiently. The combination of these tools allows us to automate many aspects of the testing process, while our manual inspection ensures accuracy and depth.

To simulate JWT forging and replay attacks, we follow a series of methodical steps. Initially, we capture a valid JWT from an HTTP request. We then modify the token using our toolset to test for forgery by altering the payload, header, or signature. For replay attacks, we attempt to reuse a valid token to access the application after its intended expiration. This process involves checking the server's ability to properly validate token expiration and revocation. Our case study on a recent project revealed that a target system was vulnerable to token replay due to improper expiration handling, which we demonstrated by successfully accessing user data with an expired token.

AI-driven techniques significantly enhance our ability to identify JWT vulnerabilities. By automating pattern recognition and anomaly detection, these techniques allow us to quickly pinpoint potential weaknesses that might not be immediately visible during manual inspections. The AI algorithms continuously learn from each engagement, improving our platform's accuracy and efficiency over time. This approach not only saves time but also increases the reliability of our findings, ensuring that our clients receive the most thorough security assessment possible.

Validating Role Escalation with Real Endpoints

Role escalation is a critical vulnerability where an attacker gains unauthorized access to higher privilege operations by exploiting service misconfigurations. This can lead to severe security breaches, allowing attackers to perform actions meant for administrators or other privileged users. Understanding the significance of role escalation is imperative for maintaining a secure application environment. It ensures that only authorized users can access or modify sensitive data, which is essential for compliance with data protection regulations.

To validate role escalation, we simulate JWT attacks by forging tokens with altered claims. By manipulating the alg=none header, we bypass signature verification and test if the system improperly grants elevated access. Our methodology involves crafting JWTs that mimic legitimate tokens but with escalated privileges, then observing if the backend accepts them without proper validation.

const jwt = require('jsonwebtoken');
const token = jwt.sign({ "role": "admin" }, "", { algorithm: 'none' });
fetch('https://api.example.com/admin', {
  method: 'GET',
  headers: { 'Authorization': `Bearer ${token}` }
}).then(response => response.json())
  .then(data => console.log(data));

In practical scenarios, we observed endpoints where altering the token’s payload led to unauthorized access to administrative dashboards or exposed sensitive endpoints. These findings underscore the need for strict JWT validation mechanisms. At Pentestas, we ensure the accuracy of our validation by employing automated tools alongside manual testing to confirm vulnerabilities. This dual approach enhances both the efficiency and reliability of our security assessments.

Lessons from Real-World Validations

We've learned that endpoint behavior varies significantly across different environments, necessitating a tailored approach for each validation. Consistently, we've found that even well-configured systems can harbor overlooked vulnerabilities, emphasizing the importance of continuous security evaluations.

Best Practices for Securing JWTs

Securing JSON Web Tokens (JWTs) against forging and replay attacks is crucial for maintaining the integrity of web applications. One effective way to do this is by employing strong cryptographic algorithms such as HS256 or RS256. Avoid using none as an algorithm, which leaves JWTs vulnerable to attacks. Implementing a short expiration time for tokens and refreshing them periodically can significantly reduce the risk of replay attacks.

Strong cryptographic practices are the backbone of JWT security. Ensuring that secret keys are long, randomly generated, and stored securely can prevent unauthorized access. For example, using tools like openssl to generate keys can enhance security:

openssl rand -base64 32

Regular security assessments and audits are essential to identify potential vulnerabilities in JWT implementations. At Pentestas, we assist our clients by conducting thorough audits and providing actionable insights into their JWT configurations. Our security experts leverage state-of-the-art tools to uncover weaknesses and recommend best practices for fortifying JWTs against attacks.

Enhancing JWT Security

Pentestas provides clients with resources such as security guidelines and tools like jwt.io for ongoing JWT management. By staying updated with the latest security trends, we ensure our clients are protected against emerging threats.

Conclusion and Future Directions

In this exploration of JWT vulnerabilities, we delved into the nuances of JWT forgery and the infamous alg=none trick. We demonstrated the potential risks such manipulations pose and emphasized the critical importance of robust token validation processes. This discussion highlighted that even well-established standards like JWTs are not immune to exploitation, necessitating continuous vigilance and updates in security practices.

While JWTs provide a flexible mechanism for authentication, the security testing of these tokens still faces limitations. Current tools often lack the depth needed to uncover sophisticated exploits, such as those involving token replay or signature forgery. At Pentestas, we recognize this gap and are actively working on feature enhancements that will aid in more comprehensive security assessments. These improvements aim to automate the detection of anomalies in token handling, streamlining the identification of potential vulnerabilities.

Future Enhancements on Pentestas

We are developing an AI-driven module to enhance JWT testing capabilities, focusing on anomaly detection and automated threat modeling. Stay tuned for upcoming releases.

As cybersecurity threats evolve, so too must our approaches to combating them. We encourage continuous learning and adaptation, urging security practitioners to stay informed about emerging vulnerabilities and attack vectors. Engaging with the latest research and collaborating on platforms like Pentestas can empower professionals to better safeguard their systems. By taking proactive steps today, we can mitigate the risks of tomorrow's threats.

Finally, we call upon the security community to actively engage with new and existing vulnerabilities. By sharing insights and experiences, we can collectively enhance our defenses. Whether through contributing to open-source projects, participating in forums, or conducting independent research, every effort counts in fortifying our digital environments against sophisticated attacks.

Try it on your stack

Free tier includes 10 scans/month on a verified domain. No credit card required.

Start scanning

In Pentestas's daily pipeline

The technique above runs inside Pentestas — an AI penetration testing system delivered as pentesting-as-a-service that exposes the same primitives to operators via Forge, Volley, the OAST callback host, and a per-scan capture corpus. Our penetration testing with Claude routing handles narrative reasoning and finding triage; our penetration testing with DeepSeek routing handles bulk verification and exploit-DB matching. Either backend lands findings in the same dedupe pipeline, the same accuracy gate, and the same Big-4-style PDF report — so a B2B SaaS pentest produces the same evidence quality whichever model touched it.

For teams new to penetration testing with AI, the platform's free tier (10 verified-domain scans per month) is enough to validate the approach against your own stack before committing to a paid plan.

Alexander Sverdlov

Alexander Sverdlov

Founder of Pentestas. Author of 2 information security books, cybersecurity speaker at the largest cybersecurity conferences in Asia and a United Nations conference panelist. Former Microsoft security consulting team member, external cybersecurity consultant at the Emirates Nuclear Energy Corporation.