jwt icon indicating copy to clipboard operation
jwt copied to clipboard

json_encode method should use unescaped slashes

Open samckittrick opened this issue 8 years ago • 3 comments

Some of our "sub" claims contain forward slashes. I noticed that when the signature is verified and the unsigned value is generated, the json_encode function was adding backslashes to the subject.

I think the proper way to handle this would be to use "return json_encode($properties, JSON_UNESCAPED_SLASHES);"

samckittrick avatar Oct 12 '16 04:10 samckittrick

Hi, thanks for opening this issue. We are aware of this problem after diagnosing and discussing it in #21. Will track the progress here.

emarref avatar Oct 12 '16 06:10 emarref

@emarref you're having these issues here because this lib recreates the payload to verify the token. And slashes won't be your only problem since JSON encoding varies a lot - specially across different languages.

My advice is to always generate a small JSON string but allow the library to accept some weird stuff (like spaces after :, escaping or even a pretty JSON string).

On lcobucci/jwt I've solved this by saving the original encoded string, maybe you can do the same 😉

lcobucci avatar Feb 12 '17 21:02 lcobucci

Yeah, I realise that. My plan on #23 was to disable slashes by default, but allow them using options.

However your point about how much JSON encoding can differ is the reason I haven't completed this branch.

Saving the original encoded string looks like the best way to do it, thanks for the tip.

emarref avatar Feb 12 '17 21:02 emarref