authelia: rd query parameter is not url-encoded
First off: Thanks for this awesome project, it works nicely in my traefik setup.
I have an issue when redirecting from more complicated url’s then my subdomains. (Redirecting on specific resources instead of the whole page.)
When the redirection url contains a query string, it terminates the rd
variable, because it is not escaped, which then results in a redirect to the original site without it’s query variables.
E.g. in my setup I have something like https://redacted.org/auth/authorize?response_type=code&...
, which gets redirected to authelia, which results in https://login.redacted.org/#/?rd=https://redacted.org/auth/authorize?response_type=code&...
.
After authentication I am redirected to https://redacted.org/auth/authorize
missing any previous query arguments.
I suppose the redirection url should be escaped to be url-safe once extracted from traefiks headers and decoded again for the actual redirect.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 23 (14 by maintainers)
Commits related to this issue
- Normalise all Traefik configuration via labels and commands When the the middleware issue with Traefik 2.x (#476) is resolved this means all Traefik related configuration can be self-contained within ... — committed to authelia/authelia by nightah 4 years ago
- Encode URL set to rd parameter. URL encoding that parameter solves PR #476. Some URL parameters set during redirection were magically disappearing after the redirection due to the authentication pro... — committed to authelia/authelia by clems4ever 4 years ago
- Encode URL set to rd parameter. URL encoding that parameter solves PR #476. Some URL parameters set during redirection were magically disappearing after the redirection due to the authentication pro... — committed to authelia/authelia by clems4ever 4 years ago
- Encode URL set to rd parameter. (#559) * Encode URL set to rd parameter. URL encoding that parameter solves PR #476. Some URL parameters set during redirection were magically disappearing afte... — committed to authelia/authelia by clems4ever 4 years ago
- Add Traefik2 suite and refactor Traefik suite (#562) * Update Traefik 1.x to v1.7.20 for integration tests * Add suite for Traefik 2.x * Refactor Traefik2 suite to utilise Docker labels * Mo... — committed to authelia/authelia by nightah 4 years ago
Sure; here is the relevant snippet:
@tlvenn , I will provide the fix of URL encoding this week. @nightah , I think it should solve most issues and then, when it’s implemented, we can see if there is still an issue with Traefik 2.0.
Well it really was a simple misconfiguration issue it appears, the issue I was having was due to single quotes vs double quotes and how that’s interpreted by Docker.
Thanks @726a67!
@tlvenn/@clems4ever looks like the issue is limited to Traefik2 when utilising the docker provider and specifically when defining the authelia middleware with labels.
@clems4ever initial implementation for Traefik 2.x was with a file based provider because I was unsure if there would be any conflict with Traefik 1.x labels, commit can be viewed at https://github.com/authelia/authelia/commit/55612957aba6a71244eb0e1a8a3842137d317b35. This resulted in https://buildkite.com/authelia/authelia/builds/126#c1a31cd6-556e-46c7-905a-3ca9af38b1ba.
After this I refactored from a file based provider to utilise the docker provider along with the respective Traefik 2.x labels commit can be viewed at https://github.com/authelia/authelia/commit/86fdf4dc4949856dbb5adcff8a43a15a21e753e0. This resulted in https://buildkite.com/authelia/authelia/builds/127#5aca33da-2f56-4111-81af-873b185e3969.
Looking at the Traefik logs, it appears the Referer and RequestURI is being stripped when utilising the docker provider.
With further investigation, it looks like it’s actually ONLY the middleware definition via the docker provider that causes this specific symptom.
So if we move the middleware definition to be a file based provider and reference that from the container with a label like such: https://github.com/authelia/authelia/commit/34454af65e4fd7301604b916a200c9cee8d60b21 we have Authelia working with Traefik 2.x and are able to utilise all of the fancy service discovery, etc associated with that provider, you can see the test results at https://buildkite.com/authelia/authelia/builds/128#0e1dee49-56d5-44bb-bdfc-42443ac13654.
Clearly there’s something odd going on with Traefik because the behaviour differs depending on how the routes are defined (read: providers). I’d be curious to see if URL encoding actually resolves this issue with the middlewares, but I’ll leave that to you @clems4ever, please utilise the branch as you see fit.
For anybody that wants to utilise Traefik 2.x right now, the configuration discussed and detailed above work.
I am facing the same issue and as pointed in #500, it’s not even just with a complicated redirect url / querystring, a simple domain with Traefik 2.0 will not work as
https://
will be replaced withhttps:/