Skip to content

Decode method does not enforce object return type #370

Closed
@markrandall

Description

@markrandall

The decode method declares an object return type using docblock, however this is not enforced by either userland runtime checks or a PHP return type, and the function will quite happily return a non-object result if the original JWT was created in such a way:

public function testDecodeNonObject(): void {
	$key = 'example';
	$token = JWT::encode(123, $key, 'HS256');
	$decoded = JWT::decode($token, $key, ['HS256']);
	self::assertIsObject($decoded);
}

This causes higher levels of static analysis to either fail to detect a possible error condition when using the return value, or alternatively create a false positive for a redundant check when verifying the return type is an object.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions