Skip to content

Commit 3936842

Browse files
authored
fix: accept float claims but round down to ignore them (#492)
1 parent 48b0210 commit 3936842

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Diff for: src/JWT.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,18 @@ public static function decode(
152152

153153
// Check the nbf if it is defined. This is the time that the
154154
// token can actually be used. If it's not yet that time, abort.
155-
if (isset($payload->nbf) && $payload->nbf > ($timestamp + static::$leeway)) {
155+
if (isset($payload->nbf) && floor($payload->nbf) > ($timestamp + static::$leeway)) {
156156
throw new BeforeValidException(
157-
'Cannot handle token prior to ' . \date(DateTime::ISO8601, $payload->nbf)
157+
'Cannot handle token prior to ' . \date(DateTime::ISO8601, (int) $payload->nbf)
158158
);
159159
}
160160

161161
// Check that this token has been created before 'now'. This prevents
162162
// using tokens that have been created for later use (and haven't
163163
// correctly used the nbf claim).
164-
if (!isset($payload->nbf) && isset($payload->iat) && $payload->iat > ($timestamp + static::$leeway)) {
164+
if (!isset($payload->nbf) && isset($payload->iat) && floor($payload->iat) > ($timestamp + static::$leeway)) {
165165
throw new BeforeValidException(
166-
'Cannot handle token prior to ' . \date(DateTime::ISO8601, $payload->iat)
166+
'Cannot handle token prior to ' . \date(DateTime::ISO8601, (int) $payload->iat)
167167
);
168168
}
169169

0 commit comments

Comments
 (0)