Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

`isExpired` doesn't correctly validate `iat`

オープン
#100 コメント 9 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
android, java

調査の方向性

lib/src/main/java/com/auth0/android/jwt/JWT.java の 161~171 行付近から始め、isExpired が時間の境界を計算して iat を検証している箇所を確認します。作成直後に使用された JWT で報告されたケースを再現し、その後、既存の leeway や有効期限チェックを弱めることなく、有効な iat が受け入れられることを確認します。

索引モデルが issue の本文から書いたものです。

説明

bug
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:

https://github.com/auth0/JWTDecode.Android/blob/df3eb302a2164abaef36a33fded58f99f516c731/lib/src/main/java/com/auth0/android/jwt/JWT.java#L161-L171

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

主要言語
Java
スター
457
フォーク
81
平均マージ
5時間 4分
マージ済み PR(30日)
5

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

auth0/JWTDecode.Android のほかの issue

auth0/JWTDecode.Android の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。