Skip to content

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

Open
cosminmodoranu wants to merge 4 commits intopotatosalad:mainfrom
cosminmodoranu:main
Open

Add error handling for peek function when tokens with invalid payload are passed.#174
cosminmodoranu wants to merge 4 commits intopotatosalad:mainfrom
cosminmodoranu:main

Conversation

@cosminmodoranu
Copy link
Copy Markdown

@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