Web Authentication Methods Explained - RisingStack Engineering (2024)

We are keen on security – recently we have published theNode.js Security Checklist. As a sequel, let’s dive deep into the world of cookies, tokens and other web authentication methods. If you’d like to learn more about the basic authentication strategies with Passport.js, check out ourbeginner guide here.

We are going to start with the most basic one, theHTTP Basic authentication, continue withcookiesandtokens, and finish up withsignaturesandone-time passwords.

HTTP authentication methods

HTTP Basic authentication is a simple authentication method for the client to provide a username and a password when making a request.

This is the simplest possible way to enforce access control as it doesn’t require cookies, sessions or anything else. To use this, the client has to send theAuthorizationheader along with every request it makes. The username and password are not encrypted, but constructed this way:

  • username and password are concatenated into a single string:username:password
  • this string is encoded with Base64
  • theBasickeyword is put before this encoded value

Example for a user namedjohnwith passwordsecret:

curl --header "Authorization: Basic am9objpzZWNyZXQ=" my-website.com

The same can be observed in Chrome as well:

Web Authentication Methods Explained - RisingStack Engineering (1)

Implementing it is pretty easy in Node.jsNode.js is an asynchronous event-driven JavaScript runtime and is the most effective when building scalable network applications. Node.js is free of locks, so there's no chance to dead-lock any process. as well – the following snippet shows how you can do an Express middleware to do so.

Of course, you can do it on a higher level, like innginx.

Looks simple, right? So what are thedrawbacks ofusingHTTP Basic authentication?

The cons:

  • the username and password are sent with every request, potentially exposing them – even if sent via a secure connection
  • connected to SSL/TLS, if a website uses weak encryption, or an attacker can break it, the usernames and passwords will be exposed immediately
  • there is no way to log out the user using Basic auth
  • expiration of credentials is not trivial – you have to ask the user to change password to do so

Cookies

When a server receives an HTTP request in the response, it can send aSet-Cookieheader. The browser puts it into a cookie jar, and the cookie will be sent along with every request made to the same origin in theCookieHTTP header.

To use cookies for authentication purposes, there are a few key principles that one must follow.

Always use HttpOnly cookies

To mitigate the possibility of XSS attacks always use theHttpOnlyflag when setting cookies. This way they won’t show up indocument.cookies.

Always use signed cookies

With signed cookies, a server can tell if a cookie was modified by the client.

This can be observed in Chrome as well – first let’s take a look at how a server set cookies:

Web Authentication Methods Explained - RisingStack Engineering (3)

Later on all the requests use the cookies set for the given domain:

Web Authentication Methods Explained - RisingStack Engineering (4)

The cons:

  • Need to make extra effort to mitigateCSRF attacks
  • Incompatibility with REST – as it introduces a state into a stateless protocol

Tokens

Nowadays JWT (JSON Web Token) is everywhere – still it is worth taking a look on potential security issues.

First let’s see what JWT is!

JWT consists of three parts:

  • Header, containing the type of the token and the hashing algorithm
  • Payload, containing the claims
  • Signature, which can be calculated as follows if you chose HMAC SHA256:HMACSHA256( base64UrlEncode(header) + "." + base64UrlEncode(payload), secret)

Adding JWT to Koa applications is only a couple of lines of code:

Example usage –(to check out the validity/content of the token, you can usejwt.io):

curl --header "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ" my-website.com 

As the previous ones, the tokens can be observed in Chrome as well:

Web Authentication Methods Explained - RisingStack Engineering (5)

If you are writing APIs for native mobile applications or SPAs, JWT can be a good fit. One thing to keep in mind: to use JWT in the browser you have to store it in either LocalStorage or SessionStorage, which can lead to XSS attacks.

The cons:

Signatures

Either using cookies or tokens, if the transport layer for whatever reason gets exposed your credentials are easy to access – and with a token or cookie the attacker can act like the real user.

A possible way to solve this – at least when we are talking about APIs and not the browser is to sign each request. How does that work?

When a consumer of an API makes a request it has to sign it, meaning it has to create a hash from the entire request using a private key. For that hash calculation you may use:

  • HTTP method
  • Path of the request
  • HTTP headers
  • Checksum of the HTTP payload
  • and a private key to create the hash

To make it work, both the consumer of the API and the provider have to have the same private key. Once you have the signature, you have to add it to the request, either in query strings or HTTP headers. Also, a date should be added as well, so you can define an expiration date.

Web Authentication Methods Explained - RisingStack Engineering (6)

AWS Request Signing Flow –source

Why go through all these steps? Becauseeven if the transport layer gets compromised, an attacker can only read your traffic, won’t be able to act as a user, as the attacker will not be able to sign requests – as the private key is not in his/her possession.Most AWS services are using this kind of authentication.

node-http-signaturedeals with HTTP Request Signing and worth checking out.

The cons:

  • cannot use in the browser / client, only between APIs

One-Time Passwords

One-Time passwords algorithms generate a one-time password with a shared secret and either the current time or a counter:

  • Time-based One-time Password Algorithm, based on the current time,
  • HMAC-based One-time Password Algorithm, based on a counter.

These methods are used in applications that leverage two-factor authentication: a user enters the username and password then both the server and the client generates a one-time password.

In Node.js, implementing this usingnotpis relatively easy.

Cons:

  • with the shared-secret (if stolen) user tokens can be emulated
  • because clients can be stolen / go wrong every real-time application have methods to bypass this, like an email reset that adds additional attack vectors to the application

Which type of authentication method to pick when?

In this article we discussed several types of authentication methods for web applications:

If you have to support a web application only, either cookies or tokens are fine – for cookies think about XSRF, for JWT take care of XSS.

If you have to support both a web application and a mobile client, go with an API that supports token-based authentication.

If you are building APIs that communicate with each other, go with request signing.

Do you have additional thoughts on website authentication protocols and secure web authentication techniques? Share it in the comments.

In case you’re looking forNode development or consulting services, don’t hesitate to reach out to us.

Web Authentication Methods Explained - RisingStack Engineering (2024)

FAQs

What are the methods of authentication for Web applications? ›

Choose Cookie or Token-based authentication. If you want to support both web as well mobile clients go with API-token with that of Cookie-based authentication. For a standard web app authentication, you can also opt for One Time Password(OTP), Two Factor Authentication(2FA), and Email verification, among others.

What are the 3 types authentication methods and what is included in each? ›

There are generally three recognized types of authentication factors:
  • Type 1 – Something You Know – includes passwords, PINs, combinations, code words, or secret handshakes. ...
  • Type 2 – Something You Have – includes all items that are physical objects, such as keys, smart phones, smart cards, USB drives, and token devices.

What are the authentication methods supported by web checks? ›

The web form (HTML-based), HTTP authentication, or certificate authentication methods are supported for single-URL browser monitors and browser clickpaths.

Which web authentication method is most secure? ›

1. Biometric Authentication Methods. Biometric authentication relies on the unique biological traits of a user in order to verify their identity. This makes biometrics one of the most secure authentication methods as of today.

What is the most common form of authentication in web applications today? ›

Password-based authentication

Passwords are the most common methods of authentication. Passwords can be in the form of a string of letters, numbers, or special characters. To protect yourself you need to create strong passwords that include a combination of all possible options.

What type of authentication is used in Web API? ›

There are four ways to authenticate when calling a web API: API key authentication. Basic authentication. OAuth 2.0 Client Credentials Grant.

What is the basic authentication method? ›

Basic Authentication is a method for an HTTP user agent (e.g., a web browser) to provide a username and password when making a request.

What is the strongest authentication factor? ›

Biometric and possession-based authentication factors may be the strongest means of securing a network or application against unauthorized access. Combining these methods into a multifactor authentication process decreases the likelihood of a hacker gaining unauthorized access to the secured network.

What are three main examples of authentication? ›

In this article, we'll cover these three types of authentication in more detail, exploring how they work and giving examples for each one.
  • Something You Know. ...
  • Something You Have. ...
  • Something You Are. ...
  • Summary.
Apr 23, 2024

What is the best authentication system for web apps? ›

Cookie- or token-based authentication is best for web-based applications. API-token authentication is better than cookie-based authentication to support both web and mobile.

How does web authentication work? ›

The WebAuthn protocol uses a public-private keypair to authenticate the user via a WebAuthn-capable browser. The private key (biometrics or external hardware) is stored on the user's device.

How to find the authentication method of a website? ›

All you have to do is click on the URL and check whether the site in question has an “HTTP” or “HTTPS” tag. The "https" tag is more secure compared to “HTTP”. HTTP is an abbreviation for “hypertext transfer protocol,” which enables your web browser and server to communicate by exchanging data.

What is the best authentication for websites? ›

The Top 10 User Authentication And Access Management Solutions include:
  • Duo Advantage.
  • Entrust Identity Enterprise.
  • IBM Security Verify.
  • JumpCloud Protect.
  • Microsoft Entra ID.
  • Okta Adaptive Multi-Factor Authentication.
  • Onelogin Workforce Identity.
  • SecureAuth.
Jul 22, 2024

What type of authentication is a website using? ›

Form-based Authentication

This is the most common form of web authentication. It uses an HTML form to collect the username and password, which are then submitted to the server. The advantage of this method is it's simple to implement and supported by all browsers.

What are the 3 forms of authentication that can be used in an app and be able to differentiate them with one another? ›

Top 3 Types of User Authentication
  • Password-based User Authentication. The first type of user authentication on our top 3 list is password-based user authentication. ...
  • One-time Password (OTP) One-time Password or OTP is commonly used as a second factor for authentication. ...
  • Biometric Authentication.
Jun 28, 2024

What is two factor authentication for web applications? ›

Two Factor Authentication gives the user and system administrator a peace of mind as it ensures that even if the users password is compromised the account cannot be accessed without also knowing not only the method used as the second factor but also having access to the second factor such as a dynamically generated one ...

Top Articles
A court just ruled that CFPB's funding is unconstitutional, and that could be 'catastrophic' for mortgage markets - newspaperswale
Cardano ADA vs. Ethereum: A Comprehensive Analysis of Two Blockchain Titans
3 Tick Granite Osrs
Time in Baltimore, Maryland, United States now
855-392-7812
Pangphip Application
Myexperience Login Northwell
Academic Integrity
Athletic Squad With Poles Crossword
Ogeechee Tech Blackboard
Ave Bradley, Global SVP of design and creative director at Kimpton Hotels & Restaurants | Hospitality Interiors
Whitley County Ky Mugshots Busted
5808 W 110Th St Overland Park Ks 66211 Directions
Oc Craiglsit
Nioh 2: Divine Gear [Hands-on Experience]
Nissan Rogue Tire Size
Mzinchaleft
Tygodnik Polityka - Polityka.pl
2024 INFINITI Q50 Specs, Trims, Dimensions & Prices
Aes Salt Lake City Showdown
Wics News Springfield Il
Vernon Dursley To Harry Potter Nyt Crossword
Обзор Joxi: Что это такое? Отзывы, аналоги, сайт и инструкции | APS
Soul Eater Resonance Wavelength Tier List
HP PARTSURFER - spare part search portal
Valley Craigslist
The Creator Showtimes Near Baxter Avenue Theatres
Ehome America Coupon Code
Craigslist Texas Killeen
Craigslist Maryland Baltimore
Forager How-to Get Archaeology Items - Dino Egg, Anchor, Fossil, Frozen Relic, Frozen Squid, Kapala, Lava Eel, and More!
Nacho Libre Baptized Gif
AsROck Q1900B ITX und Ramverträglichkeit
Louisville Volleyball Team Leaks
Are you ready for some football? Zag Alum Justin Lange Forges Career in NFL
3400 Grams In Pounds
968 woorden beginnen met kruis
Davis Fire Friday live updates: Community meeting set for 7 p.m. with Lombardo
Clima De 10 Días Para 60120
Simnet Jwu
Ezpawn Online Payment
Subdomain Finder
Shipping Container Storage Containers 40'HCs - general for sale - by dealer - craigslist
3 bis 4 Saison-Schlafsack - hier online kaufen bei Outwell
6576771660
2017 Ford F550 Rear Axle Nut Torque Spec
The Sports Academy - 101 Glenwest Drive, Glen Carbon, Illinois 62034 - Guide
8 4 Study Guide And Intervention Trigonometry
Windy Bee Favor
Lesson 5 Homework 4.5 Answer Key
Black Adam Showtimes Near Cinemark Texarkana 14
Island Vibes Cafe Exeter Nh
Latest Posts
Article information

Author: Ouida Strosin DO

Last Updated:

Views: 5374

Rating: 4.6 / 5 (56 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Ouida Strosin DO

Birthday: 1995-04-27

Address: Suite 927 930 Kilback Radial, Candidaville, TN 87795

Phone: +8561498978366

Job: Legacy Manufacturing Specialist

Hobby: Singing, Mountain biking, Water sports, Water sports, Taxidermy, Polo, Pet

Introduction: My name is Ouida Strosin DO, I am a precious, combative, spotless, modern, spotless, beautiful, precious person who loves writing and wants to share my knowledge and understanding with you.