Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 041105c

Browse filesBrowse files
committed
feature symfony#3883 Removed redundant POST request exclusion info (ryancastle)
This PR was submitted for the 2.4 branch but it was merged into the 2.3 branch instead (closes symfony#3883). Discussion ---------- Removed redundant POST request exclusion info The default ``ExceptionListener::setTargetPath()`` already excludes POSTs/PUTs, so suggesting that people should implement their own listener to do this is a bit misleading. However, doing this to prevent XMLHttpRequest URIs from being saved is still valuable. Commits ------- 01fc656 Added comma after "For example" c633f6b Improved clarity of explanation around overriding setTargetPath() 556365b Removed redundant POST request exclusion info
2 parents c4eb628 + a409349 commit 041105c
Copy full SHA for 041105c

File tree

Expand file treeCollapse file tree

1 file changed

+6
-5
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-5
lines changed

‎cookbook/security/target_path.rst

Copy file name to clipboardExpand all lines: cookbook/security/target_path.rst
+6-5Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ the name of the firewall, defined in ``security.yml``). Upon a successful
1010
login, the user is redirected to this path, as to help them continue from the
1111
last known page they visited.
1212

13-
On some occasions, this is unexpected. For example when the last request
14-
URI was an HTTP POST against a route which is configured to allow only a POST
15-
method, the user is redirected to this route only to get a 404 error.
13+
In some situations, this is not ideal. For example, when the last request
14+
URI was an XMLHttpRequest which returned a non-HTML or partial HTML response,
15+
the user is redirected back to a page which the browser cannot render.
1616

1717
To get around this behavior, you would simply need to extend the ``ExceptionListener``
1818
class and override the default method named ``setTargetPath()``.
@@ -56,9 +56,10 @@ Next, create your own ``ExceptionListener``::
5656
{
5757
protected function setTargetPath(Request $request)
5858
{
59-
// Do not save target path for XHR and non-GET requests
59+
// Do not save target path for XHR requests
6060
// You can add any more logic here you want
61-
if ($request->isXmlHttpRequest() || 'GET' !== $request->getMethod()) {
61+
// Note that non-GET requests are already ignored
62+
if ($request->isXmlHttpRequest()) {
6263
return;
6364
}
6465

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.