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

Unable to exclude URIs from CSRF verification #53

Closed
MatanYadaev opened this issue Jan 21, 2020 · 3 comments
Closed

Unable to exclude URIs from CSRF verification #53

MatanYadaev opened this issue Jan 21, 2020 · 3 comments
Labels

Comments

@MatanYadaev
Copy link
Contributor

MatanYadaev commented Jan 21, 2020

  • Airlock Version: 0.1.0
  • Laravel Version: 6.9.0
  • PHP Version: 7.4.0
  • Database Driver & Version: MySQL 5.7

Description:

I can't exclude URIs from CSRF verification because of this LoC
Laravel Airlock is using the middleware from the Illuminate package instead of the local one.
This way the $except remains always an empty array, and I can't exclude URIs.

Steps To Reproduce:

  1. Add URIs to the $except array in App\Http\Middleware\VerifyCsrfToken.php file.
  2. Try to access this route without a CSRF token.

Suggestion

Add to the config/airlock.php file a configuration variable:

'csrfMiddleware` => App\Http\Middleware\VerifyCsrfToken::class,

And make sure to use it in the EnsureFrontendRequestAreStateful:

static::fromFrontend($request) ? [
  \Illuminate\Cookie\Middleware\EncryptCookies::class,
  \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
  \Illuminate\Session\Middleware\StartSession::class,
  Config::get('airlock.csrfMiddlewareClass', \Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::class),
: []
@driesvints
Copy link
Member

Hmm that indeed seems problematic but I'm not sure if the current solution is the best one? What you can do instead is perhaps bind your implementation to the foundation one through the container:

$this->app->bind(
    \Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::class,
    \App\Http\Middleware\VerifyCsrfToken::class
);

@MatanYadaev
Copy link
Contributor Author

@driesvints My solution may not be the best one, but binding to the container it's just a workaround in my opinion.
I'm sure more some people are using the $except property, so a solution must be documented for them.

@lukadriel7
Copy link
Contributor

Hello, I Think the same should apply to the EncryptCookies middleware too.

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

No branches or pull requests

3 participants