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

Uncaught RuntimeException (with Slim4) #358

Closed
anandasubas opened this issue May 22, 2020 · 4 comments
Closed

Uncaught RuntimeException (with Slim4) #358

anandasubas opened this issue May 22, 2020 · 4 comments
Assignees

Comments

@anandasubas
Copy link

Request Headers:
Content-Type:"application/json"
cache-control:"no-cache"
Postman-Token:"7aa53299-d109-4574-9e5c-b8e6df3e4e0a"
Authorization:"Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0sssssssaSI6IjgxOGM5ZTY0LWQyZTktNGZjYy1iZjIyLWJmOWY5MmMxYjgxMCJ9.eyJpc3MiOiJ3d3cua2VuaW1hZGFsYS5jb20iLCJqdGkiOiI4MThjOWU2NC1kMmU5LTRmY2MtYmYyMi1iZjlmOTJjMWI4MTAiLCJpYXQiOjE1OTAxNTA5OTMsIm5iZiI6MTU5MDE1MDk5MywiZXhwIjoxNTkwMTY1MzkzLCJ1aWQiOiJsb2dpbiJ9.x8mtKaeRCURZ-B7wMdI_D86ZiZDn29n1TFjckwOaJ4L7mWz3MXDDItsqOkY8mTpgmiHhc-KgrrcBFGQica_G67hxV1F63_aAIe4rr4yDlha5pK28_c5VxEjeoOhRBmBWWYeWSC61sxNiOyAsA3fjFFC3fqtdtQC3KBl-T-sGFEYvpRJfEfc70be12QCppxkQpXY93HeqsZJS2hnf9l-raJexyQeVnJxUuqzG9BdZFtI3b7zcvY2qrYdeToN6FSWGUdJIea63Wfp2hOI_NUsqMAWbTOzTxPv3KILa9RR0eDxGivzBkkc7j1BWUZ-IypY1lXxSVFKXsIv1VhONWGU7nQ"
User-Agent:"PostmanRuntime/7.6.0"
Accept:"/"
Host:"slimapi.local"
accept-encoding:"gzip, deflate"
content-length:158
Request Body:
Response Headers:
Date:"Fri, 22 May 2020 13:05:24 GMT"
Server:"Apache/2.4.41 (Ubuntu)"
Vary:"Accept-Encoding"
Content-Encoding:"gzip"
Content-Length:"455"
Keep-Alive:"timeout=5, max=100"
Connection:"Keep-Alive"
Content-Type:"text/html; charset=UTF-8"

Response Body:


Fatal error: Uncaught RuntimeException: Error while decoding to JSON: Malformed UTF-8 characters, possibly incorrectly encoded in /var/www/slimapi/vendor/lcobucci/jwt/src/Parsing/Decoder.php:36
Stack trace:
#0 /var/www/slimapi/vendor/lcobucci/jwt/src/Parser.php(112): Lcobucci\JWT\Parsing\Decoder->jsonDecode()
#1 /var/www/slimapi/vendor/lcobucci/jwt/src/Parser.php(60): Lcobucci\JWT\Parser->parseHeader()
#2 /var/www/slimapi/src/Lib/JwtAuth.php(104): Lcobucci\JWT\Parser->parse()
#3 /var/www/slimapi/src/Lib/JwtAuth.php(115): App\Lib\JwtAuth->createParsedToken()
#4 /var/www/slimapi/src/Middleware/JwtMiddleware.php(45): App\Lib\JwtAuth->validateToken()
#5 /var/www/slimapi/vendor/slim/slim/Slim/MiddlewareDispatcher.php(188): App\Middleware\JwtMiddleware->process()
#6 /var/www/slimapi/vendor/slim/slim/Slim/Middleware/BodyParsingMiddleware.php(66): class@anonymous->handle()
#7 /var in /var/www/slimapi/vendor/lcobucci/jwt/src/Parsing/Decoder.php on line 36

@lcobucci
Copy link
Owner

lcobucci commented May 22, 2020

@anandasubas you have a token with invalid JSON data on the headers: https://3v4l.org/1LPTf

How did you issue the token?

@lcobucci
Copy link
Owner

lcobucci commented May 22, 2020

Closing as invalid since it's not really an issue of this library (feel free to comment btw).

@berndtja
Copy link

berndtja commented Aug 26, 2020

I got the same error.

RuntimeException: Error while decoding to JSON: Control character error, possibly incorrectly encoded in /var/www/phpinclude/vendor_composer/lcobucci/jwt/src/Parsing/Decoder.php:36
Stack trace:
#0 /var/www/phpinclude/vendor_composer/lcobucci/jwt/src/Parser.php(130): Lcobucci\JWT\Parsing\Decoder->jsonDecode('{"...')
#1 /var/www/phpinclude/vendor_composer/lcobucci/jwt/src/Parser.php(61): Lcobucci\JWT\Parser->parseClaims('...')

I sent the token by GET parameter. When I modified the token in the address bar of my browser randomly this error occurred.
Shouldn't the $token->validate() function catch this error and returns FALSE?

Or what can I do to prevent throwing the error?

@lcobucci
Copy link
Owner

@berndtja validation happens after parsing. If the library is throwing an exception during parsing is because it's unable to create a valid token object from the string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants