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

Add error handling for peek function when tokens with invalid payload are passed. #174

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

cosminmodoranu
Copy link

@cosminmodoranu cosminmodoranu commented Jul 22, 2024

This PR contains some changes that add error handling to peeking claims functions.
An issue I encountered is that if we supply a JWT with an invalid payload (like the token below), it would throw an exception.

JOSE.JWT.peek("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJteSI6IYWltIn0.ePRp64gsJScUPmQ6jJxBnup2ThKMsBeUroa0xopiU")
** (Jason.DecodeError) unexpected byte at position 6: 0x21 ("!")
    (jason 1.4.1) lib/jason.ex:92: Jason.decode!/2
    (jose 1.11.9) src/jwt/jose_jwt.erl:58: :jose_jwt.from_binary/1
    (jose 1.11.9) lib/jose/jwt.ex:193: JOSE.JWT.peek/1
    iex:1: (file)

The changes made in this PR make the functions return an error if the token's payload is malformed (instead of throwing an exception).

@cosminmodoranu cosminmodoranu changed the title Add error handling for tokens with invalid payload. Add error handling for peek function when tokens with invalid payload are passed. Jul 22, 2024
@cosminmodoranu cosminmodoranu marked this pull request as ready for review July 22, 2024 15:08
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.

1 participant