{"record":{"id":"b49c31578ec0a9bf","repo":"moodle/moodle","slug":"expiration-time-too-far-in-future-s","errorCode":null,"errorMessage":"Expiration time too far in future: %s","messagePattern":"Expiration time too far in future: (.+?)","errorType":"exception","errorClass":"Google_Auth_Exception","httpStatus":null,"severity":"error","filePath":"public/lib/google/src/Google/Auth/OAuth2.php","lineNumber":578,"sourceCode":"    if (array_key_exists(\"iat\", $payload)) {\n      $iat = $payload[\"iat\"];\n    }\n    if (!$iat) {\n      throw new Google_Auth_Exception(\"No issue time in token: $json_body\");\n    }\n    $earliest = $iat - self::CLOCK_SKEW_SECS;\n\n    // Check expiration timestamp\n    $now = time();\n    $exp = 0;\n    if (array_key_exists(\"exp\", $payload)) {\n      $exp = $payload[\"exp\"];\n    }\n    if (!$exp) {\n      throw new Google_Auth_Exception(\"No expiration time in token: $json_body\");\n    }\n    if ($exp >= $now + $max_expiry) {\n      throw new Google_Auth_Exception(\n          sprintf(\"Expiration time too far in future: %s\", $json_body)\n      );\n    }\n\n    $latest = $exp + self::CLOCK_SKEW_SECS;\n    if ($now < $earliest) {\n      throw new Google_Auth_Exception(\n          sprintf(\n              \"Token used too early, %s < %s: %s\",\n              $now,\n              $earliest,\n              $json_body\n          )\n      );\n    }\n    if ($now > $latest) {\n      throw new Google_Auth_Exception(\n          sprintf(","sourceCodeStart":560,"sourceCodeEnd":596,"githubUrl":"https://github.com/moodle/moodle/blob/48ea8c33227277e916cdd4079dbecef448b37f2c/public/lib/google/src/Google/Auth/OAuth2.php#L560-L596","documentation":"Thrown by verifySignedJwtWithCerts() when the JWT's 'exp' claim is at or beyond now + max_expiry — the token was issued with an unreasonably far-future expiration (or the cert max expiry is too small), so it is rejected as potentially fraudulent.","triggerScenarios":"verifySignedJwtWithCerts() (via verifyIdToken/verifySignedJwt) called with a token whose exp exceeds now + $max_expiry — e.g. default 1-hour limit exceeded, or the caller passed a small $max_expiry while using a long-lived token.","commonSituations":"Minting your own JWT with a multi-day/month expiry and validating it with verifyIdToken()'s default max_expiry; or passing a deliberately short $max_expiry argument that conflicts with your issuer's token lifetime.","solutions":["Reduce the token lifetime at issuance so exp is within the allowed window (Google ID tokens: <= 1 hour).","If your use case legitimately needs longer-lived tokens, pass a larger $max_expiry to verifySignedJwtWithCerts/verifyIdToken.","Check for clock problems: a badly wrong client clock can distort the comparison less often than a bad exp, but verify server time is NTP-synced."],"exampleFix":"// before\n$payload = $client->verifyIdToken($token); // default max_expiry=1h, token valid 30 days\n// after\n$payload = $client->verifyIdToken($token, $audience, $issuer, 60 * 60 * 24 * 30);","handlingStrategy":"validation","validationCode":"$maxExpiry = 3600;\n$payload = json_decode(base64_decode(str_replace(['-','_'],['+','/'], explode('.', $token)[1]) . '=='), true);\nif (isset($payload['exp']) && $payload['exp'] >= time() + $maxExpiry) {\n  throw new InvalidArgumentException('Token lifetime exceeds allowed max expiry');\n}","typeGuard":"function expWithinLimit(array $payload, $maxExpiry) { return isset($payload['exp']) && $payload['exp'] < time() + $maxExpiry; }","tryCatchPattern":"try {\n  $payload = $client->verifyIdToken($token);\n} catch (Google_Auth_Exception $e) {\n  if (strpos($e->getMessage(), 'Expiration time too far in future') !== false) {\n    // shorten token lifetime at issuance or raise max_expiry\n  }\n  throw $e;\n}","preventionTips":["Issue tokens with standard lifetimes (<= 1 hour for ID tokens)","Keep your $max_expiry argument consistent with your issuer's real token lifetime","Do not mint long-lived tokens for interactive login validation"],"tags":["jwt","token-expiry","google-auth"],"backgroundTag":"jwt-token-expired","analyzedSha":"48ea8c33227277e916cdd4079dbecef448b37f2c","analyzedAt":"2026-09-14T20:34:48.527Z","contentChangedAt":"2026-09-14T20:34:48.527Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}