I made an interesting discovery. Microsoft, HashiCorp, Apache and Spring have all had a kind of bug you wouldn't believe. It has been happening for a while now, and it's crazy. Let me share it.
I came across this while researching Kotlin and Spring Boot security, reading JetBrains' tutorial Secure Your APIs: OAuth2 and JWT for Beginners, by Mdu Sibisi. If you write Kotlin and Spring Boot and haven't set up Spring Security before, it walks you through the fix.
The problem: an API receives a JWT, verifies its signature and expiry, and lets the request in. It never checks the issuer (iss, who created the token) or the audience (aud, which app the token is for). So a real, properly signed token meant for a different app, or from an issuer you never meant to trust, still gets accepted.
Since 2023, at least five projects and platforms have accepted tokens that were genuinely signed but never meant for them. This might sound like something less serious, but it is ridiculously serious.
Are these vibe coded apps?
No.
Microsoft, July 2023. Attackers got hold of a signing key meant only for consumer Microsoft accounts. Because of what Microsoft called "a validation issue", Exchange Online also trusted that key for enterprise tokens, and the attackers used forged tokens to read customers' email.
HashiCorp Vault, June 2024. Vault "did not properly validate" the audience claim on JWT logins, so a token meant for a different audience could log in when it should have been rejected.
Apache CXF, 2026. CXF's token validator never checked the audience at all, which allowed "a JWT issued for one Resource Server to be successfully replayed against a completely different Resource Server".
It keeps happening
Many others have had the same issue, including Argo CD and Spring Security itself (advisories linked at the bottom).
None of these was broken cryptography. The systems just didn't ask whether the token came from the right place, or whether it was meant for them.
I believe it's human error. In the end, every piece of code has an engineer responsible for it, and anybody could have forgotten this check. You might have missed it too. It can happen to anyone.
How it happens
A JWT carries claims. Two of them do the work here:
-
iss(issuer) says who printed the badge. -
aud(audience) says which door it opens.
This is the token a document API expects:
{
"iss": "https://myapp.com/auth",
"aud": "http://localhost:8080/api/",
"sub": "mdu",
"scope": "read:documents",
"exp": 1800000000
}
This one is for the same user and comes from the same issuer, with a valid signature. But it was issued for a different app:
{
"iss": "https://myapp.com/auth",
"aud": "https://billing.myapp.com/",
"sub": "mdu",
"scope": "read:documents",
"exp": 1800000000
}
Here is how the second token gets in, step by step:
- Your company runs one authorisation server, and it signs every token with the same private key, whichever app the token is for.
- A user logs in to the billing app and gets the second token. Its
audsays billing. - That token leaks: from a log, a compromised billing service, or a malicious app the user signed in to.
- Someone sends it to your document API as
Authorization: Bearer <token>. - Your API fetches the public key and verifies the signature. It passes, because the same server signed it.
- It checks
exp, and the token hasn't expired. It checks the scope, andread:documentsis there. - Nothing reads
aud. The request gets a 200.
Spring makes this easy to fall into. Give its resource server an issuer-uri and, by default, it checks the issuer, expiry (exp) and nbf. It doesn't check the audience until you configure it.
The fix in Spring Boot is to set spring.security.oauth2.resourceserver.jwt.audiences to your own API's address:
spring:
security:
oauth2:
resourceserver:
jwt:
issuer-uri: https://myapp.com/auth
audiences: http://localhost:8080/api/
Be careful when you build your own JwtDecoder. Those properties no longer apply, so you have to add the issuer and audience checks yourself, as OAuth2TokenValidators on the decoder. With both in place, the wrong-audience and wrong-issuer tokens get rejected, while the first token still gets through.
The JetBrains guide
If you write Kotlin and Spring Boot but haven't set up Spring Security before, JetBrains' tutorial is where I'd start. Before any code, it explains the OAuth2 roles and what's inside a JWT, so the terms make sense by the time you meet them in the code.
I haven't written Spring Security for production before, and I still found it easy to follow. Building the first part in IntelliJ IDEA gave me enough of the concepts to write this article. The part I'm taking into my own projects is the issuer and audience check: an API without it still runs and still returns data, so it's easy to leave out.
One heads-up for the last step: the custom decoder needs a live authorisation server, so run mock-oauth2-server locally instead of using the key file from earlier.
Where AI can help
This is 2026, and we have very smart models. Should this still be happening now? It can. Nothing fails when the check is missing: the app compiles, tests can pass and everything runs fine. But I think AI can really help us catch some of these bugs, if we use it correctly.
I love an optimised workflow, so I use agent skills a lot. A skill makes the AI stop and think about the right things before it writes any code. Reach for one in any workflow you hand to an AI.
If you work with Kotlin or Spring, JetBrains has some really useful ones in its skills repository. The spring-security-configurator-auditor skill tells the agent:
Validate JWT issuer, audience, expiration, signature, and clock-skew assumptions deliberately.
It also warns:
JWT validation without issuer or audience checks is weaker than many teams realize.
And it won't let the agent skip testing: "Do not generate security config without tests for the key routes."
Checklist for your API
Whatever framework you use, Spring, Ktor, Express or anything else, go through this list for every API that accepts tokens:
- Check the signature against a key you trust.
- Check the expiry.
- Check the issuer.
- Check the audience.
- Require a scope or role for each endpoint.
- Write one test that sends a token meant for another app, and make sure it gets a 401.
Sources
- JetBrains, Secure Your APIs: OAuth2 and JWT for Beginners (Mdu Sibisi, 29 July 2026): https://us.list-manage.com/aMJMh2Vby89?e=e394d8521e&c2id=b6503ccfe68027c8a297bf9eb5be4907
- Argo CD, CVE-2023-22482: https://github.com/argoproj/argo-cd/security/advisories/GHSA-q9hr-j4rf-8fjc
- Spring Security, CVE-2026-22748: https://spring.io/security/cve-2026-22748
- Spring Security docs, OAuth 2.0 Resource Server JWT: https://docs.spring.io/spring-security/reference/servlet/oauth2/resource-server/jwt.html
- JetBrains skills catalogue: https://github.com/JetBrains/skills
Top comments (0)