phalcon/cphalcon · error · InvalidHeader

Invalid Header (not an array)

Error message

Invalid Header (not an array)

What it means

Thrown by JWT Token Parser::decodeHeaders when base64-decoding and JSON-decoding the header segment does not yield an array. The header part of the token is malformed (not a JSON object). Verify the token's first segment encodes a JSON object.

Solutions

  1. Check that the token's first segment decodes to a JSON object
  2. Reject malformed tokens and force the client to obtain a fresh one
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at phalcon/Encryption/Security/JWT/Token/Parser.zep:113 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21). Data as JSON: /api/errors/4a3d32e66ded61a8. Report an issue: GitHub.

Appendix: source

Thrown at phalcon/Encryption/Security/JWT/Token/Parser.zep:113

        return new Item(decoded, claims);
    }

    /**
     * Decodes the headers
     *
     * @param string $headers
     *
     * @return Item
     */
    private function decodeHeaders(string headers) -> <Item>
    {
        var decoded;

        let decoded = this->decode->__invoke(this->doDecodeUrl(headers), true);

        if typeof decoded !== "array" {
            throw new InvalidHeader();
        }

        if !isset decoded[Enum::TYPE] {
            throw new MissingJwtTypHeader();
        }

        return new Item(decoded, headers);
    }

    /**
     * Decodes the signature
     *
     * @param Item   $headers
     * @param string $signature
     *
     * @return Signature
     */
    private function decodeSignature(<Item> headers,  string signature) -> <Signature>

View on GitHub (pinned to b7419de9cd)