DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
11 Monitoring and Observability Tools for 2023
Learn more
  1. DZone
  2. Software Design and Architecture
  3. Security
  4. How to Improve OAuth Security With HMAC Validation

How to Improve OAuth Security With HMAC Validation

We explain a type of attack that's possible to carry out on systems using OAuth and how to mitigate them using keyed-Hash Message Authentication Code Validation.

Lahiru Sandaruwan user avatar by
Lahiru Sandaruwan
·
Dec. 05, 17 · Tutorial
Like (3)
Save
Tweet
Share
8.05K Views

Join the DZone community and get the full member experience.

Join For Free

Today, everyone focuses on advanced security measures and preventing all possible attacks on their enterprise software. This post will explain a type of attack that's possible to carry out on systems using OAuth and how you can mitigate them by adding keyed-Hash Message Authentication Code (HMAC) validation to the OAuth token. This specific solution can be used when your enterprise platform is built with WSO2 API Manager and WSO2 Identity Server.

The main use case this would address is preventing miss-use of expired OAuth tokens or randomly generated OAuth tokens. Stolen or randomly generated tokens can be used to employ DoS/DDoS attacks effectively.

If an attacker uses random tokens to send API requests, API Manager and IS will be trying to verify the token and it will go through the critical path of verification. This is a costly transaction and it can cause high latencies and instability in WSO2 APIM (WSO2 API Manager) and WSO2 IS (WSO2 Identity Server) clusters. Implementation of this particular solution is done using extensions developed for standard extension points of WSO2 IS and WSO2 APIM.

WSO2 IS Extension — OAuth Token Generator Extension

Please find more information on developing OAuth token generator extensions here. Code for this particular solution can be found in my GitHub repository here.

You can engage this handler by adding the following entry to your IS_HOME/repository/conf/identity.xml.

<IdentityOAuthTokenGenerator>com.sample.lahiru.wso2.hmac.oauth</IdentityOAuthTokenGenerator>

This extension is responsible for enhancing the OAuth token with HMAC (Hash-based Message Authentication Code) so that the above-discussed attacks will be less effective. The following two parts will be added to the token in addition to the default token created in WSO2 IS.

  • HMAC
  • Expiry timestamp

Access Token Format

Token has 3 parts, delimited by “.”

Part I — Original access token issued from WSO2 Identity Server.

Part II — Hex value for token expiry time.

Part III — HMAC calculation of (‘Part I’ + ‘.’ + ‘Part II’).

<Part I>.<Part II>.<Part III>

For Example:

ba13cf7473cfbde970ae6e8b60973f64.0000015fc1ebabde.67830f2f2886256eb80faa9dab85c3d2c9be7db1

WSO2 APIM Extension — HMAC and Timestamp Verification Handler

Please refer to this document to understand how to develop and engage WSO2 API handler extensions. You can find the code for APIM handler on GitHub, here.

You can engage this handler by adding the following entry before “#foreach($handler in $handlers)” line of “velocity_template.xml” file. You can find this file at APIM_HOME/repository/resources/api_templates/ directory.

<handler class=“com.sample.lahiru.wso2.hmac.handler.HMACTokenValidatorHandler”/>

This custom handler verifies the HMAC of the token before it tries to authenticate using a default authentication handler, which will be an expensive operation usually. It will also make sure the token is not expired. These verifications will avoid any API calls to WSO2 IS, in case the token is expired or HMAC is invalid.

HMAC validation handler calculates the HMAC using Part I and Part II (see access token format), extracted from the token and validates by comparing that value with the HMAC value included in the token (Part III).

authentication security

Published at DZone with permission of Lahiru Sandaruwan. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Keep Your Application Secrets Secret
  • Steel Threads Are a Technique That Will Make You a Better Engineer
  • Unlock the Power of Terragrunt’s Hierarchy
  • Custom Validators in Quarkus

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: