Bringing modern authentication to Wagtail: WebAuthn and Passkeys
Transcript
By Storm Heg. From Wagtail Space NL 2024. Published June 27, 2024.
Watch the video Markdown version 2,893 words · auto-generated · en
Summary
Passwords and common second factors can be inconvenient and vulnerable to phishing, password reuse, stolen credentials, and approval fatigue. WebAuthn passkeys offer a passwordless alternative: each site stores a public key, while the user’s device keeps the private key and verifies access with Touch ID, Face ID, or a device password. Because passkeys are unique to a site and tied to its domain, they reduce the risks of credential reuse and phishing, though Wagtail’s multi-site setups may need separate passkeys for each domain. Storm Heg demonstrated a Wagtail package, Wagtail MFA, that adds passkey registration and login, and outlined its setup requirements while noting that the package was still early in development.
Transcript
Automatically transcribed, so expect mistakes in names and technical terms. Filler words are removed.
0:00 Introduction
This we'll have to do. That's my cursor It's down here. All right. Hello folks. Nice to be here. I'm Storm Heck. And I'm an independent contractor from the Netherlands. I work on Wagtail and Django applications. I'm also a member of the Recto Core team since 2021 or so. So for a couple of years. The accessibility team I'm also a member of. And currently I'm also the lead mentor for a Google Summer of Code project. And we're working on bringing extended
1:04 Password Security Challenges
alt text capabilities to Wagtail, but that's not what I'm here for today. Today I want to talk about traditional authentication as we know it, passwords, multi-factor authentication, and I want to Tell you why you shouldn't be content with that. There is a better alternative that you can use. That's what the next part is about. Introducing pass keys. And what makes them a better alternative? And at the end I'll go to show you a quick demo of a package I created to make this easy to integrate into your rectal site. But first, passwords. Raise your hand if you are using a password manager. Can I see some hands?
Yeah, this is what I expected. We are a developer audience. We care about security. Good for you. But not every internet user is as security conscious as you are. And here are a couple of pain points that I know exist for passwords. There comes something and that's why people tend to choose easily guessable passwords. And this all passwords also have the they are a shared secret, they can be stolen. either through like fishing, a user goes to a phishing site and enters their password there and suddenly there is a leak in your application
Or maybe they have acquired malware on their computer that is logging all their keystrokes and logging passwords. And because passwords are often reused across sites, this leads to an attack called credential stuffing where if a credential or a password was previously leaked then an attacker can try hey does this credential match with any other user accounts on other websites so Even if your security is strong, well because of someone else's website leak and your user reusing their password You're still you're can still be hacked.
Password managers they help in this regard, but they are not universally used. I don't think most non-technical people use a password manager or even know what it is. So let's get to my daily annoyance. I'm security conscious, I also use two-factor authentication, and this means I have to enter them. And I have to go to an app on my phone and I have to look up this at this six digit code and I have to transcribe it onto my computer screen as quickly as possible. because in a few seconds it's going to expire and oh I'm too late. I have to re-enter the code. I have to do this daily. I'm really annoyed by it and that's why I'm giving this talk.
4:10 Traditional Second Factors
Why I want to make it better. Let's talk for a minute about the common second factor implementations we see out there. We have the time-based one-time passwords that I think are most common. These are the expiring codes I just told you about. But we also know SMS verification codes is appears also to be common. But has this ever happened to you? You switched phone numbers and now you can't receive the SMS code you need to log in because you have a new phone number. Next, codes delivered by email. I every time I have to log into my GitLab account, I get an email with the codes.
and I have to wait for the email to arrive and then I have to copy the code, go back to the window with GitLab in it, and yeah, it just takes precious time. And yeah, I want to be as productive as possible during my day. Yeah, and also somewhat less common, but it's still out there. It's Tap to approve. It's by far the easiest way to log in, you get like a notification or a pop-up on your phone like, hey, is this you? Do you want to approve this? But perhaps this is also the most insecure because you can accidentally approve these prompts And sometimes it happens that a user or an attacker is
5:42 WebAuthn and Passkeys
attacking an account and a user is spammed with a lot of approval requests and yet they user isn't physically present so they can just tap approve and then somewhere there is an attacker logging into the user's account Can't we do better than this? Isn't there anything else or are we lost? This is where web outn comes in It's a pretty new standard. It's been around for a couple years now, but it's recently gaining traction with large tech businesses like Google. and Apple like they are really ding into this and they are making integrating web
out and into their platforms like iPhones and MacBooks And what Web Out and does, I don't think it is necessarily the a silver bullet to security, but it is A very nice way to make this better a better user experience. So, how does this work? It's based on public key cryptography, so there is no shared secret like a password. A user they register a credential with your websites and this is where pass keys come in. There is like a very it isn't a an
exact definition of pass key, but it's more of like an umbrella term for this standard. But for the purpose of this talk, I'm going to define it as The credential that is registered on the website and that is being used to authenticate. So this is the public key pair that is created. So when a user registers a pass key a public key pair is cre or a public private key pair is created. The private key is stored on the user's device securely and we as the website implementing pass keys. We get the public key and we store that on our site along with a reference to which
which user this is And whenever the user wants to use their passkey to log in, we, the server, the website, we're going to send a challenge. to the browser that is currently trying to, or the user that is currently trying to log in. And we're going to ask them like, hey, sign this challenge with the private key you have. And this signature is sent back to us. And we use the public key we have stored for this user to check that signature. Is this actually a valid signature? If it is, then the user or the person on the other end must be in possession of the private key and it must be
who they say they are there is an additional step to this because devices they aren't going to make the secret key available for signing immediately. They're going to perform like an additional verification like maybe the user left their laptop unlocked and someone walks along and they try to log in. Well That's where why the devices they perform additional verification. But you can use your computer password, or if you have a laptop with a fingerprint scan, you can use a fingerprint scan. If you have an iPhone with face ID you can do facial recognition. And this is not something that we have to worry about.
9:35 Passkey Benefits and Domain Limits
It is This is implemented by Google and by Apple on their hardware, their software. And I think it makes for a really nice integrated experience. So, yeah, the benefits. Like I mentioned, no shared secrets. I think that's a benefit. By design the keyper is created per site, so pass keys are unique. So if the secret key were ever to leak then it can only be used to log in to the website it was created for It's not like with passwords that are reused across websites. So yeah, the blast radius
is less with that. They are bound to a specific domain too, so fishing attacks they are ineffective. You can't use a pass key to authenticate on a domain it wasn't registered for, like the your web browser just won't give you the option to use this pass key. This does have like a slight disadvantage to it because Wagtail is a multi-site and usually users or editors. Can access the admin through like the multiple domains that are connected to your Wactor instance. Well the pa Apaski isn't going to work, it's only going to work on the domain it was registered for.
11:06 Registration and Authentication Flows
If you have another domain like a different domain then you can't use this pass key. So For now, a user would have to register like multiple passkeys, one for each domain they want to log in from, or just access the admin from the same domain always. So let's have a look at how registering a pass key how that works exactly. I just explained it very briefly and it's like magic, but how do how does it work exactly So we begin at the top with this is always initiated by the web browser. The web browser has an API that we
We can call from JavaScript to begin the passkey authentication process. But before we do that, we request from the server a couple of options like maybe we e expect like specific security options and we also have to defetch the challenge we need to sign and we get back the options and the challenge from the server. And At that point, the web browser is going to show a pop-up, usually a system pop-up, like hey what pass
key do you want to use? To log into the site and it can list the pass keys that are already stored on the device. And the user can select one and then it creates the signature and we send that back. The public key or sorry the sorry the yeah the registry sorry I'm talking about registration I was When we register, we're going to send the public key that was created along with the credential ID. This is also created by the web browser and it's just a very large opaque string of bytes
that is unique but every time we're going to use this pass key we get this credential ID so we can use this to look up the public key we have in our database. And yeah, that's it. Then we have registered a pass key on our website. And after the initial registration, what does the authentication process look like exactly Well once again it's initiated by the client by JavaScript calling a browser API And again
we ask the server for some options and the challenge that needs to be signed The browser is going to show a system pop-up again, like hey, which pass key do you want to use And it sends the credential ID and the sign challenge. And on our server we look up like, hey, do we have a pass key stored with this credential ID? Take the public key for that and use that to verify the signature. And if it matches, okay, then log in the user we know is associated with this pass key. Well, this all sounds pretty complicated, right? There's a lot of interactioning interaction happening between the user, the device, browser APIs, your backends, you have to store our data on your backend, you have to do like
15:05 The Wagtail MFA Package
Cryptography, verifying signatures, all complicated. And you're right, it's a pretty complicated standard, but the hard work is already done for you. Introducing Ractil MFA. It's a package I've been working on for the past couple of months. It's not feature complete yet. Some important features are missing because I want to add the traditional multi-factor authentication too like these time-based codes just for the devices that don't have don't have pass keys yet there needs to be a fallback And right now, since yesterday, I'm officially
past the proof of concept stage. It's just adding more a little bit more features now. Documentation tests are completely lacking right now and some more polishing. So let's check it out. Let's Go to the rectil admin, register a pass key and use it to log in back or to use it use it to log in to a rectil admin without using a password at all. Completely passwordless. So let's have a look if I can show my Safari screen
Just appear. Here we go. Oh this is difficult. Let me just mirror my screen quickly. Which option is it?
17:26 Passkey Demo
So here we are in the bakery demo. So let's go to our account and go to more actions, manage authentication settings. And here it is, the custom fuse added by my package. We don't have any pass keys registered yet, so let's get started. And register one. So here we get a pop-up from Safari from macOS like hey do you want to use Touch CD from my MacBook? To log in and a pass key will be saved to my iCloud keychain. Yeah sure let's do that All right, it's created.
Let's give it a name. Call it my MacBook And there it is. Well, let's try it. Let's log out of the admin and look what we have here. Safari knows it has a pass key for this website, so it already prompts us, hey, do we want to use this pass key? Yeah, sure we do. And again, just with a touch of my finger, here I am locked into the wagtail.
19:07 Installation and Django Integration
So what do you have to do to add this Rectil MFA to your rectil project? Well, you have to install it from pip and afterwards you have to add it to your installed app setting. And you have to set a couple of additional settings. One is the RP ID, the relying party ID, and this is the domain that your that a PASCE will be bound to when it is created. So this should be the primary domain of your back to the site. And we also set the RP
name because some authenticators, some browsers, they in the pop-up they show when you want to create a pass key. The you can add your own business name here like hey do you want to create a passkey for my company incorporated And one other important thing to set is the allow allowed origins. I see I made a typo in the setting name, but you didn't notice And this is a list of origins that pass keys can be used from. And it's very similar to the Django
Cross-site request forgery origins setting. It has a security purpose And the only other thing you need to do I think this is the wrong the wrong image in my slide the same image again but there was supposed to be an image here of adding the wagtail mf a urls to your url config And yeah, that's it. That's all you have to do. And this is a default implementation that I think works very well. For most if you don't want to spend a lot of time integrating passkeys. But it's based on another package I wrote which is more for Django
and integrates with the Django OTP framework. for managing fac verification. And yeah Even outside of Ractil, you can integrate pass keys in your Django application using the lower level Django OTP Webout N library. Yeah, thank you. Here it is.