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

Relative path in ui_url or default_browser_return_url cause runtime crash #1446

Closed
zhming0 opened this issue Jun 18, 2021 · 7 comments
Closed
Labels
bug Something is not working.

Comments

@zhming0
Copy link
Contributor

zhming0 commented Jun 18, 2021

Describe the bug

When selfservice.default_browser_return_url or selfservice.flows.XXX.ui_url is set to be relative path (e.g. /foo/bar), Kratos will crash whenever it access those setting.

Reproducing the bug

Steps to reproduce the behavior:

  1. Setup the demo kratos server using demo config.
  2. Change selfservice.flows.login.ui_url to /login
  3. Try to access login page
  4. See Kratos crashes with following log

Screen Shot 2021-06-18 at 5 39 39 pm

Server configuration

Just like the demo config:

serve:
  public:
    base_url: http://127.0.0.1:3001/kratos/
  admin:
    base_url: http://kratos:4434/

selfservice:
  default_browser_return_url: http://127.0.0.1:3001/
  whitelisted_return_urls:
    - /

  methods:
    password:
      enabled: true

  flows:
    login:
      ui_url: /login

Expected behavior

It works just like v0.5 or it throws a proper error instead of crashing

Environment

  • Version: v0.6.3
  • Environment: Docker

Additional context

  • It appears this new behavior was introduced in v0.6.
  • The same problem applies to the default_browser_return_url setting
@zepatrik
Copy link
Member

zepatrik commented Jun 18, 2021

I am not sure that ever worked, are you sure that it worked in v0.5 to have a relative URL for selfservice.flows.login.ui_url? The history shows it always used the same parse function: https://github.com/ory/kratos/blame/2e6f87ba7f3d9b4df8851e204554464ecc199c15/driver/config/config.go#L565
Same goes for default_browser_return_url: https://github.com/ory/x/blame/e598287a046d0178b4648b6175ed732ea065e20f/configx/provider.go#L461
However, at least the error should be handled correctly.

@aeneasr
Copy link
Member

aeneasr commented Jun 18, 2021

We should probably change this in the schema config and only allow URL-URIs to be defined

@aeneasr aeneasr added the bug Something is not working. label Jun 18, 2021
@zhming0
Copy link
Contributor Author

zhming0 commented Jun 18, 2021

@zepatrik I am sure it worked in v0.5. I have been running it on prod using such configuration. I thought the serve.public.base_url was designed to support this feature?

For default_browser_return_url, the doc mentions this (/dashboard) as an example.

@zhming0
Copy link
Contributor Author

zhming0 commented Jun 20, 2021

@aeneasr @zepatrik I did some quick digging I believe this is where the absolute paths were rejected.

And this is the original PR that introduces such check.

I do believe it's a bug, I can raise a PR to remove the scheme validation if you guys agree.

@aeneasr
Copy link
Member

aeneasr commented Jun 21, 2021

I believe I added this to ensure that the login, registration, ... redirects are deterministic and not implicitly set via the e.g. public base URL. This ensures that all redirects end up at the page we configured, and are not dependent on implicit configuration.

I think the fix here would be to disallow setting relative URLs in the config schema so that we do not get a runtime error but instead a config validation error.

Is there a particular reason why you want to have relative URLs here? Given that it would be computed as such

<serve.public.base_url><selfservice.flows.login.ui>

I see no functional difference to making this explicit.

@aeneasr aeneasr added this to the v0.8.0-alpha.1 milestone Jun 21, 2021
@zhming0
Copy link
Contributor Author

zhming0 commented Jun 22, 2021

Is there a particular reason why you want to have relative URLs here?

The same reason why HTML would allow anchor to support /foo
It reduces possibility of making mistake, promotes separation of concern: allow single source of truth for the base URL. Easier to use for most use cases.

But you are right, for machine, there is no functional difference. It's a just matter of human taste and use case. I thought it was a bug only because the doc mention it was supported and it was supported in the past 😄 .

I agree the bottom line is to ensure no runtime error + fix the doc.

@chlasch
Copy link
Contributor

chlasch commented Sep 15, 2021

I believe I added this to ensure that the login, registration, ... redirects are deterministic and not implicitly set via the e.g. public base URL. This ensures that all redirects end up at the page we configured, and are not dependent on implicit configuration.

I think the fix here would be to disallow setting relative URLs in the config schema so that we do not get a runtime error but instead a config validation error.

Is there a particular reason why you want to have relative URLs here? Given that it would be computed as such

<serve.public.base_url><selfservice.flows.login.ui>

I see no functional difference to making this explicit.

Relative URLs worked in v0.5. This was an important feature for us, for an on-premise application that does not know a reliable hostname when it is deployed, it can be behind a load-balancer for instance with a different DNS name that originally configured, or might be just be IP.

Is there a security concern with relative URLs that I'm missing?

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

No branches or pull requests

4 participants