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

Drip not working (no cookie attached) with route caching #153

Open
michellaurent opened this issue Jul 25, 2024 · 2 comments
Open

Drip not working (no cookie attached) with route caching #153

michellaurent opened this issue Jul 25, 2024 · 2 comments

Comments

@michellaurent
Copy link

Expected Behavior

The XSRF-TOKEN should be attached to the response when calling the drip endpoint.

Actual Behavior

No cookies are attached to the drip response when route caching is enabled. This is due to the fact that the drip route is not linked with the ‘web’ middleware group which add the cookie via the VerifyCRSF middleware. I think this is caused by the way the route are added in the ServiceProvider which is not compatible with route caching. Desactivating route caching in production solves the issue

Environment

  • PHP Version: 8.2
  • Laravel Version: 10.48.12
  • LaravelCaffeine Version: 10.0.2

Stack Trace

@mikebronner
Copy link
Owner

@michellaurent Thank you for reporting this. I'm not sure how soon I will be able to look into this, so if you are able to submit a PR with proposed changes, that would greatly help.

@michellaurent
Copy link
Author

@mikebronner

There is a check in Providers\Service.php to determine if the routes has to be loaded in the web middleware group or not. I think that this check fails when routes are cached.

        app('router')->group(app("router")->hasMiddlewareGroup('web')
            ? ['middleware' => 'web']
            : [], function () {
                require __DIR__ . '/../../routes/web.php';

                if (config("app.env") === 'internaltesting') {
                    require __DIR__ . '/../../tests/routes/web.php';
                }
            });

I don't understand the reason of this check as the VerifyCRSFmiddleware only applies to web

Capture d’écran 2024-07-25 à 20 52 39

It looks like that replacing the previous code with the code below (removing the check) solves the issue.

        app('router')->group(['middleware' => 'web'], function () {
                require __DIR__ . '/../../routes/web.php';

                if (config("app.env") === 'internaltesting') {
                    require __DIR__ . '/../../tests/routes/web.php';
                }
            });

By the way, the Laravel documentation suggests to use

$this->loadRoutesFrom(__DIR__.'/../routes/web.php');

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

2 participants