Skip to content
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

chore(docs): example of unsafe header decode in README #501

Merged
merged 4 commits into from May 4, 2023

Conversation

saranshdhingra
Copy link
Collaborator

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
Copy link
Collaborator 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

README.md Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@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
10 checks passed
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.

None yet

2 participants