uOTP : simple TOTP extension for firefox - eviltoast

cross-posted from: https://lemmy.ml/post/12744832

As I updated the version to 1.4.0 , adding the ‘import’ feature I am sharing this here.

I made this extension because I couldn’t find one that wouldn’t ask for too much permissions (such as accessing all websites data).

Eventually I found it nice to have a TOTP that can really be audited, the code is 649 lines of JS, 214 CSS and 52 HTML. Feel free to fork, copy part of it, contribute or just request fix/features.

I have used it for more than a year every day and it works nicely.

  • mox@lemmy.sdf.org
    link
    fedilink
    arrow-up
    40
    arrow-down
    3
    ·
    edit-2
    8 months ago

    I struggle to think of a situation where I would willingly undermine TOTP security by storing the secrets in my web browser.

    Before using this for anything you can’t afford to lose, I suggest thinking twice. And then twice again.


    Edit to elaborate:

    Web browsers are probably the single most targeted component in a desktop computer, have an enormous attack surface, and suffer from an unending stream of vulnerabilities and exploits discovered practically every month. Storing your 2FA secrets there is akin to putting a second lock on your door and hiding the key under the doormat.

    And no, encrypting the secrets in the browser for storage-at-rest does not solve this problem, because it also delegates decryption to the browser. That means an exploited browser can access all of your secrets as soon as you request a TOTP from any of them. Closing it won’t help, because an exploited browser can trivially save or give away a copy of the password you entered, or the decryption key that was generated from it, or the secrets themselves, so your secrets are then compromised forever.

    2FA generators are generally built as stand-alone programs for good reason. Even the ones that offer a browser extension don’t let it access the secret storage.

    Really, think twice before depending on this design for anything important.

    • CameronDev@programming.dev
      link
      fedilink
      arrow-up
      9
      arrow-down
      3
      ·
      8 months ago

      It’s also an extension with 1 review, by a no-name developer, with only 12 installs… definitely would trust that…

      • AYO_Official@lemmy.mlOP
        link
        fedilink
        arrow-up
        15
        arrow-down
        2
        ·
        8 months ago

        Well this is 600 lines of code, if you cannot audit that you can indeed ignore it for now. Once again this is the only auditable code out there and not asking for unrelated permissions.

        • Miss Brainfarts@lemmy.blahaj.zone
          link
          fedilink
          arrow-up
          8
          arrow-down
          2
          ·
          8 months ago

          It might be safe, it might work well and all, but it does defeat the point of 2FA, so I wouldn’t want people to even know about it before they explored undeniably better and safer options, like Authenticator apps for their phones.

          But to be fair, many people around the world only have one single device, so 2FA becomes a difficulty. But that’s the point where I’m not knowledgable enough anymore to see what the best way of going about it is.

          From my gut feeling, I’d rather put a dedicated TOTP App on a device than to use a browser extension.

          • AYO_Official@lemmy.mlOP
            link
            fedilink
            arrow-up
            8
            arrow-down
            2
            ·
            edit-2
            8 months ago

            Thank you for your constructive comment.

            Indeed many people thinks 2FA as 2 devices. I am not sure where that came from and what specifically make people think that way. Despite all my research and experience using 2 devices solve no specific security problem. I think there is a whole topic to be argued on this (should I make a blog post on this?).

            As for me I have Aegis on my smartphone (really perfect nothing to say). But I have many unwanted/unnecessary 2FA to go through every day (for the last 3 years). I am cleaning my cookie/connection every time I close my web browser and I am not keeping my computer on all the time. Therefore those 2FA needs to be done a lot (I mean at least 3 time a day). I do not interact much with my smartphone, also this is the least secure device I own so web browser extension is an OK way. I used to have a python script I could have run from one of my IoT through ssh. So far I don’t see any vector of attack this would prevent compared to browser extension.

            I see hundreds of thousands of users using other extensions that I wouldn’t run on my system and I am sharing a better solution, nothing perfect, nothing that requires mass adoption.

            • Miss Brainfarts@lemmy.blahaj.zone
              link
              fedilink
              arrow-up
              6
              arrow-down
              1
              ·
              8 months ago

              2FA being on a separate device is simply the most secure way of doing it. An attacker who gets access to some passwords for my accounts can’t do a whole lot without also physically stealing my phone.

              It’s simply an extra hurdle for malicious actors to go through.

              Though I guess in most cases, having any 2FA at all will probably already turn off a majority of attackers.

            • Pantherina@feddit.de
              link
              fedilink
              arrow-up
              2
              ·
              8 months ago

              Thanks a lot! I selectively keep cookies for login sites, which is not a good solution.

              The threat is websites escaping the browser sandbox and reading stuff. I dont know if this is really that realistic though.

              • AYO_Official@lemmy.mlOP
                link
                fedilink
                arrow-up
                2
                ·
                8 months ago

                Websites have no way to creep into your browser, extensions included. Usually it is the other way around. Such a leak would be catastrophic for the browser (thinks of all the password manager). At least here it is not even a password manager but only the TOTP so you still have your password as security (still this will never happen realistically).

        • CameronDev@programming.dev
          link
          fedilink
          arrow-up
          4
          ·
          8 months ago

          With all due respect, it doesnt matter what the code is right now. This is an extension that you can update at any point in the future to replace with something malicious.

          Trust is near impossible to build in todays internet.

          https://www.kaspersky.com.au/blog/dangerous-chrome-extensions-87-million/32170/

          Note that a plugin’s malicious functionality can evolve over time in line with its owners’ goals. And the owners themselves may change: there have been cases when malicious features appeared in a previously safe extension after its creators sold the plugin to someone else.

          • AYO_Official@lemmy.mlOP
            link
            fedilink
            arrow-up
            4
            ·
            8 months ago

            This is were the manifest/permission is important. I cannot emphasize enough that I had to code this myself because, at the time, nothing else would be OK with me. This was because of 1- way too big of a code base, 2- way too many permissions.

            It is indeed a problem that extensions are not as well maintained as Linux distribution packages but in this specific instance the extension has no right to read any information nor send requests to any server.

            • CameronDev@programming.dev
              link
              fedilink
              arrow-up
              4
              arrow-down
              1
              ·
              8 months ago

              I appreciate you have put effort into this, and you have gone out of your way to make it safer, but if the extension were to become malicious at a later date, expanding permissions (and relying on users brainlessly-clicking accept) or using an exploit or sidechannel would undo any of that.

              The downside of browser extensions is that they are operating within a massive codebase, and thus have a huge attack surface if they decide to become malicious.

              For what its worth, I commend your efforts here, its just near impossible to trust any peice of software not backed by the reputation of an established company/developer.

      • lemmyreader@lemmy.ml
        link
        fedilink
        English
        arrow-up
        6
        arrow-down
        1
        ·
        8 months ago

        Every software started with 0 reviews, by a no-name developer, with only 1 installs.

        • CameronDev@programming.dev
          link
          fedilink
          arrow-up
          12
          arrow-down
          1
          ·
          8 months ago

          This is a privacy community. Half the posters here think their toaster is listening to their thoughts. Browser extensions are a serious and known vector for malware, installing one from a no-name developer and handing it your tfa codes is a high level of blind trust.

          • lemmyreader@lemmy.ml
            link
            fedilink
            English
            arrow-up
            2
            ·
            8 months ago

            So, are you saying you would use an add-on for OTP by a well known developer (Think about the well-known developers of No-Script and Ghostery and their history) ?

            I see no issue with the add-on of the OP being advertised because some people simply do not use phones at all, so TOTP app is not an option for them. And attack vectors via the browser only apply when the user visits shady web links.

            • CameronDev@programming.dev
              link
              fedilink
              arrow-up
              1
              ·
              8 months ago

              Essentially, yeah? Unless you calculate the OTPs by pen and paper, you have to use some kind of software, and therefore you have to trust that it is safe. Writing your own like OP is actually a very safe option, because you can trust yourself, but everyone else needs to trust OP.

              Attack vectors apply to the add-on itself, it is (potentially) the shady site. OP has the potential to update the add-on later with its own malicious code. This is true of all addons, hence the trust issue.

              I dont have any problem with OP advertising their addon, but potential users should be aware of the risks.

    • fl42v@lemmy.ml
      link
      fedilink
      arrow-up
      6
      arrow-down
      1
      ·
      8 months ago

      Does it, tho? It’s like “smth you know + smth you have” (although knowing or being able to remember most paswords is also quite often a bad idea, but I digress); so you have a device and know [the password for the password manager which knows] the password.

      Besides, given that logic, to not defeat the purpose of 2fa you’ll have to have another smartphone just to run aegis or something

      • AYO_Official@lemmy.mlOP
        link
        fedilink
        arrow-up
        1
        ·
        edit-2
        8 months ago

        There is an irony in password managers that stores your password but need a password (passphrase would be better). A password for your passwords. Fundamentally this is because the only secured space, only you can get in and no one else, is your own brain.

        Most password leaks are usually caused by bad implementations on the server side. I have an authentication protocol to avoid many password leakages I’d like to share one day (double salt, one from client, one on server so password is never shared to the server).

    • Pantherina@feddit.de
      link
      fedilink
      arrow-up
      3
      arrow-down
      1
      ·
      8 months ago

      No it doesnt, it is a password and a secret stored on that device. A password might get stolen on the database, or entered on a fishing website, but with 2FA that would be useless.

      It goes against ONE idea of 2FA, that phones are more secure (thanks Android) and your Browser might get hacked.

      • Katlah@lemmy.dbzer0.com
        link
        fedilink
        English
        arrow-up
        3
        ·
        8 months ago

        If your computer gets compromised and you store your passwords on it (as most do) then you are also storing your 2fa on it, then there is no 2fa.

        • AYO_Official@lemmy.mlOP
          link
          fedilink
          arrow-up
          1
          ·
          8 months ago

          If your computer is compromised whatever token/cookie you will get from the authentication will be also compromised.

          Assuming the computer is compromised also open a lot more issues, privilege escalation can be done in a lot of ways depending of what is being installed (even sudo was hit by such issues https://www.cve.org/CVERecord?id=CVE-2021-3156 )

          • Katlah@lemmy.dbzer0.com
            link
            fedilink
            English
            arrow-up
            1
            ·
            8 months ago

            whatever token/cookie you will get from the authentication will be also compromised

            This assumes you are already logged in. If you aren’t logged in then 2FA will protect you, unless of course you store your 2FA in your browser like an idiot.

            a lot more issues

            Okay but that isn’t relevant at all.

            • AYO_Official@lemmy.mlOP
              link
              fedilink
              arrow-up
              1
              ·
              edit-2
              8 months ago

              Sorry I had in mind you login in from a computer that was compromised (without your knowledge), I didn’t had in mind a computer compromised without being in use.

              EDIT : store your 2FA in the browser from the extension would not be ‘like an idiot’ as it is encrypted.

              EDIT 2 : no forget everything, this whole situation is absurd. If your computer is compromised your password are not (do you store in clear text?!). If you use it to login you are owned already.

      • Lojcs@lemm.ee
        link
        fedilink
        arrow-up
        1
        ·
        8 months ago

        Even if it’s not more secure it’s extra effort nevertheless. But as you said even without that it still removes an entire vector of attack

  • Pantherina@feddit.de
    link
    fedilink
    arrow-up
    3
    ·
    8 months ago

    Really cool! How is the database stored, can it be encrypted using the masterpassword, or a different one? Can it be only loaded into RAM?

    On traditional desktops like any app can read your browser data, which would be very problematic.

    • AYO_Official@lemmy.mlOP
      link
      fedilink
      arrow-up
      8
      ·
      edit-2
      8 months ago

      Database is encrypted in the local storage of the extension. So far Firefox is secure enough so this is not accessible from outside (it is encrypted anyway). The encryption is using the crypto web API (native from web browser) to use PBKDF2 key. It is decrypted with your password so the database is in RAM (not saved anywhere unencrypted) as long as the browser is open or you click to “logout”.

      You can export/import all the entries with a simple JSON format (for now, simple “name”+“secret” for each entry). You should encrypt this export file or save it in a encrypted volume yourself.