VOOZH about

URL: https://dzone.com/articles/test-group

โ‡ฑ How to Handle the CSRF Token in JMeter


Related

  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 May. 09, 17 ยท Tutorial
Likes
Comment
Save
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 expressionname="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.

Let's be friends: