Skip to content

parseKeySet consuming a lot of time #481

Closed
@joskfg

Description

@joskfg

Hello,

I have a case where I have a lot of clients (kids) that access my application. Currently my implementation is like

return JWT::decode($tokenString, $this->getJwks($useCache));

I didn't notice nothing until I've got a high volume of kids. The implementation from getJwks uses internally JWK::parseKeySet($jwks);. And this method is doing this loop

foreach ($jwks['keys'] as $k => $v) {
            $kid = isset($v['kid']) ? $v['kid'] : $k;
            if ($key = self::parseKey($v, $defaultAlg)) {
                $keys[(string) $kid] = $key;
            }
        }

This means that in my case, with 204 kids, for every request, when the token is validated, it parse the keys and it takes 191ms, that are 204 calls to openssl_pkey_get_public.

I think that it could be possible to just get the kid from the JWT header and generate the Key object for a single jwk instead of parse all of them.

Am I missing something? Is this approach right?

Tahnks

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions