Token binding in Asgardeo

Kayathiri Mahendrakumaran
Identity Beyond Borders
4 min readOct 15, 2023
Photo by Dan Bucko on Unsplash

Token binding is an essential security mechanism utilized in web protocols to establish a secure connection between an authentication token and the client device that holds it. The primary purpose of token binding is to prevent unauthorized token theft and replay attacks.

Why do we need Token Binding?

In typical web authentication scenarios, a user logs in and obtains an authentication token (such as a session cookie) from the server. This token is then sent with each subsequent request to prove the user’s identity. However, there’s a vulnerability known as token hijacking or session hijacking that arises from the fact that tokens are often not securely tied to the communication channel.

When an attacker intercepts the token, they can impersonate the user by presenting the token from a different device or location. This is particularly problematic in scenarios where the token is transmitted over an insecure network or stored in an insecure manner.

What is the solution?

Token binding is a security mechanism that aims to mitigate this vulnerability by binding the authentication token to a specific communication channel (Binding reference value). This ensures that the token is only valid when presented over the same channel it was issued for, making it much harder for attackers to reuse intercepted tokens.

This diagram visually illustrates how token binding enhances the security of authentication tokens by tying them to a specific communication channel, making it significantly more challenging for attackers to misuse intercepted tokens.

In conventional web authentication scenarios, a server grants a client device an authentication token, such as a session cookie, upon successful authentication. The client then includes this token in subsequent requests to the server to verify its identity and gain access to protected resources. However, without additional safeguards, an attacker who intercepts or steals the token can exploit it to impersonate the client and gain unauthorized access.

Token binding becomes especially crucial in situations where tokens are transmitted over insecure networks, such as the internet, where interception and tampering are possible. By implementing token binding, the security of web protocols is significantly strengthened, providing protection against various types of attacks targeting authentication tokens.

Binding types

In the context of Asgardeo, the following token binding support is provided:

  • None — No binding: This option does not establish any specific binding between the token and the client device. It is suitable for scenarios where token binding is not required or implemented separately.
  • Cookie Based — This binding type is specifically designed to enhance the security of Single Page Applications (SPAs) where the access token is stored in the browser. Along with access token validation, a cookie with Secure and HttpOnly parameters is validated to grant access. In the current implementation, this binding type can be enabled for authorization code grants by enabling the “Allow Authentication without the client secret” option. When this option is enabled, a new cookie named “atbv” is returned to the client browser along with the authorization code. The application includes this cookie when making token requests, and it is validated and attached to the generated tokens. Consequently, the SPA must present both the access token and the cookie for successful authorization when accessing the Asgardeo API.
  • Session Based — This binding type is designed to generate different tokens for each new browser instance. It ensures that the same access token is not shared across multiple browser instances of the same application. Additionally, it allows for revoking the access token when logging out from one application (browser) instance without affecting other instances. Session-based token binding is supported for the authorization code grant type.

Please note that session-based token binding is only supported with the grant type “Code”.

When to use token binding?

Cookies are suitable for most web applications where the security requirements are moderate and token binding is not necessary. However, cookies can be vulnerable to attacks such as session hijacking and CSRF (Cross-Site Request Forgery), so proper security measures should be implemented, such as using HTTPS and secure flags.

Session binding is suitable for web applications where user authentication and session handling are critical but token binding or cookies may not be necessary or feasible.Session management can be implemented using various techniques, including session tokens, session identifiers stored in cookies, or URL rewriting.

In summary, the choice of token binding, cookies, session management, or none depends on the specific requirements and security considerations of your web application. It’s essential to understand the strengths and limitations of each approach and choose the one that best fits your use case.

I hope this helps! Let me know if you need further assistance.

--

--

Kayathiri Mahendrakumaran
Identity Beyond Borders

Senior Software Engineer 👨‍💻, WSO2 | Undergraduate👩‍🎓 , Computer Science & Engineering | Writer ✍️