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

Limit storePreviousURL to certain requests #2126

Merged
merged 4 commits into from
Aug 15, 2019

Conversation

MGatner
Copy link
Member

@MGatner MGatner commented Aug 11, 2019

Description
Currently storePreviousUrl() will fire on AJAX requests, saving the URL from the AJAX request and causing redirect()->back() to return to routes that probably were never intended for direct browsing.

This change causes $_SESSION to be updated only when it is a valid IncomingRequest that is not CLI or AJAX (including these additional parameters helps with testing).

Checklist:

  • Securely signed commits
  • Component(s) with PHPdocs
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@@ -968,6 +969,12 @@ protected function gatherOutput($cacheConfig = null, $returned = null)
*/
public function storePreviousURL($uri)
{
// Only valid for some requests
if (! $this->request instanceof IncomingRequest || $this->request->isCLI() || $this->request->isAJAX())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little concerned with checking against IncomingRequest. it's entirely possible for someone to use a completely different IncomingRequest-like class. While I would think they would extend IncomingRequest there's nothing that limits them from doing something crazy. Better to either not check against a class type and just do the AJAX and CLI checks, or check against Request.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is how I had it originally but since neither Request nor RequestInterface require isAJAX() and isCLI() it was causing issues, e.g. CLI requests where giving "method doesn't exist" exceptions.

I guess I will try it by checking for each method, but I'm also open to an additional interface or some other means of defining a "browser visit".

// Only valid for some requests
if (! $this->request instanceof IncomingRequest || $this->request->isCLI() || $this->request->isAJAX())
// Ignore CLI requests
if (method_exists($this->request, 'isCLI') && $this->request->isCLI())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_cli() is an available function provided in Common.php, so no need to check, just use the helper function.

Unfortunately, none exists for is_ajax.

@MGatner
Copy link
Member Author

MGatner commented Aug 13, 2019

You had a productive night! I’ll make that change. Would you like me to take a crack at is_ajax() as well?

@lonnieezell
Copy link
Member

Feel free to take a look at it. I think that it requires info from IncomingRequest, though.

@MGatner
Copy link
Member Author

MGatner commented Aug 13, 2019

Okay I'll look at that later - we'll pick the low-hanging fruit for now.

@MGatner
Copy link
Member Author

MGatner commented Aug 15, 2019

@lonnieezell This one is all set.

@lonnieezell lonnieezell merged commit 6f156c5 into codeigniter4:develop Aug 15, 2019
@InsiteFX
Copy link
Contributor

is_ajax would be a IncomingRequest because it gets a lot of the information from $_SERVER[]

@MGatner MGatner deleted the ajax-return-url branch August 26, 2019 02:19
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

Successfully merging this pull request may close these issues.

3 participants