As the long title says.
I made an API to call from a Vue.js application with Spring Boot,
It was decided to load test the API.
I use JMeter to create a scenario, but since I am using CSRF measures using CookieCsrfTokenRepository of Spring Security.
XSRF-TOKEN cookie as a CSRF tokenX-XSRF-TOKEN header when calling an API using POSTThat's why we needed to do that in the scenario.
Only the image looks like this.
| url | HTTP method | Overview |
|---|---|---|
| /login | POST | ID/Send Password to log in Upon successful login XSRF-TOKENCookies are givenNot subject to CSRF check |
| /orders | POST | Register an order CSRF check target |
The / login response will contain the XSRF-TOKEN cookie, so we will extract it.
For the time being, looking at the response of / login with DevTools, it looks like this.

Calls to / login are defined in the HTTP Request sampler. (Details omitted)
After running this sampler, use regular expression extraction to get a CSRF token.
HTTP Request sampler in / login and right-click → Post Processors→Regular Expression Extractor`
Is that the point?
In subsequent scenarios, you can specify $ {xsrf_token} to resolve the extracted value from a variable.
Since / orders is subject to CSRF checking, it is necessary to set the X-XSRF-TOKEN header at the time of calling.
Calls to / orders are defined in the HTTP Request sampler. (Details omitted)
When running this sampler, use the HTTP Header Manager to set the X-XSRF-TOKEN header.
HTTP Request sampler in / orders and right-click → Config Element→HTTP Header Manager`
The $ {xsrf_token} obtained earlier is set as the X-XSRF-TOKEN header.
With the above settings, you can pass the CSRF measures. If you're new to JMeter, you can't immediately think of such a small application. I thought it would be annoying (it's my unfamiliar experience), so I wrote it down.
I referred to the following. Thank you very much.
https://www.blazemeter.com/blog/how-load-test-csrf-protected-web-sites
Recommended Posts