{"record":{"id":"7fded22729db9b2d","repo":"roundcube/roundcubemail","slug":"failed-to-validate-jwt-invalid-aud-value","errorCode":null,"errorMessage":"Failed to validate JWT: invalid aud value","messagePattern":"Failed to validate JWT: invalid aud value","errorType":"validation","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"program/include/rcmail_oauth.php","lineNumber":450,"sourceCode":"            $this->fetch_jwks();\n\n            // Validate the token (throws exceptions)\n            $header = new \\stdClass();\n            $body = (array) JWT::decode($jwt, JWK::parseKeySet($this->jwks), $header);\n            $header = (array) $header;\n        } else {\n            [$headb64, $bodyb64, $cryptob64] = explode('.', $jwt);\n\n            $header = json_decode(static::base64url_decode($headb64), true);\n            $body = json_decode(static::base64url_decode($bodyb64), true);\n            // $crypto = static::base64url_decode($cryptob64);\n        }\n\n        // FIXME depends on body type: ID, Logout, Bearer, Refresh,\n        if (isset($body['azp']) && $body['azp'] !== $this->options['client_id']) {\n            throw new \\RuntimeException('Failed to validate JWT: invalid azp value');\n        } elseif (isset($body['aud']) && !in_array($this->options['client_id'], (array) $body['aud'])) {\n            throw new \\RuntimeException('Failed to validate JWT: invalid aud value');\n        } elseif (!isset($body['azp']) && !isset($body['aud'])) {\n            throw new \\RuntimeException('Failed to validate JWT: missing aud/azp value');\n        }\n\n        // if defined in parameters, check that issuer match\n        if (isset($this->options['issuer']) && $body['iss'] !== $this->options['issuer']) {\n            throw new \\RuntimeException('Failed to validate JWT: issuer mismatch');\n        }\n\n        // check that token is not an outdated message\n        if (isset($body['exp']) && (time() > $body['exp'])) {\n            throw new \\RuntimeException('Failed to validate JWT: expired message');\n        }\n\n        $body['header'] = $header;\n\n        $this->log_debug('jwt: %s', json_encode($body));\n","sourceCodeStart":432,"sourceCodeEnd":468,"githubUrl":"https://github.com/roundcube/roundcubemail/blob/4b54c2acfb54d5ee3d1c281ca7f143bed0dea804/program/include/rcmail_oauth.php#L432-L468","documentation":"jwt_decode() checks that when a token carries an 'aud' (audience) claim, the configured client_id must be among its audiences. This guards against accepting tokens minted for other relying parties.","triggerScenarios":"parse_tokens() -> jwt_decode() where the token body has no mismatching 'azp' but its 'aud' array/string does not contain $this->options['client_id'].","commonSituations":"Roundcube configured with the wrong client_id; IDP audience restriction excluding Roundcube's client; token reuse across services; multi-tenant IDP issuing tokens for a sibling client.","solutions":["Verify 'oauth_client_id' matches the client registered with the IDP for Roundcube.","Decode the token and compare 'aud' with the configured client_id.","Add Roundcube's client to the IDP's allowed audience list, or request tokens with the correct audience scope.","Obtain a fresh token via the normal authorization-code flow rather than reusing one from another app."],"exampleFix":"// before\n\"aud\": [\"other-app\"], // config client_id = 'roundcube'\n// after\n\"aud\": [\"roundcube\"],","handlingStrategy":"validation","validationCode":"$claims = json_decode(base64_decode(strtr(explode('.', $token)[1], '-_', '+/')), true);\n$aud = isset($claims['aud']) ? (array) $claims['aud'] : [];\nif ($aud && !in_array(RCUBE_OAUTH_CLIENT_ID, $aud, true)) { /* abort: wrong audience */ }","typeGuard":"function audIncludes(array $claims, string $clientId): bool { return !isset($claims['aud']) || in_array($clientId, (array) $claims['aud'], true); }","tryCatchPattern":"try { $payload = $oauth->jwt_decode($token); } catch (\\RuntimeException $e) { // force re-login / token refresh }","preventionTips":["Verify IDP audience restrictions include the Roundcube client.","Decode tokens during integration to confirm audience claims.","Request tokens with the audience scope matching the configured client_id."],"tags":["oauth","jwt","validation","oidc"],"backgroundTag":"invalid-argument-value","analyzedSha":"4b54c2acfb54d5ee3d1c281ca7f143bed0dea804","analyzedAt":"2026-09-14T13:23:19.231Z","contentChangedAt":"2026-09-14T13:23:19.231Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}