Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Cannot register yubikey #540

Closed
Closed

Description

@Nimamoh

Steps to reproduce

Deployed nextcloud through docker (using version 16.0.4) and a postgres 10. nginx is setup to serve nextcloud with valid ssl cert on a public domain name.
Installed the two factor u2f app

The yubi key works correctly with github, I tested under firefox 69 and chromium (with no extension)

The install is as fresh as it can be.

Expected behaviour

Clicking on "add u2f device" should let me register my key

Actual behaviour

Spinning and an error is logged

image

Activity

  1. Nimamoh commented on Sep 22, 2019

    @Nimamoh
    Author

    Okay, that was a configuration problem.

    I had a default http://localhost as overwrite.cli.url in the config.php (probably a default value setup by the installer), changing it to the actual domain fixed the issue.

    Maybe a more explicit error message would be nice (I don't really know if that's realistic, just an idea)

  2. theorangepotato commented on Oct 7, 2019

    @theorangepotato
    Contributor

    I have also experienced this problem. While my overwrite.cli.url value was set to an old URL, it is now set properly. I have since restarted my server and reinstalled this app, but neither had an effect. My errors look like this:
    Nextcloud U2F Error

    This occurs for me in both Firefox and Chromium. I have confirmed that my key works with other sites, so I believe it is Nextcloud that is the issue. Does anyone have any ideas?

  3. ChristophWurst commented on Oct 9, 2019

    @ChristophWurst
    Member

    overwrite.cli.url value was set to an old URL, it is now set properly

    Does it fully match the URL you use to access your instance?

  4. ChristophWurst commented on Oct 9, 2019

    @ChristophWurst
    Member

    do you use https?

  5. ChristophWurst commented on Oct 9, 2019

    @ChristophWurst
    Member

    I have also experienced this problem. While my overwrite.cli.url value was set to an old URL, it is now set properly. I have since restarted my server and reinstalled this app, but neither had an effect. My errors look like this:

    Is it the first key you're trying to add?

  6. theorangepotato commented on Oct 9, 2019

    @theorangepotato
    Contributor

    Does it fully match the URL you use to access your instance?

    Yes. The URL matches exactly. Would trailing slashes matter?

    do you use https?

    Yes, I use public facing HTTPS certificates from Let's Encrypt, nothing is self-signed.

    Is it the first key you're trying to add?

    Yes, this is the first U2F key I am trying to add to my account (actually, the first for my server ever).

    Hopefully this helps!

  7. ChristophWurst commented on Oct 22, 2019

    @ChristophWurst
    Member

    Thanks for the info. Unfortunately I'm still clueless.

  8. tarioch commented on Nov 8, 2019

    @tarioch

    I'm also not able to register it, getting the following error in the console

    Error: Registration 
        at l (settings.js?v=8ac46a71-1:34)
        at settings.js?v=8ac46a71-1:34
        at i.responseHandler_ (settings.js?v=8ac46a71-1:61)
        at settings.js?v=8ac46a71-1:61
    

    I'm using the docker image behind a reverse proxy which also does ssl termination. overwrite.cli.url is set to the "final" external url with https.

  9. ChristophWurst commented on Nov 21, 2019

    @ChristophWurst
    Member

    @tarioch fix your webserver config to server .js.map files, then we get the actual stack trace with line number of the source files.

  10. tarioch commented on Nov 21, 2019

    @tarioch

    Will have to look into the docker image, not sure what needs to be configured there for this to work.

  11. tarioch commented on Nov 21, 2019

    @tarioch

    any hint where the js.map files should get served?

  12. tarioch commented on Nov 23, 2019

    @tarioch

    Figured out how to enable the map files, was a simple missing map in the rewrite rules in .htaccess. The error is

    Error: Registration failed
        at l (u2f-api.js:75)
        at u2f-api.js:118
        at i.responseHandler_ (generated-google-u2f-api.js:614)
        at generated-google-u2f-api.js:386
    
  13. 1 remaining item

  14. theorangepotato commented on Dec 22, 2019

    @theorangepotato
    Contributor

    I have done some investigation, and I am not sure if this is relevant or not, but I figured I would mention it. When I dive into the JS running with developer tools, I find that in the error occurs in the register function, wherein the req object that is passed in has three attributes:

    appId: "http://DOMAIN_CENSORED"
    ​​​​challenge: "CENSORED"
    version: "U2F_V2"

    Notice that the appId being passed is being passed as an http:// domain, not an https:// domain, despite the fact that my site is protected by Let's Encrypt. I know that both Firefox and Chrome will refuse to handle U2F keys if the domain is not protected by HTTPS, could this be the problem?

    And, to help with triaging, my Nextcloud instance is running behind a reverse proxy, like many of the other posters here. This may be relevant to why the appId is being passed as an HTTP version? However, my overwrite.cli.url is set to use HTTPS and my reverse proxy is listed under trusted_proxies.

    I am not very familiar with this code base, so I apologize if this is irrelevant information, or if there is an obvious next step in debugging that I have not taken.

  15. markmcb commented on Dec 22, 2019

    @markmcb

    I can confirm the http observation of @theorangepotato ... shouldn't the app be referencing the overwrite.cli.url setting? Or is there some other setting to tell it to use https?

  16. theorangepotato commented on Dec 28, 2019

    @theorangepotato
    Contributor

    Okay, I now believe that this line is the culprit. As you can see, it just prepends the server protocol to the server host name, and this is the value that gets propagated to the req object I identified above. This would result in it using http://, since my server is behind a reverse proxy.

    I have looked through the App Development documentation, but I could not find a comprehensive list of APIs, so I don't know how to get the overwrite.cli.url value from an app. In the server you can get it from the SystemConfig object, but this API appears to be private.

    I am away from my server currently, but I will try to verify that changing the value returned in the first link fixes the issue in my personal set up. If it does, and someone can explain how to access the overwrite.cli.url from an app, I will be happy to submit a PR.

  17. theorangepotato commented on Dec 31, 2019

    @theorangepotato
    Contributor

    I have confirmed that this is my issue. When I replace the offending line with the same string as my overwrite.cli.url, this app works flawlessly. I can add a key, name it, and use it to authenticate. So, for anyone who is still experiencing this issue, you can try this to see if it fixes it (and let us know if it does!).1

    In terms of potential fixes, I think the cleanest solution would be to use the overwrite.cli.url, though I do not know how much of a refactor that is in the core (like I said, I am not very familiar with this code base). Alternatively, it seems that $this->request->getServerHost() did return the correct hostname for me. So, another option is to hard code in 'https://', given that U2F is useless without it. I do not know what that error would look like on an HTTP server, but hopefully some reasonable error UI could be implemented.


    1: The file can be found at $NEXTCLOUD/apps/twofactor_u2f/lib/Service/U2FManager.php.

  18. ChristophWurst commented on Jan 7, 2020

    @ChristophWurst
    Member

    Got it. You didn't set overwriteprotocol, did you? https://docs.nextcloud.com/server/stable/admin_manual/configuration_server/reverse_proxy_configuration.html#overwrite-parameters That prop is taken into account for the U2F appId. Set it to https and registration will work :)

  19. ChristophWurst commented on Jan 7, 2020

    @ChristophWurst
    Member

    nextcloud/server#13116 if your problems started with Nextcloud 16 and you didn't configure your proxy as trusted.

  20. markmcb commented on Jan 19, 2020

    @markmcb

    @ChristophWurst this persists for me. I have x-forwarded-for set, and the trust_proxies config in config.php. Either I've got something set up wrong, or this issue is not closed.

  21. theorangepotato commented on Jan 19, 2020

    @theorangepotato
    Contributor

    Do you also have a line that says 'overwriteprotocol' => 'https', in your config.php? That's what did it for me after I had my trusted_proxies set up properly. This allows Nextcloud to know what protocol to use (either http or https) given that it's behind a reverse proxy and does not have access to that information.

  22. markmcb commented on Jan 19, 2020

    @markmcb

    @theorangepotato yes, I've got that in my config.php. I'm at a loss for what my issue could be.

  23. theorangepotato commented on Jan 19, 2020

    @theorangepotato
    Contributor

    @markmcb With the new PR, it should warn you in the console if you try to use U2F and it sees http as your protocol. Does this show up for you? Have you confirmed if you go through the Developer Tools that the req object is still using http? Have you tried my initial workaround, and does it work for you?

    Because, if you can force it to use https and you still get this error, then you are probably experiencing a different bug altogether.

  24. markmcb commented on Jan 19, 2020

    @markmcb

    In the console I see this:

    Error: "U2F not supported"
        d u2f-api.js:88
        register u2f-api.js:113
    

    The source of the first is definitely https related:

    exports.isSupported = isSupported;
    function _ensureSupport(backend) {
        if (!backend.u2f) {
            if (location.protocol === 'http:')
                throw new Error("U2F isn't supported over http, only https");
            throw new Error("U2F not supported");
        }
    }
    

    Overriding the line in U2FManager.php doesn't seem to help either:

    private function getU2f(): U2F {
            // $url = $this->request->getServerProtocol() . '://' . $this->request->getServerHost();
            $url = 'https://' . $this->request->getServerHost();
            return new U2F($url);
    }
    

    And for completeness, relevant lines from config.php and my nginx config:

    'overwrite.cli.url' => 'https://[my domain]',
    'overwriteprotocol' => 'https',
    'trusted_proxies' =>
      array (
        0 => '127.0.0.1',
      ),
    
    proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header    X-Forwarded-Proto $scheme;
    proxy_pass          http://127.0.0.1:81;
    
  25. ChristophWurst commented on Jan 20, 2020

    @ChristophWurst
    Member

    Please file a new ticket with this info.

  26. gspe commented on Jan 28, 2020

    @gspe

    Do you also have a line that says 'overwriteprotocol' => 'https', in your config.php? That's what did it for me after I had my trusted_proxies set up properly. This allows Nextcloud to know what protocol to use (either http or https) given that it's behind a reverse proxy and does not have access to that information.

    This is the solution for me too. Thanks

  27. daisukixci commented on Feb 8, 2020

    @daisukixci

    same as gspe, this worked for me as well. Thanks for your help/work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions