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

Request payload with key overrides token in cookies #227

Open
jmiller42ce opened this issue Nov 15, 2023 · 0 comments
Open

Request payload with key overrides token in cookies #227

jmiller42ce opened this issue Nov 15, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@jmiller42ce
Copy link

Subject of the issue

Some of the JSON models that we POST to our API contain a property called token. Since this library initializes the parser chain order as AuthHeaders, QueryString, InputSource, RouteParams, Cookies in AbstractServiceProvider and LaravelServiceProvider, the token property in the JSON is being used as a JWT token instead of the value in the cookie.

Your environment:

Q A
Bug? yes
New Feature? no
Framework Laravel
Framework version 8.83.27
Package version 2.0
PHP version 8.2

Steps to reproduce

  1. do not provide an authorization header, instead rely on the token contents in cookies (and therefore the cookie token parser).
  2. POST a request with a payload containing a form data attribute token:
Screenshot 2023-11-15 at 5 20 02 PM

Expected behaviour

Cookie tokens should be parsed before InputSource, or an option to do this should be provided. Some other packages (such as Laravel Nova where this request originated) cannot add headers to API requests and apparently must rely on cookies for authentication with JWT, so this is preventing the use of this package for Nova resources which have a column named token.

Actual behaviour

The incorrect token is being used and therefore the request is unauthorized.

Note you can use a workaround here by overriding Laravel's AuthServiceProvider boot method and including this:

        $parser = $this->app['tymon.jwt.parser'];

        $parser->setChain([
            new PHPOpenSourceSaver\JWTAuth\Http\Parser\Cookies($this->app->make('config')->get('jwt.decrypt_cookies')),
            ...$parser->getChain()
        ]);
@jmiller42ce jmiller42ce added the bug Something isn't working label Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant