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

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

How does AI transform chaos engineering from an experiment into a critical capability? Learn how to effectively operationalize the chaos.

Data quality isn't just a technical issue: It impacts an organization's compliance, operational efficiency, and customer satisfaction.

Are you a front-end or full-stack developer frustrated by front-end distractions? Learn to move forward with tooling and clear boundaries.

Developer Experience: Demand to support engineering teams has risen, and there is a shift from traditional DevOps to workflow improvements.

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
  • Implementing DDoS With MuleSoft: Demonstration With Apache JMeter

Trending

  • Building a Simple Todo App With Model Context Protocol (MCP)
  • The Perfection Trap: Rethinking Parkinson's Law for Modern Engineering Teams
  • The End of “Good Enough Agile”
  • Evaluating the Evaluators: Building Reliable LLM-as-a-Judge Systems
  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
35.5K 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
  • Implementing DDoS With MuleSoft: Demonstration With Apache JMeter

Partner Resources

×

Comments

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
  • [email protected]

Let's be friends: