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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

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
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

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Building Resilient Identity Systems: Lessons from Securing Billions of Authentication Requests
  • Secure by Design: Modernizing Authentication With Centralized Access and Adaptive Signals
  • MuleSoft OAuth 2.0 Provider: Password Grant Type
  • The Evolution of User Authentication With Generative AI

Trending

  • How GitHub Copilot Helps You Write More Secure Code
  • After 9 Years, Microsoft Fulfills This Windows Feature Request
  • Memory Leak Due to Time-Taking finalize() Method
  • How Large Tech Companies Architect Resilient Systems for Millions of Users
  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.

By 
Lahiru Sandaruwan user avatar
Lahiru Sandaruwan
·
Dec. 05, 17 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
9.2K 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.

Related

  • Building Resilient Identity Systems: Lessons from Securing Billions of Authentication Requests
  • Secure by Design: Modernizing Authentication With Centralized Access and Adaptive Signals
  • MuleSoft OAuth 2.0 Provider: Password Grant Type
  • The Evolution of User Authentication With Generative AI

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!