Skip to content

Conversation

saranshdhingra
Copy link

Is it worth making sure we return the headers from decodeHeaders as an array?

Headers often have dashed key names and in order to access them currently, the user will have to do: $cls->{'x-header-key'}.

In order to make sure we return array, I think it's best to add a default argument to JWT::jsonDecode which forwards the second param to \json_decode().

@bshaffer
Copy link
Collaborator

We do not want to add a utility function to decode headers because this could encourage our users to decode insecure headers (this happens before any validation occurs). To exclude these helpers is an intentional decision. Additionally, if users want to check their headers (insecurely), they can do so easily:

list($headersB64, $payloadB64, $sig) = explode('.', $jwt);
$headers = json_decode(base64_decode($headersB64), true);

@bshaffer
Copy link
Collaborator

It may be a good idea to add this to the README so that we do not keep getting these requests

@saranshdhingra saranshdhingra force-pushed the add-helpers-decode-headers branch from b2d5db7 to f4c294f Compare April 25, 2023 09:54
@saranshdhingra
Copy link
Author

It may be a good idea to add this to the README so that we do not keep getting these requests

Updated PR to only show the example in the readme.

Copy link
Collaborator

@bshaffer bshaffer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds more disclaimers and information regarding unvalidated headers

@bshaffer bshaffer changed the title chore: Added helper to decode headers in JWT.php chore(docs): example of unsafe header decode in README May 3, 2023
@bshaffer bshaffer merged commit 7970104 into firebase:main May 4, 2023
shenkimaro pushed a commit to shenkimaro/php-jwt that referenced this pull request May 30, 2023
shenkimaro pushed a commit to shenkimaro/php-jwt that referenced this pull request May 30, 2023
shenkimaro pushed a commit to shenkimaro/php-jwt that referenced this pull request Jul 7, 2023
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 this pull request may close these issues.

2 participants