Tightening Bearer Token Authentication with Proof-of-Possession Tokens Using Kong (2024)

Engineering

November 15, 2023

5 min read

Tightening Bearer Token Authentication with Proof-of-Possession Tokens Using Kong (1)

Veena Rajarathna

Staff Product Manager, Kong

Access tokens

In token-based architecture, tokens represent the client’s entitlement to access protected resources. Access tokens (or bearer tokens as they're commonly known) are issued by authorization servers after successful user authentication. The tokens are passed as credentials in the request to the target APIs which inform the API that the bearer of the token is authorized to access the API and perform certain actions.

Challenges with access/bearer tokens

In the flows where access tokens grant access to protected resources, the legitimacy of the token bearer is assumed. Access is granted based on the validity of the token. There is no validation that the bearer is in fact the legitimate owner of the token. This is one of the main vulnerabilities of a bearer token.

If the tokens fall into the hands of bad actors, they can be misused. With the stolen or leaked tokens, bad actors can easily impersonate the user and obtain unauthorized access to protected resources.

For any average API provider, this is a major concern. Recently, Sourcegraph experienced a securityincidentwith leaked admin tokens. The malicious users used their privileges to increase API rate limits for a small number of users. For environments with heightened security needs, stolen or leaked tokens are a serious security risk.

A solution to secure access tokens

A solution to this problem is constraining the tokens issued by authorization server to clients (sender-constrained tokens)so only the entity/client to whom a token was issued can use the token to access resources. This approach is also known asholder of keyorproof of possessiontokens.

The client presenting the access token has to prove that they are authorized to use the token. To achieve this, the authorization servers bind the tokens to the client's cryptographic keys. Resource servers can then validate the clients are in possession of those keys and grant/deny access accordingly.

Advantages of sender-constrained tokens

The primary security vulnerability of standard bearer tokens is remediated, as the legitimacy of the bearer is verified. Access to the protected resource is granted after successful validation of

  1. The client certificate used in the connection
  2. The thumbprint of the client certificate in the token matching the client certificate in the underlying connection
  3. Token validity

For environments with high security requirements such as financial services, e-health, and e-gov, this added layer of token security mitigates the risk of misuse of tokens as sender-constrained tokens simply cannot be replayed or redirected by an unauthorized party.

Moreover, usage of sender-constrained tokens is a must in open banking. One of the requirements of financial API (FAPI2.0) is for the resource servers to support and verify sender-constrained access tokens using either of the methods.

Example of an access token with certificate thumbprint

Tightening Bearer Token Authentication with Proof-of-Possession Tokens Using Kong (2)

Implementations of sender-constrained tokens

TheRFCdescribes two methods to implement sender-constrained tokens

  1. Using Client Certificates (mTLS ) - Certificate-bound access tokens
  2. The Demonstration of Proof-of-Possession (DPoP) at application layer

Gateway Enterprise 3.5 offers Certificate-Bound Access Tokens via mTLS.

Certificate-bound access tokens

With mTLS, the access tokens are bound to the underlying mutual TLS connection between the client and the authorization server. Such tokens are known ascertificate-bound access tokens. This approach uses the Public Key Infrastructure (PKI). The CA is trusted by the Authorization server and Kong.

Figure 1 shows a sample exchange between the client, IDP, and Kong. In a request to obtain a token, the client establishes a mutual TLS session with the authorization server’s token endpoint. After a successful TLS client authentication, the authorization server will mint an access token, encode the thumbprint of (hash) the client certificate either directly in the token (JWT) or in the Introspection Response (when using opaque tokens).

To access resources protected by Kong, the client establishes a TLS connection to Kong Gateway using the same client certificate and presents the access token. The same CA is trusted by Kong as well. Kong validates the client certificate and the certificate thumbprint in the tokens to the underlying mTLS connection. Access to the protected resource is granted after successful validation of all three.

  1. The client certificate used in the connection
  2. The thumbprint of the client certificate in the token matching the client certificate in the underlying connection
  3. Token validity

Tightening Bearer Token Authentication with Proof-of-Possession Tokens Using Kong (3)

Kong’s support of certificate-bound access tokens: How it all comes together

To support certificate-bound tokens there are requirements on all parties involved in a typical token-based flow. Following are the prerequisites for each party involved in the flow

Prerequisites

  1. Authorization server that is capable of generating OAuth 2.0 Mutual TLS Certificate Bound Access Tokens
  2. A Certificate Authority(CA) that trusted by both the Authorization Server and Kong. The CA is used to issue client certificates
  3. A client application with an appropriate grant type (example client credentials grant) and ability to handle sender constrained tokens via mTLS
  4. Kong Gateway 3.5 with OIDC and mTLS plugins
  5. Upstream API service to which Kong proxies the request
  6. Client certificates issued to clients

Configuring Kong

Kong can be instructed to handle certificate-bound access tokens with the help of two plugins:

  1. OIDCplugin
  2. mTLS plugin such asTLS modifierormtls-auth

TLS Modifier plugindoes not enforce a mTLS connection. However, for certificate-bound access tokens to work, a client certificate must be presented along with the token

mtls-authThe CN check/validation cannot be disabled in the plugin and hence the plugin requires consumer mapping. Consumer objects should be created and client certificates need to be mapped.

Kong supports the usage of certificate-bound access tokens in three authentication flows. In these flows, the client entity obtains an access token from the authorization server's token endpoint and presents that as a bearer in the request to Kong. If the access token is opaque, Kong exchanges it for a JWT by calling the introspection endpoint.

  1. JWT bearer
  2. Introspection
  3. Session (Session Authentication is only compatible with certificate-bound access tokens when used along with one of the other supported authentication methods)

OIDC plugin configuration options

OIDC plugin offers two new settings to control the behavior of the plugin for certificate-bound tokens.

Tightening Bearer Token Authentication with Proof-of-Possession Tokens Using Kong (4)

With all the prerequisites met and the plugins configured to support certificate-bound tokens, Kong Gateway will enforce the incoming requests to establish a mutual TLS connection using a valid client certificate and present an access token. Kong proxies the request after successful validation of the certificate thumbprint in the token to the client certificate in the underlying connection.

For step-by-step instructions on how to enable the feature refer toOpenID Connect | Kong Docs

Conclusion

With this feature, Kong complies with the requirements of financial API (FAPI 2.0) to support and verify sender-constrained access tokens. It's not limited to open banking or financial services. Mutual TLS Sender-Constrained Tokens are a suitable implementation for any environment with high security requirements such as e-gov and e-health. The solution forces the sender to prove they are the rightful owner of the token. This added layer of security mitigates the risk of misuse of tokens as they cannot be used without proof of possession.

Tags:api authentication

|

API Security

|

Governance

Tightening Bearer Token Authentication with Proof-of-Possession Tokens Using Kong (2024)

FAQs

How to authenticate with bearer token? ›

The authenticated user obtains the Bearer token issued by the server and sends it to the server in the header of the request. The server verifies the received bearer token and controls user access based on the token. The Bearer token is also usually sent over an encrypted connection via HTTPS.

What is proof of possession token? ›

PoP tokens are bound to the client machine, via a public/private PoP key. The PoP public key is injected into the token by the token issuer (Entra ID) and the client also signs the token using the private PoP key. A fully formed PoP token has two digital signatures - one from the token issuer and one from the client.

How do I protect my API with bearer token? ›

Here's a step-by-step explanation of how JWT Bearer Token authentication typically works:
  1. Client Login: The client sends a login request with user credentials to the server.
  2. Server Verification: The server verifies the credentials. ...
  3. Token Issuance: The server sends the JWT back to the client.
Jun 17, 2024

What is the best way to store authentication tokens? ›

These can be stored server-side or in a session cookie. The cookie needs to be encrypted and have a maximum size of 4 KB. If the data to be stored is large, storing tokens in the session cookie is not a viable option.

Is Bearer authentication the same as token authentication? ›

Bearer authentication is a more advanced and secure authentication method that uses tokens instead of credentials. A token is a string of characters that represents the identity and permissions of the client. The client obtains a token from an authentication server by providing valid credentials or other information.

How to pass bearer token to API? ›

Passing a bearer token in your API calls
  1. Set up token authentication, and then get a bearer access token. For more information, see Setting up token authentication and Getting a token.
  2. Most Venafi API headers require an Authorization parameter. ...
  3. In the header, add the Authorization parameter.

Is bearer token the same as API key? ›

API keys offer simplicity and ease of use, making them ideal for straightforward applications and server-to-server communication. On the other hand, Bearer tokens provide enhanced security, user context, and flexibility, making them perfect for user-centric applications and high-security environments.

What is the vulnerability of bearer token? ›

This is one of the main vulnerabilities of a bearer token. If the tokens fall into the hands of bad actors, they can be misused. With the stolen or leaked tokens, bad actors can easily impersonate the user and obtain unauthorized access to protected resources.

What is the difference between bearer token and holder of key token? ›

A bearer token does not verify the identity of the user or entity that is sending the request. This value specifies the lifetime value of a bearer token before the token has to be reissued. Holder-of-key tokens provide authentication based on security artifacts that are embedded in the token.

What is better than token authentication? ›

If your application handles sensitive data or requires rapid revocation, session-based authentication may be the better choice. If your application needs fast, efficient authorization or requires more interaction between the client and server, token-based authentication may be more suitable.

How do I authenticate a user using token? ›

Token-based authentication works through this five-step process:
  1. Request: The user logs in to a service using their login credentials, which issues an access request to a server or protected resource.
  2. Verification: The server verifies the login information to determine that the user should have access.

How do I secure my authentication token? ›

Before we actually get to implementing JWT, let's cover some best practices to ensure token based authentication is properly implemented in your application.
  1. Keep it secret. Keep it safe. ...
  2. Do not add sensitive data to the payload. ...
  3. Give tokens an expiration. ...
  4. Embrace HTTPS. ...
  5. Consider all of your authorization use cases.

How do I verify my bearer token online? ›

For access JWTs the standard type is at+jwt. Algorithm check -- The JWS algorithm specified in the JWT header must match the agreed / expected one (e.g. "RS256" for an RSA PKCS #1 signature with SHA-256). If a token's JWS algorithm is unexpected it is rejected.

How do I validate my authentication token? ›

You can validate your tokens locally by parsing the token, verifying the token signature, and validating the claims that are stored in the token. Parse the tokens. The JSON Web Token (JWT) is a standard way of securely passing information. It consists of three main parts: Header, Payload, and Signature.

How do I authenticate my personal access token? ›

From your home page, open user settings and select Personal access tokens. Select + New Token. Name your token, select the organization where you want to use the token, and then set your token to automatically expire after a set number of days. Select the scopes for this token to authorize for your specific tasks.

Top Articles
How hard is it to get a job at JP Morgan?
55+ “Can't Wait to See You” Texts & Flirty Responses
Using GPT for translation: How to get the best outcomes
Trevor Goodwin Obituary St Cloud
Pieology Nutrition Calculator Mobile
PRISMA Technik 7-10 Baden-Württemberg
Best Theia Builds (Talent | Skill Order | Pairing + Pets) In Call of Dragons - AllClash
You can put a price tag on the value of a personal finance education: $100,000
Craigslist Estate Sales Tucson
Olivia Ponton On Pride, Her Collection With AE & Accidentally Coming Out On TikTok
Moonshiner Tyler Wood Net Worth
Trac Cbna
Video shows two planes collide while taxiing at airport | CNN
R Personalfinance
Healthier Homes | Coronavirus Protocol | Stanley Steemer - Stanley Steemer | The Steem Team
Juicy Deal D-Art
Shiftselect Carolinas
Baja Boats For Sale On Craigslist
Japanese Mushrooms: 10 Popular Varieties and Simple Recipes - Japan Travel Guide MATCHA
European Wax Center Toms River Reviews
Saxies Lake Worth
When His Eyes Opened Chapter 3123
Vht Shortener
How rich were the McCallisters in 'Home Alone'? Family's income unveiled
Housing Intranet Unt
Halsted Bus Tracker
Otis Offender Michigan
Smartfind Express Henrico
Orangetheory Northville Michigan
How to Play the G Chord on Guitar: A Comprehensive Guide - Breakthrough Guitar | Online Guitar Lessons
Lyca Shop Near Me
Trap Candy Strain Leafly
Hometown Pizza Sheridan Menu
Reese Witherspoon Wiki
Sdn Fertitta 2024
Walgreens On Secor And Alexis
Hawkview Retreat Pa Cost
Unblocked Games - Gun Mayhem
Accident On 40 East Today
Aloha Kitchen Florence Menu
City Of Irving Tx Jail In-Custody List
60 Second Burger Run Unblocked
Helpers Needed At Once Bug Fables
Sj Craigs
Parks And Rec Fantasy Football Names
Bumgarner Funeral Home Troy Nc Obituaries
Cool Math Games Bucketball
Yoshidakins
Latest Posts
Article information

Author: Allyn Kozey

Last Updated:

Views: 6143

Rating: 4.2 / 5 (63 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Allyn Kozey

Birthday: 1993-12-21

Address: Suite 454 40343 Larson Union, Port Melia, TX 16164

Phone: +2456904400762

Job: Investor Administrator

Hobby: Sketching, Puzzles, Pet, Mountaineering, Skydiving, Dowsing, Sports

Introduction: My name is Allyn Kozey, I am a outstanding, colorful, adventurous, encouraging, zealous, tender, helpful person who loves writing and wants to share my knowledge and understanding with you.