Skip to content

[Security] use current request attributes to generate redirect url? #7325

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

Closed
wants to merge 4 commits into from

Conversation

jfsimon
Copy link
Contributor

@jfsimon jfsimon commented Mar 11, 2013

Maybe we should consider to use current request attributes to generate the login/logout redirections URL?

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #5080

@Seldaek
Copy link
Member

Seldaek commented Mar 11, 2013

Can you explain why?

@jfsimon
Copy link
Contributor Author

jfsimon commented Mar 11, 2013

@Seldaek let say I prefixed all my URLs with a {domain} var (_locale for instance), I'd like it to be passed to my redirected request. I guess it could lead to side effects, that's why I tagged this PR RFC.

@Seldaek
Copy link
Member

Seldaek commented Mar 11, 2013

Fair enough. The main issue I see is that you end up with "garbage" query params in the URL. Any params that was needed by the previous page and not needed by the new one ends up as ?foo=bar in the URL. It's usually not harmful, but not very clean either. I'm not sure what it would take to grab all the params that a route can use, and only copy those over.

@jfsimon
Copy link
Contributor Author

jfsimon commented Mar 11, 2013

@Seldaek indeed, I didn't think about those query parameters... I'll try to fix this in a simple way this afternoon.

@jfsimon
Copy link
Contributor Author

jfsimon commented Mar 11, 2013

@Seldaek tell me if what you think of this, it may look like a hack (which wont be acceptable).

@Seldaek
Copy link
Member

Seldaek commented Mar 11, 2013

Eh I see. I can't say it's the less hacky thing I ever saw, but it might be alright. I don't think I'm the best person to take this call though.. Let's see what @fabpot thinks.


// unnecessary query string parameters must be removed from url
// (ie. query parameters that are presents in $attributes)
return $this->cleanQueryString($url, array_keys($attributes));
Copy link
Member

Choose a reason for hiding this comment

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

You can just remove the query string altogether as it will always only contain attributes.

Copy link
Member

Choose a reason for hiding this comment

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

Just for info, I have seen people generate routes with patterns like:
/foo?bar={bar} just because of some legacy reasons. So removing the
query string in all cases might create issues.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Seldaek: Using such a path pattern, the ? gets encoded anyway. So it wouldn't generate a query string.

Copy link
Member

Choose a reason for hiding this comment

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

Well it was working in 2.0, but maybe they had to fix this since then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fabpot done

// unnecessary query string parameters must be removed from url
// (ie. query parameters that are presents in $attributes)
// fortunately, they all are, so we have to remove entire query string
return $this->removeQueryString($url);
Copy link
Member

Choose a reason for hiding this comment

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

Can you inline the method instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

fabpot added a commit that referenced this pull request Mar 13, 2013
This PR was squashed before being merged into the 2.1 branch (closes #7325).

Commits
-------

6575df6 [Security] use current request attributes to generate redirect url?

Discussion
----------

[Security] use current request attributes to generate redirect url?

Maybe we should consider to use current request attributes to generate the login/logout redirections URL?

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #5080

---------------------------------------------------------------------------

by Seldaek at 2013-03-11T08:33:37Z

Can you explain why?

---------------------------------------------------------------------------

by jfsimon at 2013-03-11T09:30:07Z

@Seldaek let say I prefixed all my URLs with a `{domain}` var (`_locale` for instance), I'd like it to be passed to my redirected request. I guess it could lead to side effects, that's why I tagged this PR `RFC`.

---------------------------------------------------------------------------

by Seldaek at 2013-03-11T09:46:33Z

Fair enough. The main issue I see is that you end up with "garbage" query params in the URL. Any params that was needed by the previous page and not needed by the new one ends up as ?foo=bar in the URL. It's usually not harmful, but not very clean either. I'm not sure what it would take to grab all the params that a route can use, and only copy those over.

---------------------------------------------------------------------------

by jfsimon at 2013-03-11T10:12:49Z

@Seldaek indeed, I didn't think about those query parameters... I'll try to fix this in a simple way this afternoon.

---------------------------------------------------------------------------

by jfsimon at 2013-03-11T14:54:31Z

@Seldaek tell me if what you think of this, it may look like a hack (which wont be acceptable).

---------------------------------------------------------------------------

by Seldaek at 2013-03-11T14:59:39Z

Eh I see. I can't say it's the less hacky thing I ever saw, but it might be alright. I don't think I'm the best person to take this call though.. Let's see what @fabpot thinks.
@fabpot fabpot closed this Mar 13, 2013
$url = $this->urlGenerator->generate($route, $attributes, $absolute);

// unnecessary query string parameters must be removed from url
// (ie. query parameters that are presents in $attributes)
Copy link
Contributor

Choose a reason for hiding this comment

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

bad English

fabpot added a commit that referenced this pull request Mar 16, 2013
This PR was merged into the 2.1 branch.

Commits
-------

bd38483 [Security] fixed HttpUtils class tests

Discussion
----------

[Security] fixed HttpUtils class tests

This fixes tests broken in #7325.

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #7325
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.

4 participants