Skip to content

Cannot use restorePreviousSession with CSS on localhost #1276

Closed

Description

@Otto-AA

Environment

  • Server version: 3.0.0 & 4.0.0 (others not tested)
  • Node.js version: v16.14.2
  • npm version: 8.5.0

Description

solid-client has an option to restore the previous session, if the user was logged in (see the docs). When using this with a localhost CSS this crashes.

Steps to reproduce

  • run npx community-solid-server
  • go to podbrowser
  • login with http://localhost:3000
  • create a new account in a new tab, finish podbrowser login and consent
  • blank podbrowser page (expected I guess, because the card does not return a storage location)
  • press F5 to reload the page

This redirects to the page: http://localhost:3000/.oidc/auth?client_id=https%3A%2F%2Fpodbrowser.inrupt.com%2Fapi%2Fapp&redirect_uri=https%3A%2F%2Fpodbrowser.inrupt.com%2F%3Fiss%3Dhttp%253A%252F%252Flocalhost%253A3000%252F&response_type=code&scope=openid%20offline_access%20webid&state=6b1b006866e44d5a9346c730df24deae&code_challenge=N3foZBLzeTXvkUUGbM1HFdA0hTupM9f3-iCCmgvf-X0&code_challenge_method=S256&prompt=none&response_mode=query

Which shows the error:

InvalidRedirectUri: invalid_redirect_uri - redirect_uri did not match any of the client's registered redirect_uris
    at checkRedirectUri (/home/oaie/coding/solid/solid-filemanager/node_modules/oidc-provider/lib/actions/authorization/check_redirect_uri.js:10:11)
    at dispatch (/home/oaie/coding/solid/solid-filemanager/node_modules/koa-compose/index.js:42:32)
    at checkOpenIdScope (/home/oaie/coding/solid/solid-filemanager/node_modules/oidc-provider/lib/actions/authorization/check_openid_scope.js:28:12)
    at dispatch (/home/oaie/coding/solid/solid-filemanager/node_modules/koa-compose/index.js:42:32)
    at checkScope (/home/oaie/coding/solid/solid-filemanager/node_modules/oidc-provider/lib/actions/authorization/check_scope.js:54:10)
    at dispatch (/home/oaie/coding/solid/solid-filemanager/node_modules/koa-compose/index.js:42:32)
    at checkResource (/home/oaie/coding/solid/solid-filemanager/node_modules/oidc-provider/lib/shared/check_resource.js:77:10)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async parseBodyIfPost (/home/oaie/coding/solid/solid-filemanager/node_modules/oidc-provider/lib/shared/conditional_body.js:7:5)

I think one can reproduce it with any application using client-js and the automatic session restore. I also tried it with solid-filemanager, but I didn't make a minimal reproducible example with only client-js running.

Use case

In my case, I wanted to write an e2e test for solid-filemanager where I initially used a reload in the page. I was able to do a workaround which doesn't require so it's not an immediate problem.

Still, I think it would be helpful to debug applications. The current fix is to externally delete the local storage before reopening the page, which is tiring.

Open questions

I don't know if this is a problem of CSS. It could also be due to running on localhost (but I would expect a different error then), or an error in solid-client.

Activity

  1. jvherweg commented on Apr 25, 2022

    @jvherweg
    Member

    Just tried this myself with both the memory and file-based backends and I can't reproduce the problem.

    Just to be sure, I did the following steps:

    Might be a caching issue?

  2. Otto-AA commented on Apr 25, 2022

    @Otto-AA
    Author

    Yes, exactly those steps. In the login process I kept the default settings (Stay logged in and Remember this client are checked). And when the podbrowser loaded again, then refresh, which tries and fails at the session restore.

    I'm using Firefox 99.0.1 in private browsing mode, but it also fails for me with cypress e2e tests which seems to use chromium. For both cases, caching should not be an issue. Also I've tested it with a freshly started npx community-solid-server (so the in-memory version v4.0.0)

    I'll try to setup a basic cypress test some hours later and upload it to github, so reproducing should not be a problem then.

  3. jvherweg commented on Apr 25, 2022

    @jvherweg
    Member

    Just found the problem by looking at your original redirect URL again.

    There are 2 important parameters in the redirect URL you posted above:
    client_id=https%3A%2F%2Fpodbrowser.inrupt.com%2Fapi%2Fapp & redirect_uri=https%3A%2F%2Fpodbrowser.inrupt.com%2F%3Fiss%3Dhttp%253A%252F%252Flocalhost%253A3000%252F. The first tells the IDP the ID of the client doing the request, the second tells the IDP where to redirect to after the request was successful. Since the ID is an URL here, the server dereferences it to discover client metadata (this is part of the Solid OIDC spec). Looking at https://podbrowser.inrupt.com/api/app, it states that it has 2 valid redirect URIs: https://podbrowser.inrupt.com/ and https://podbrowser.inrupt.com/login. But the request says that it wants to redirect to https://podbrowser.inrupt.com/?iss=http%3A%2F%2Flocalhost%3A3000%2F. This is not one of the defined redirect_uris so the server is going to reject the request. This is a safety measure built in OIDC to prevent malicious actors from identifying as someone else. The problem lies with podbrowser sending an invalid redirect URI.

  4. Otto-AA commented on Apr 25, 2022

    @Otto-AA
    Author

    Thanks for the explanation!

    Just to be sure I understood it correctly: The problem is, that the client id document says https://podbrowser.inrupt.com/ is valid, but actually it redirects to https://podbrowser.inrupt.com/?iss=http%3A%2F%2Flocalhost%3A3000%2F which contains the additional query parameter.

    If that's the case, even an example from solid-client-authn-browser (link) has this issue. Because when I tested it, it tries to redirect to a page with the ?iss=... at the end (which is not in the client_id document) and I received the same InvalidRedirectUrl error. And I think this is due to the library itself, not the usage of it. So I would open an issue there to ask if this is intended or a bug (or some error on my side)

  5. jvherweg commented on Apr 25, 2022

    @jvherweg
    Member

    That is the issue yes. I have not used that example yet, but the demoClientApp example in the authn client should definitely work though.

    Specifically from the OpenID spec https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest :

    Redirection URI to which the response will be sent. This URI MUST exactly match one of the Redirection URI values for the Client pre-registered at the OpenID Provider, with the matching performed as described in Section 6.2.1 of [RFC3986] (Simple String Comparison).

  6. Otto-AA commented on Apr 25, 2022

    @Otto-AA
    Author

    I've opened an issue at solid-client-authn-js (inrupt/solid-client-authn-js#2103).

    I'm confused, that demoClientApp works for you, as it doesn't seem to allow a session restore with CSS on my side. However, I think it makes more sense to discuss it their, so I'll close this issue here. Thanks for the help!

  7. changed the title [-]Cannot use restoreSession with CSS on localhost[/-] [+]Cannot use restorePreviousSession with CSS on localhost[/+] on May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions