Authentication – Terms and concepts

Authentication vs. Authorization

Authentication and authorization are foundational concepts in web security, yet they are often confused.

Authentication is the process of verifying the identity of a user or system. In simpler terms, authentication ensures that the user is who they claim to be.

Authorization, on the other hand, is the process of granting or denying access to resources based on the user’s permissions or roles. Essentially, authentication comes first: it identifies the user, while authorization comes second: it determines what the identified user is allowed to do.

Think of it like entering a building:

  • Authentication: Showing your ID at the door to prove you are who you say you are.
  • Authorization: Deciding which rooms you can enter based on your ID.

Understanding the distinction helps in implementing and managing security policies effectively. It’s crucial to get both right to ensure both identity verification and appropriate access control.

Why are both terms often confused?

Both terms start with “auth” and are closely related, leading to surface-level confusion. Authentication typically precedes authorization in most systems. You first prove who you are, then the system decides what you’re allowed to do. Because these steps are often part of a single user interaction, they can be easily conflated. Many systems handle both processes in an integrated manner, making it less obvious to users where one ends and the other begins.

Does authentication always rely on a secret, like a password?

No, authentication often relies on something known only to the user, but it doesn’t always have to. Here’s a quick rundown of different types of authentication:

  1. Something you know: This is the classic approach, like passwords or PINs. It’s a secret that only you know.
  2. Something you have: This could be a physical device, like a smart card, security token, or even your smartphone used in two-factor authentication (2FA).
  3. Something you are: This involves biometric data, like fingerprints, facial recognition, or retina scans.
  4. Somewhere you are: This is based on your location, which can be tracked through GPS or IP addresses.

While secrets (like passwords) are common, modern security systems often use multiple factors (like two-factor or multi-factor authentication) to add extra layers of protection beyond just a secret. This makes it harder for unauthorized users to gain access.

Token

In the context of authentication, a token is a piece of data that is generated by an authentication server and provided to a client to use as proof of identity. Tokens are used to grant access to resources without repeatedly asking the user to re-enter their credentials.

Types of Tokens

  1. Session Tokens: These are generated upon successful login and are used to maintain a user’s session. When a user logs in, the server generates a session token that is stored in the user’s browser (often as a cookie) and sent with each request to authenticate the user. Session tokens can be categorized depending on where the information is stored:
    • Server-Side Storage: These kind of tokens are “stateful” because they are often stored on the server in a session store (like a database or in-memory store). The client holds a reference (typically a session ID) that the server uses to look up the session data.
      • Advantages: The server has full control over session management, which can enhance security and allow for easy invalidation of sessions.
      • Disadvantages: Requires additional server resources to manage sessions and can be less scalable.
    • Client-Side Storage: These tokens are self-contained and “stateless”, because they do not require the server to maintain session information, instead they include all necessary information within the token itself, which is digitally signed. They are typically stored on the client side, often in local storage or cookies.
      • Advantages: Scales well as no server-side storage is required. The server only needs to validate the token signature.
      • Disadvantages: The token is as secure as the client’s storage mechanism. Tokens can also become large if they include a lot of data.
    • Hybrid approaches: Sometimes, a hybrid approach is used where a session token might contain a reference to server-side data, balancing between scalability and control.
  2. Access Tokens: These tokens are often short-lived and grant access to specific resources. They are commonly used in APIs and OAuth implementations. Access tokens include information about the user’s permissions and are verified by the resource server to allow or deny access.
  3. Refresh Tokens: These are used to obtain new access tokens without requiring the user to re-authenticate. Refresh tokens are typically long-lived and can be exchanged for new access tokens when the old ones expire.

How Tokens Enhance Security

  • Reduced Credential Exposure: Once a user is authenticated, their actual credentials (like a password) are no longer needed for each request. Instead, the token is used, reducing the risk of credential interception.
  • Token Expiry: Tokens often have expiration times, which limits the window of opportunity for misuse if a token is compromised.
  • Granular Access Control: Access tokens can include detailed scopes and permissions, allowing precise control over what resources a user can access.

Challenge and Nonce

In the context of authentication, a “challenge” is a piece of data sent by a server to a client to verify the client’s identity. This is part of a challenge-response mechanism. The server sends a unique challenge (e.g. “abc123”), often including a nonce (a number used once) or a timestamp. The client then responds with a hashed value based on the challenge and the client’s credentials (e.g. hashing the challenge “abc123” + “my-password”). The server compares this hashed value with its own calculation to verify the client’s identity. This method ensures that the actual password is never sent over the network, enhancing security.

Why not simply send the hashed password?

Protection Against Replay Attacks: If you send a static password hash, an attacker could intercept this hash and reuse it to authenticate. By using a unique challenge for each authentication attempt, the response changes every time, making intercepted data useless for future attempts.
Dynamic Authentication: The challenge-response mechanism ensures that each authentication session is unique. Even if an attacker captures the data from one session, they can’t use it to gain access later because the challenge will be different.
Reduced Exposure of Password Hashes: Sending password hashes directly over the network exposes them to potential interception. By using a challenge-response mechanism, the actual hash of the password is never transmitted. Instead, a hashed combination of the password and the challenge is sent, which is meaningless without the original challenge.
Man-in-the-Middle Attack Mitigation: In a man-in-the-middle attack, an attacker intercepts communication between the client and server. With a challenge-response mechanism, the attacker can’t simply pass on captured hashes because each challenge-response pair is unique to the session.

Here’s a simple analogy: imagine you have a lock that changes its pattern every time you use it (the challenge). You have a key that can adjust itself to match the current pattern (the password). Without knowing the lock’s current pattern, an intercepted key wouldn’t work on any other lock.

When are challenges used and when not?

Challenges are usually used in Digest Authentcation, Multi-Factor Authentication, Digital Certificates of a Public Key Infrastructure, Biometric Authentication, Token-Based Authentication, Network Authentication like Kerberos.

Examples where a challenge-response approach is not used:

Simple Password Authentication: This is the basic approach where users just provide their username and password directly. There’s no challenge involved; the server checks the credentials against stored information.

SMS-Based OTP: A server sends a one-time password to the user’s mobile device, which the user then enters to authenticate. The OTP is generated independently, without a server-issued challenge.

OAuth: In some OAuth implementations, once the user has authenticated with the identity provider (e.g., logging into Google or Facebook), they receive a token that they can use to access various services. The initial authentication might involve a challenge, but subsequent use of the token does not.

Static API Keys: Applications often use static API keys to authenticate requests. These keys are included in each request and do not involve a challenge-response mechanism.

Local Biometric Verification: For instance, unlocking a device with a fingerprint or facial recognition often involves local verification against stored biometric data without a dynamic challenge from a server.

About Author

Mathias Bothe To my job profile

I am Mathias from Heidelberg, Germany. I am a passionate IT freelancer with 15+ years experience in programming, especially in developing web based applications for companies that range from small startups to the big players out there. I create Bosycom and initiated several software projects.