{"record":{"id":"5263bfc3cb4031e4","repo":"moodle/moodle","slug":"no-issue-time-in-token-json-body","errorCode":null,"errorMessage":"No issue time in token: $json_body","messagePattern":"No issue time in token: \\$json_body","errorType":"exception","errorClass":"Google_Auth_Exception","httpStatus":null,"severity":"error","filePath":"public/lib/google/src/Google/Auth/OAuth2.php","lineNumber":564,"sourceCode":"    foreach ($certs as $keyName => $pem) {\n      $public_key = new Google_Verifier_Pem($pem);\n      if ($public_key->verify($signed, $signature)) {\n        $verified = true;\n        break;\n      }\n    }\n\n    if (!$verified) {\n      throw new Google_Auth_Exception(\"Invalid token signature: $jwt\");\n    }\n\n    // Check issued-at timestamp\n    $iat = 0;\n    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","sourceCodeStart":546,"sourceCodeEnd":582,"githubUrl":"https://github.com/moodle/moodle/blob/48ea8c33227277e916cdd4079dbecef448b37f2c/public/lib/google/src/Google/Auth/OAuth2.php#L546-L582","documentation":"The JWT payload decoded from the token body has no 'iat' (issued-at) claim, or it is 0. verifySignedJwtWithCerts requires iat to compute the earliest acceptable time window, so a token without it is rejected.","triggerScenarios":"verifyIdToken()/verifySignedJwt() called with a token whose JSON body lacks the 'iat' field — typically a non-standard or hand-crafted JWT, or a token whose payload decodes to an object without iat.","commonSituations":"Developers minting their own JWTs for testing without setting iat, tokens issued by non-Google systems being validated against Google certs, or iat encoded as a string \"0\"/null after bad JSON manipulation.","solutions":["Ensure the token issuer includes the 'iat' claim as a numeric Unix timestamp in the payload.","If you mint test JWTs, add iat: time() before signing.","Only pass Google-issued ID tokens to verifyIdToken(); validate other tokens with the appropriate issuer's library."],"exampleFix":"// before (minting a test JWT)\n$payload = ['exp' => time() + 3600];\n// after\n$payload = ['iat' => time(), 'exp' => time() + 3600];","handlingStrategy":"validation","validationCode":"$payload = json_decode(base64_decode(str_replace(['-', '_'], ['+', '/'], explode('.', $token)[1]) . '=='), true);\nif (empty($payload['iat'])) { throw new InvalidArgumentException('Token missing iat claim'); }","typeGuard":"function hasIat(array $payload) { return isset($payload['iat']) && is_numeric($payload['iat']) && $payload['iat'] > 0; }","tryCatchPattern":null,"preventionTips":["Only verify standard OIDC ID tokens, which always carry iat","If minting test JWTs, always include numeric iat and exp claims","Never modify the JWT payload in transit"],"tags":["jwt","missing-claim","google-auth"],"backgroundTag":"missing-required-jwt-claim","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"}