{"record":{"id":"418306ced987a806","repo":"lcobucci/jwt","slug":"the-jwt-string-is-missing-the-claim-part","errorCode":null,"errorMessage":"The JWT string is missing the Claim part","messagePattern":"The JWT string is missing the Claim part","errorType":"exception","errorClass":"Lcobucci\\JWT\\Token\\InvalidTokenStructure","httpStatus":null,"severity":"error","filePath":"src/Token/Parser.php","lineNumber":35,"sourceCode":"\nfinal readonly class Parser implements ParserInterface\n{\n    private const int MICROSECOND_PRECISION = 6;\n\n    public function __construct(private Decoder $decoder)\n    {\n    }\n\n    public function parse(string $jwt): TokenInterface\n    {\n        [$encodedHeaders, $encodedClaims, $encodedSignature] = $this->splitJwt($jwt);\n\n        if ($encodedHeaders === '') {\n            throw InvalidTokenStructure::missingHeaderPart();\n        }\n\n        if ($encodedClaims === '') {\n            throw InvalidTokenStructure::missingClaimsPart();\n        }\n\n        if ($encodedSignature === '') {\n            throw InvalidTokenStructure::missingSignaturePart();\n        }\n\n        $header = $this->parseHeader($encodedHeaders);\n\n        return new Plain(\n            new DataSet($header, $encodedHeaders),\n            new DataSet($this->parseClaims($encodedClaims), $encodedClaims),\n            $this->parseSignature($encodedSignature),\n        );\n    }\n\n    /**\n     * Splits the JWT string into an array\n     *","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/lcobucci/jwt/blob/375813049c24c7111bda8b6884c57b071ceb2fe7/src/Token/Parser.php#L17-L53","documentation":"Parser::parse() requires the second JWT segment (the Base64Url-encoded claims/payload) to be non-empty. When it is empty, InvalidTokenStructure::missingClaimsPart() is thrown. A JWT shaped 'header..signature' is structurally invalid.","triggerScenarios":"Calling parse('header..signature') — e.g. a token built with an empty payload or corrupted so the claims section was removed.","commonSituations":"Truncated tokens from log scraping; tokens mangled by systems that strip empty segments; hand-assembled tokens in tests; copying only header and signature.","solutions":["Obtain the token from the authoritative issuer rather than reconstructing it manually","Validate token shape before parsing with a regex like /^[^\\s.]+\\.[^\\s.]+\\.[^\\s.]+$/","Catch InvalidTokenStructure and return a 401 'malformed token' response","Check the storage/transport path for truncation (DB column size, header size limits)"],"exampleFix":"// before\n$token = $parser->parse($jwt);\n// after\nif (!preg_match('/^[^\\.]+\\.[^\\.]+\\.[^\\.]+$/', $jwt)) {\n    throw new InvalidArgumentException('Malformed JWT: missing parts');\n}\n$token = $parser->parse($jwt);","handlingStrategy":"validation","validationCode":"$parts = explode('.', $jwt); if (count($parts) !== 3 || $parts[1] === '') { throw new InvalidArgumentException('JWT claims missing'); }","typeGuard":null,"tryCatchPattern":"try { $token = $parser->parse($jwt); } catch (Lcobucci\\JWT\\InvalidTokenStructure $e) { return error_401('Malformed token'); }","preventionTips":["Regex-validate the full 3-segment shape before parsing","Do not hand-assemble tokens in tests — use the Builder","Watch for transport-layer truncation of the middle segment"],"tags":["jwt","parser","malformed-token","php"],"backgroundTag":"invalid-argument-format","analyzedSha":"375813049c24c7111bda8b6884c57b071ceb2fe7","analyzedAt":"2026-09-14T11:12:28.004Z","contentChangedAt":"2026-09-14T11:12:28.004Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}