WSO2 is now Choreo LabsLearn more

Trusted AI Governance
Build

Create agents and AI apps with the tools and languages your teams already use.

Connect

Link agents securely to your APIs, data, models and business systems.

Run

Deploy, observe and operate agents and AI apps reliably at any scale.

Govern

Control identity, access, cost and policy for every agent in production.

Agent Management

Developer Platform

  • API Management Cloud

    Design, secure and publish APIs with governance and analytics built in.

    Sign Up Now
  • Integration Cloud

    Connect apps, data and AI agents with low-code and pro-code integration.

    Sign Up Now
  • Identity & Access Management Cloud

    Secure sign-in and access for customers, partners, workforce and agents.

    Sign Up Now
  • Agent Management Cloud

    Build, run and govern AI agents with full visibility and control.

    Sign Up Now
  • Developer Platform Cloud

    Ship cloud-native apps faster on an internal developer platform.

    Sign Up Now

Self-Hosted

Full control over your stack. Deploy directly to your own servers, bare metal, cloud, or Kubernetes environment. Your data never leaves your perimeter.

Product Downloads
Choreo Labs
AI Governance
Platform
Solutions
Resources
Article

A primer on OAuth 2.0 for client-side applications: part 3

Introduction

This is the third part of a four-part article series. In the first part, I looked at the broader categories of client-side applications (CSA), their legacy and more recent authentication and API authorization standards, as well as their pros and cons. In the second, I discussed the challenges in CSAs, standard and non-standard recommendations that are widely employed to overcome those challenges, and some of the non-standard solution patterns for single-page applications (SPA) to overcome limitations in the existing standards I discussed in part 1, specifically regarding OAuth 2.0 proxy patterns.

In this part, I will discuss the important security properties of cookies that make them a suitable candidate for a sender-constrained token technology and more non-standard solution patterns, specifically sender-constrained token patterns.

Tokens Love Cookies

Although the stateful proxy pattern and the stateless proxy pattern could be acceptable for most users, for some users, it may still not be acceptable from a user experience perspective due to it not following a clean SPA architecture.

For those users who do not find the proxy patterns suitable, how do we secure access tokens and refresh tokens from being leaked? Let’s look at some solution patterns to satisfy those users.

In the standard OIDC grant flows we’ve seen so far, the access token and refresh token are returned as JSON attributes in the HTTP response body. The access token and refresh token need to be stored in the browser in order for the client to use them when invoking APIs or refreshing access tokens respectively. For this purpose, you would typically use the HTML5 web storage (localStorage or sessionStorage).

The main drawback of using the HTML web storage is that it is vulnerable to XSS, has a larger attack surface, and can impact all application users on a successful attack. This is considered one of the primary ways a token gets leaked.

HTTP cookies is an alternate client-side storage mechanism. They also provide additional security properties such as the “httpOnly” flag and “secure” flag. With the “httpOnly” flag, the browser makes sure that no client-side script can read these cookies. With the “secure” flag, the browser makes sure that the cookies are only transmitted to the server when the connection is HTTP over TLS.

Cookies also have a drawback. Cookies are vulnerable to cross-site request forgery (CSRF). However, there are effective CSRF prevention mechanisms, such as the synchronization token pattern or the double submit cookie pattern, which are supported by most modern web frameworks. Therefore, cookies are preferred over HTML5 web storage with enough CSRF protection ensured.

Even though they are more secure to store your access tokens, cookies can cause some developer headaches, depending on if your applications require cross-domain access to work. Using AJAX, your server-side can also notify browsers whether credentials (including cookies) should be sent with requests with CORS.

These security properties for cookies lead them to be considered as a suitable candidate for technology to implement sender-constrained token patterns. These patterns allow you to bind the tokens used in OAuth 2.0 to the OAuth 2.0 client, which was originally used to request them. Collectively they are known as “sender-constrained token” patterns.

You may find some API security implementations that rely only on the security properties of a secure HTTP-only cookie to store the access token. You should note that this is not an optimal solution. Firstly, it does not follow the standard Bearer Token Usage (RFC 6750) [1] profile. And secondly, it is vulnerable to CSRF.

To overcome both of these drawbacks, the following two sender-constrained token patterns will help.

JSON Web Tokens (JWT) as OAuth 2.0 Bearer Access Tokens

Please refer to the post on “JSON Web Tokens (JWT) as OAuth 2.0 Bearer Access Tokens” [2].

Summary

In this part of the series, I discussed the important security properties of cookies that make them a suitable candidate for a sender-constrained token technology, and more non-standard solution patterns, specifically sender-constrained token patterns.

In the next part, I will be discussing the latest and upcoming standards following the sender-constrained token pattern aimed at solving the challenges in CSAs, and solution patterns being employed to improve the CSA user experience.

References

[1] https://tools.ietf.org/html/rfc6750

[2] https://medium.com/@johann_nallathamby/json-web-tokens-jwt-as-oauth-2-0-bearer-access-tokens-89120c94c082

[3] https://stormpath.com/blog/where-to-store-your-jwts-cookies-vs-html5-web-storage