`isExpired` doesn't correctly validate `iat`
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Domain
- authentication, security
Research direction
Start in lib/src/main/java/com/auth0/android/jwt/JWT.java around lines 161-171, where isExpired computes the time bounds and validates iat. Reproduce the reported case with a JWT used immediately after creation, then verify that a valid iat is accepted without weakening the existing leeway or expiration checks.
Written by the indexing model from the issue text.
Description
Checklist
- I have looked into the Readme and Examples, and have not found a suitable solution or answer.
- I have looked into the API documentation and have not found a suitable solution or answer.
- I have searched the issues and have not found a suitable solution or answer.
- I have searched the Auth0 Community forums and have not found a suitable solution or answer.
- I agree to the terms within the Auth0 Code of Conduct.
Description
Due to the way the isExpired was implemented, the iat is invalid for the first 0.5 seconds of JWT existence, given this code here:
The line 165 is rounding the current time. If your server is very fast and generate, transmit and reaches your application in less than 0.5s, the futureToday.before(payload.iat) on the line 169 returns false. But the JWT is totally valid.
Solutions:
- Also compare
futureToday == payload.iat. - Stop truncating the
todayTime.
I reimplemented the validation in Kotlin and added some logs:
fun isExpired(jwt: JWT, leeway: Int): Boolean {
val todayTime = (floor((Date().time / 1000).toDouble()) * 1000).toLong() //truncate millis
val futureToday = Date(todayTime + leeway * 1000)
val pastToday = Date(todayTime - leeway * 1000)
val expValid = jwt.expiresAt == null || !pastToday.after(jwt.expiresAt)
val iatValid = jwt.issuedAt == null || !futureToday.before(jwt.issuedAt)
return !expValid || !iatValid
}
This prints:
todayTime 1740576730000
futureToday 1740576730000
pastToday 1740576730000
expValid true
iatValid false
Reproduction
Probably create the JWT and use it straightway, it will fail on the iat.
Additional context
No response
JWTDecode.Android version
2.0.2
Android version(s)
API 32
- Dominant language
- Java
- Stars
- 455
- Forks
- 81
- Avg merge
- 5h 23m
- Merged PRs (30d)
- 8
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from auth0/JWTDecode.Android
-
feature request
Difficulty 4/5 3-5 days Newbie friendliness 35/100
auth0/JWTDecode.Android#82 · 10 reactions ·
-
Include proguard consumer directives for R8 compatibilityMay be free again A pull request for this issue was closed without being merged. Openfeature request
Difficulty 2/5 1-3 hours Newbie friendliness 52/100
auth0/JWTDecode.Android#72 · 7 comments · 3 reactions ·
All issues in auth0/JWTDecode.Android
Similar issues
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
it-at-m/Wahllokalsystem#3846 ·
Maintainers usually reply within 2 days
-
Area/Connector module/solace Priority/Low Type/Bug
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
ballerina-platform/ballerina-library#9849 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 65/100
Vakore/ZappierGames#327 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Radix number block generates NaN after switching a negative or decimal number to binary, octal or hexPossibly taken @matthewalberto claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
mit-cml/appinventor-sources#4246 · 1 comment ·
Maintainers usually reply within 1 day