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

Redirect back gives an infinite loop #26055

Closed
Whyounes opened this issue Oct 10, 2018 · 5 comments
Closed

Redirect back gives an infinite loop #26055

Whyounes opened this issue Oct 10, 2018 · 5 comments

Comments

@Whyounes
Copy link

  • Laravel Version: 5.5.*
  • PHP Version: 7.1
  • Database Driver & Version:

Description:

When the back URL is the same URL that throws the error, we get a redirect loop.

Steps To Reproduce:

  • Create a posts/create route
  • Inside the controller create a method to handle the request.
  • CreateFormRequest class to validate the request, and set authorize methode to return false.
  • Since this will throw an authorization exception, inside the Handler we redirect()->back()->withErrors("Authorization problem")
  • Go to your browser and navigate to posts/create
@AegirLeet
Copy link
Contributor

Well, yes, if visiting /posts/create returns a redirect to /posts/create, which returns another redirect and so on, you end up with an infinite loop. Or were you expecting some different behavior? What would that look like?

I suggest you either return a 403 (this is the default behavior) or return a redirect to some fixed URL that won't generate another redirect.

@Whyounes
Copy link
Author

@AegirLeet The problem here, is that when this problem happens, it's hard to find why you have an infinite redirect loop. Since redirect()->back() is supposed to return back, we can use the $fallback parameter when the back URL is the same as the current one. This will prevent the infinite redirect loop.

@laurencei
Copy link
Contributor

This has already been fixed in the latest 5.7 release: #25739

@LadyNay
Copy link

LadyNay commented Jan 7, 2019

I am sorry to say, but in my 5.7 as soon as it redirects it says:
ErrorException (E_ERROR)
Undefined variable: logos (View: ###\resources\views\admin\website\logos\index.blade.php)
After updating something

@laurencei
Copy link
Contributor

@LadyDeathKZN - that is a local error for you. It clear says the logo variable is undefined.

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

No branches or pull requests

4 participants