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 Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Safeguarding Web Applications With Cloud Service Providers: Anti-CSRF Tokenization Best Practices
  • Keep Your Application Secrets Secret
  • Five Steps To Building a Tier 1 Service That Is Resilient to Outages
  • 10 Go Best Practices Every Backend Developer Should Know

Trending

  • Stop Writing Dialect-Specific SQL: A Unified Query Builder for Node.js
  • Stop Running Two Data Systems for One Agent Query
  • AWS Managed Database Observability: Monitoring DynamoDB, ElastiCache, and Redshift Beyond CloudWatch
  • DevOps and Platform Engineering Readiness Checklist: Everything Needed for a Scalable, Secure, High-Velocity Delivery Platform
  1. DZone
  2. Software Design and Architecture
  3. Performance
  4. How to Handle the CSRF Token in JMeter

How to Handle the CSRF Token in JMeter

When we do load testing using JMeter without handling the CSRF token, you get a certain error. Learn how to handle the CSRF token in JMeter.

By 
manoj mathpal user avatar
manoj mathpal
·
May. 09, 17 · Tutorial
Likes (16)
Comment
Save
Tweet
Share
36.1K Views

Join the DZone community and get the full member experience.

Join For Free

What is CSRF? CSRF stands for Cross-Site Request Forgery. Generally, when we log into a website, it always asks for authentication. From a security point-of-view, developers mostly time pass the CSRF token with a login parameter. But our focus is on how to handle this CSRF token in JMeter.

When we do load testing using JMeter without handling the CSRF token, we get this type of error:csrf token

CSRF and JMeter

For handling the CSRF token, we have to use the following parameters in JMeter:

  • HTTP cookie manager.

  • HTTP header manager.

  • Request paramter.

Extract CSRF Token Using JMeter Post Processors

For extracting CSRF, we have to add post processors in the test plan. Then, we have to add a regular expression extractor.

csrf token value

The regular expression extractor handles this CSRF token and its value each time this value is changed. In the regular expression extractor, we have to define certain fields:

  • Reference name: value

  • Regular expression: name="csrfToken" value="(.+?)"

  • Template: $1$

  • Match no: 1

regular expression extractor

We just pass this JMeter variable in the request parameter:

request parameter

Now, we execute the script and see the result:

login with extractor

This is how you can deal with CSRF protection in your Apache JMeter test script.

Load testing Apache JMeter Requests POST (HTTP) Testing Pass (software) Template security dev Extract

Opinions expressed by DZone contributors are their own.

Related

  • Safeguarding Web Applications With Cloud Service Providers: Anti-CSRF Tokenization Best Practices
  • Keep Your Application Secrets Secret
  • Five Steps To Building a Tier 1 Service That Is Resilient to Outages
  • 10 Go Best Practices Every Backend Developer Should Know

Partner Resources

×

Comments

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

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

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 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook