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
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • 13 Impressive Ways To Improve the Developer’s Experience by Using AI
  • Tactics and Strategies on Software Development: How To Reach Successful Software [Video]
  • Exploring the Capabilities of eBPF
  • Designing a New Framework for Ephemeral Resources

Trending

  • 13 Impressive Ways To Improve the Developer’s Experience by Using AI
  • Tactics and Strategies on Software Development: How To Reach Successful Software [Video]
  • Exploring the Capabilities of eBPF
  • Designing a New Framework for Ephemeral Resources
  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.

manoj mathpal user avatar by
manoj mathpal
·
May. 09, 17 · Tutorial
Like (15)
Save
Tweet
Share
33.63K 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.

Trending

  • 13 Impressive Ways To Improve the Developer’s Experience by Using AI
  • Tactics and Strategies on Software Development: How To Reach Successful Software [Video]
  • Exploring the Capabilities of eBPF
  • Designing a New Framework for Ephemeral Resources

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

Let's be friends: