Skip to content

Commit 1890da5

Browse files
author
Azure Pipeplines CI
committed
fix: validate iat and nbf on payload
1 parent 500501c commit 1890da5

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/JWT.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ public static function decode(
127127
if (!$payload instanceof stdClass) {
128128
throw new UnexpectedValueException('Payload must be a JSON object');
129129
}
130+
if (isset($payload->iat) && !\is_numeric($payload->iat)) {
131+
throw new UnexpectedValueException('Payload iat must be a number');
132+
}
133+
if (isset($payload->nbf) && !\is_numeric($payload->nbf)) {
134+
throw new UnexpectedValueException('Payload nbf must be a number');
135+
}
136+
if (isset($payload->exp) && !\is_numeric($payload->exp)) {
137+
throw new UnexpectedValueException('Payload exp must be a number');
138+
}
139+
130140
$sig = static::urlsafeB64Decode($cryptob64);
131141
if (empty($header->alg)) {
132142
throw new UnexpectedValueException('Empty algorithm');
@@ -172,7 +182,7 @@ public static function decode(
172182
}
173183

174184
// Check if this token has expired.
175-
if (isset($payload->exp) && ($timestamp - static::$leeway) >= $payload->exp) {
185+
if (isset($payload->exp) && floor($payload->exp) && ($timestamp - static::$leeway) >= $payload->exp) {
176186
$ex = new ExpiredException('Expired token');
177187
$ex->setPayload($payload);
178188
throw $ex;

0 commit comments

Comments
 (0)