Skip to content

empty kid check breaks in latest version during decode #504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
shayaantx opened this issue May 3, 2023 · 1 comment · Fixed by #505
Closed

empty kid check breaks in latest version during decode #504

shayaantx opened this issue May 3, 2023 · 1 comment · Fixed by #505
Assignees

Comments

@shayaantx
Copy link

shayaantx commented May 3, 2023

Hi,

Forgive me if I'm missing something obvious. I recently upgraded from 5.2 to latest and noticing an issue where I get an UnexpectedValueException thrown with message '"kid" empty, unable to lookup correct key'.

The kid in this case is '0' (a string) errors because of the empty check that is new to post 5.2.x. See below screenshot for proof of example data

image

The old code didn't have this issue because it checked the old header object for the 'kid' property and "correctly" returned the $key out of the $key array (otherwise it would run through the empty check)

        if (\is_array($key) || $key instanceof \ArrayAccess) {
            if (isset($header->kid)) {
                if (!isset($key[$header->kid])) {
                    throw new UnexpectedValueException('"kid" invalid, unable to lookup correct key');
                }
                $key = $key[$header->kid];
            } else {
                throw new UnexpectedValueException('"kid" empty, unable to lookup correct key');
            }
        }

Seems like the empty() check should only happen if the following condition is not true, since the $keyOrKeyArray does indeed have a key with the right 'kid' index.

isset($keyOrKeyArray[$kid])

Again I'm unsure if I'm missing something obvious here, but it seems valid to have a kid of '0' if the keyOrKeyArray is valid. One thing I don't know is if keyOrKeyArray should be some random object (see screenshot) or something that implements ArrayAccess, but it still wouldn't matter if the 'kid' is '0' as the same error would be thrown

@shayaantx
Copy link
Author

thanks @ajupazhamayil and @bshaffer for fixing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants