In our previous posts we discussed in detail the generation of JWT tokens, how to secure them, and how to secure your users’ credentials and data on the databases.
But the latest incidents, particularly Twitter’s Breach and Garmin’s ransomware, show that we need to ask how to better protect our SaaS application users to eliminate the risk of sophisticated account takeovers and password breaches.
Two of the most popular ways to improve SaaS application security are SSO and MFA. This guide covers how to implement them and what they mean for your users.
This is part of a series of articles about SaaS architecture
See how easy it is
Learn first hand how easy it is to get your SaaS enterprise ready.
Book a demo nowSSO-based authentication
Most enterprise-grade applications allow signing in using Single Sign On (SSO). Enterprise ready applications will also support SAML as the SSO method.
IT management wants to manage the employees’ identity in a central place. When a user leaves the organization his identity goes with him. IT cannot allow John.doe@acme.com to keep on using his acme.com identity after leaving the organization, right?
Users have a motive too. Users sign up on multiple SaaS applications and websites and need to set their password on each of the applications and sites. In the best case scenario they will use a random password for each sign up. In the worst case and more common scenario they will use the same password for all SaaS applications. In case of a breach in one of them, the attacker will gain access to all of the other applications on which the user is registered.
So IT wants control, and users want to avoid “password hell”. The solution is an SSO approach that is controlled, monitored and provisioned by the IT administrator of the company that uses our SaaS service.
One of the most popular methods for enterprise SSO is the use of SAML
Security Assertion Markup Language (SAML) is an open standard that allows identity providers (IDP) to pass authorization credentials to service providers (SP). If you have a single identity at your identity provider, you should be able to login to all surrounding applications using that single identity.
The SAML flow has two main actors:
- IDP: The IDP is the single source of truth for the user’s identity. It is the only entity which holds data about users, their passwords and their entitlements.
- The SP: The SP is the third party application consumed and used by the user.
Let’s see this flow in action.
For our example we’ll use a SaaS application called DemoSaaS. DemoSaaS is used by acme.com users. In our flow DemoSaaS is the SP and acme.com’s ActiveDirectory is the IDP.
- The user is prompted with a login form (usually input for email only). After inputing his email and pressing the “next” button, a call for validating if the user is registered for SSO is sent to the backend.
- In case the user’s domain is registered for SSO using SAML, the user is redirected to his company’s IDP for login. The redirect uses the browser by sending a SAML request.
- The IDP performs the authentication check and the entitlement check (that this user can actually access the Service Provider’s application) And redirects back to the ACS (Assertion Consumer Service) which is in this case the DemoSaaS.
- The Service Provider validates the assertion response and the signature (validating that the originator is actually the claimed IDP) and lets the user in by providing a JWT token.
See how easy it is
Learn first hand how easy it is to get your SaaS enterprise ready.
Book a demo nowSo we discussed the SAML requests and SAML responses. But what exactly is SAML?
SAML is XML with assertion units. The spec and protocol for SAML2 was written and maintained by OASIS where the full specifications of the protocol can be found.
An example of SAML authentication request will look like this for DemoSaaS (Our service provider):
Upon successful login, the IDP will return the following Authentication Response:
Note these items in the flow above:
- The SP request contains sequence ID which is returned by the IDP in the “InReponseTo” attribute. This avoids a mixup of requests and responses.
- The IDP issues the email of the logged in user by using the “nameId” attribute. Usually, on each IDP there are multiple configurations which allow to set the nameId attribute to other identifiers of the user rather than his email address.
- The IDP issues a “NotBefore” and “NotOnOrAfter” attributes on the response. This is done to eliminate man in the middle attacks and replay attacks in case the connection is intercepted.
- The response is signed using the IDP’s private key. The verification of the response is done by using the IDP public key and is the responsibility of the Service Provider.
See how easy it is
Learn first hand how easy it is to get your SaaS enterprise ready.
Book a demo nowMulti-factor authentication
Multi-factor authentication (MFA) refers to an authentication method where the user is required to present at least 2 valid “evidences” that he is actually the user he claims to be.
Before he does that? He cannot login…
One of the common types of MFA is two-factor authentication (also known as 2FA). 2FA verifies that in addition to “something you know” (for example username and password) you can verify your identity via “something you have” (for example phone for SMS / Authenticator app).
Common factors, sorted by security level:
- Authenticator app: Using TOTP protocol and using one of the authenticator applications (such as Google Authenticator, Duo, Microsoft Authenticator etc.), the user is pushed with a verification code (that is usually refreshed every 30 seconds), inputs the code, then the backend verifies the validity of the code.
- SMS: User is sent a code (that expires after X minutes) to his phone via SMS and needs to input it on a dedicated screen.
- Email: User is sent a code (that expires after X minutes) to his email box and needs to input it on a dedicated screen.
The second factor proves that the user performing the action in the system is the one he claims to be.
The common flows on which we find requirements for 2FA validation:
- Login: The user inputs his email and password. If they are correct, for the next step he will need to input his one time token for second level validation.
- Change password: In case a user tries to change her password, we will send the user an email with OTP in order to validate that the account is not compromised before actually changing the password.
- Delete account: Same as for password change. In case the user tries to delete the account, we would want to validate by sending the user an additional OTP over to his Email / SMS in order for him to validate his identity before actually deleting the account.
Here’s what happens behind the scenes.
Let’s take the login challenge for example (components are simplified to keep the flow readable):
- The user inputs an email and password.
- The application verifies the correctness of the credentials (which are saved securely in the database).
- The application generates the MFA challenge (in case of SMS / Email sends the relevant code) and saves the code on cache (preferably a distributed one like REDIS) with a new uuid as the MFA token with expiration. The MFA token is returned to the user.
- The user performs the challenge (SMS/Email/TOTP) and sends the result using the MFA token. Backend validates the challenge with the token and invalidates the cache.
- A JWT is generated and the user is now authenticated.
The user is now validated through two different factors of authentication, and the login process is secured.
A few considerations for choosing the right 2FA method:
- SMS: SMS is great for easy and quick onboarding. You don’t need the user to install an additional application. We all have phones and it seems like the easy way, right? But try to google the term “sms hijack”…
- Email: Like SMS, emails are great for easy and quick onboarding. We don’t ask our users to install any additional application. The problem with email as a 2FA delivery channel is that the most common first factor, a password, can usually be reset via an email. That means that an attacker only has to compromise one factor, your email inbox, to take over your account.
- Authenticator applications: Authenticator applications use secure TOTP protocols, but at a usability cost. The user must install a dedicated application on their phone, and recovery (using recovery codes or support tickets) causes headaches.
Choose the method that balances your security requirements against your user experience goals.
Summary
Every SaaS application has to protect its users.
This is a non-negotiable requirement, both for compliance and because breaches keep growing in scope and sophistication.
As SaaS owners, we need to enable SAML IDP sign on and add an additional authentication factor for our users.
Put this into practice with Frontegg
Frontegg is customer identity and access management (CIAM) for B2B SaaS. It's free up to 7,500 monthly active users, including 5 SSO/SCIM connections.
Start for free