SameSite cookies in JMeter - jmeter

I'm developing a JMeter test for a site that requires "SameSite by default cookies" to be Disabled in Chrome, as shown here:
Turn off samesite enforcement in chrome version > 80
The site I'm testing just returns HTML pages; it does not have a separate API layer. The main element causing issues is a third-party component embedded in an iframe. The iframe content uses SSO to authenticate with the main site. In Chrome, if the SameSite setting is set to Default, I get a login page for the third-party component, rather than seeing the component render. If the SameSite setting is set to Disabled, then the third-party component renders correctly.
When I execute my test in JMeter, I'm encountering the same issue that I encounter in Chrome when "SameSite by default cookies" is set to Default--specifically, I get redirected to a login page.
However, when I execute the same sequence of HTTP requests in Postman, everything works fine.
Does JMeter have some SameSite cookie behavior built-in, and if so, how do I disable it?
UPDATE: following Dmitri's suggestion, I tried all the different cookie managers.
I also enabled cookie manager logging. If I set HTTP Cookie Manager's Cookie Policy to default, the "expires" attribute on the cookies causes an error:
2020-03-27 12:56:58,613 ERROR o.a.j.p.h.c.HC4CookieHandler: Unable to add the cookie
org.apache.http.cookie.MalformedCookieException: Invalid 'expires' attribute: Fri, 03 Apr 2020 17:56:54 GMT
at org.apache.http.impl.cookie.BasicExpiresHandler.parse(BasicExpiresHandler.java:64) ~[httpclient-4.5.10.jar:4.5.10]
at org.apache.http.impl.cookie.CookieSpecBase.parse(CookieSpecBase.java:113) ~[httpclient-4.5.10.jar:4.5.10]
at org.apache.http.impl.cookie.DefaultCookieSpec.parse(DefaultCookieSpec.java:140) ~[httpclient-4.5.10.jar:4.5.10]
at org.apache.jmeter.protocol.http.control.HC4CookieHandler.addCookieFromHeader(HC4CookieHandler.java:124) [ApacheJMeter_http.jar:5.2.1]
...
If I set the Cookie Policy to standard--"The RFC 6265 compliant policy (interoprability profile)" per HTTPClient docs--I don't see any cookie error messages in the log, but I'm still getting redirected to a login page.

If the application you're testing sends malformed cookies in Set-Cookie header JMeter might reject the cookies which don't match current domain of the HTTP Request sampler or expired or invalid by any other reason.
You can "tell" JMeter to be less restrictive by:
Choosing more "relaxed" cookie policy, i.e. netscape in the HTTP Cookie Manager
Add CookieManager.check.cookies=true line to user.properties file (JMeter restart will be required to pick the property up)
More information: HTTP Cookie Manager Advanced Usage - A Guide
If above steps don't help you can:
Increase JMeter logging verbosity for the HTTP Cookie Manager and friends by adding the next line to log4j2.xml file:
<Logger name="org.apache.jmeter.protocol.http.control" level="debug" />
and last but not the least, you can always extract cookies from the aforementioned Set-Cookie header using i.e. Regular Expression Extractor and manually add them the next request using HTTP Header Manager

Related

HTTP cookie manager not working in jmeter

I have placed cookie manager above the thread group.I have extracted cookie value from sampler request(request1) using regex extractor.I have placed cookie manager with extracted cookie values under the sampler(request2).
When i replayed the script the cookie is not set for request2.It shows no cookies.
NOTE:
When I removed the cookie manager placed above the thread group I am getting errors in samplers.
I have placed cookie manager above the thread group.I have extracted cookie value from sampler request(request1) using regex extractor.I have placed cookie manager with extracted cookie values under the sampler(request2).
When i replayed the script the cookie is not set for request2.It shows no cookies.
NOTE:
When I removed the cookie manager placed above the thread group I am getting errors in samplers.
HTTP Cookie Manager handles incoming cookies automatically, it:
Extracts the cookies from the Set-Cookie response header
On subsequent requests if domain and path of the request matches the ones of the cookie(s) the cookie is being added to the request's Cookie header
So there is no need to use any post processors for extracting the cookies.
If the cookie manager is "not working" most probably there is a problem with the cookie, i.e. it's expired or domain of the request is different or something like this. If you want to see what's going on under the hood you can increase JMeter logging verbosity for the cookie manager by adding the next line to log4j2.xml file:
<Logger name="org.apache.jmeter.protocol.http.control" level="debug" />
if there are issues with cookies and JMeter is unwilling to add the cookie you can force it by
Choosing less restrictive policy, i.e. netscape
Adding the next line to user.properties file:
CookieManager.check.cookies=false
More information: HTTP Cookie Manager Advanced Usage - A Guide

unable to add cookie in jmeter

Below is the cookie which i generated in my postman,
CAKEPHP=4c0nshbqn0vnsn92665dt23lsrpns; Path=/; Domain=.devappium.bizom.in; Secure; HttpOnly; Expires=Sun, 02 May 2021 13:58:52 GMT;
I have added the same in http cookie manager but still it is not working.Let me know whether is there anything wrong in my configuration
Cookie name is CAKEPHP and should check also Secure
Normally you should not be manually adding cookies, JMeter's HTTP Cookie Manager automatically extracts the cookies from the server's response Set-Cookie header and stores them internally in the HTTP Cookie manager (given the cookies are valid)
Then when you make a next request the HTTP Cookie Manager checks domain and path and if there is a match - it adds the cookie to the request by generating appropriate Cookie header
The same applies to manually added cookies, if you cannot see the cookie being added to the request you can:
check the domain and path
you can turn off JMeter's cookie verification logic by choosing a less restrictive implementation, i.e. netscape
there is also a property which completely turns off cookies verification, if you add the next line to user.properties file:
CookieManager.check.cookies=false
this way JMeter will store each and every incoming cookie
and last but not the least you can increase JMeter's logging verbosity for the HTTP Cookie Manager by adding the following line to log4j2.xml file:
<Logger name="org.apache.jmeter.protocol.http.control" level="debug" />
finally you can always add a HTTP Header Manager and configure it to send the Cookie header with the value you're using in Postman

iframe refused to connect while using XAMPP and Laravel

I am developing a Laravel application and have added an iframe as follows:
The iframe does not connect and simply says www.google.com refused to connect. I have done some research and it appears this related to X-Frame-Options being set. Within the Chrome Browser Developer Tools, I see the following error message:
A cookie associated with a cross-site resource at https://www.google.com/ was set without the SameSite attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with SameSite=None and Secure. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.
My guess is this is a setting that needs to be changed at the XAMPP server level within Apache but I cannot figure out where. Any ideas?
If you are testing on localhost and you have no control of the response headers, you can disable it with a chrome flag.
open this URL :
chrome://flags/#same-site-by-default-cookies
and disable SameSite by default cookies
SameSite prevents the browser from sending the cookie along with cross-site requests.
if you don't want to disable SameSite by default cookies you can add response header before sending back response to resolve this:
return response($content)
->header("Set-Cookie", "HttpOnly;Secure;SameSite=Strict");

JMeter - I need to pass a parameter called "Cookie" in the request header

I am using apache jmeter 5.2.1 with Java 8 to perform the performance test in a JSF application.
I need to send in the header of an HTTP request a parameter called "Cookie" according to the example below:
I've tried several things but none work.
I have already used the HttpHeaderManager resource but apparently the word "Cookie" is a JMeter reserved word so I can't create a parameter in the Header with the name "Cookie".
If I create a parameter in HttpHeaderManager with any name it is appended to the request header, but if I create with the name "Cookie" which is the name I need to use JMeter simply ignore it and do not add it to the request header .
I saw many posts indicating that I used the following code snippet:
CookieManager manager = sampler.getCookieManager();
Cookie cookie = new Cookie("JSESSIONID",vars.get("jSessionId"),"${serveraddress}",false,0);
manager.add(cookie);
I've tested it but it doesn't work either, it returns the following error whenever I try to use it:
I also have an Http Cookie Manager but its value is sent in the request body and not in the header.
I also tried to use the Http Autorization Manager as I saw in some posts but it only works when the login is done at a prompt in the browser.
Can someone help me?
Just add a HTTP Cookie Manager to your Test Plan and it will automatically "manage" cookies for you (the HTTP Request samplers must be in the HTTP Cookie Manager's scope)
You can double check that JMeter sends correct Cookie header using a 3rd-party sniffer tool like Wireshark or Fiddler
If you added the HTTP Cookie Manager but JMeter still doesn't send the JSESSIONID cookie it might be the case there is a problem with the cookie itself, i.e. it doesn't match domain/path or expired or your HTTP Request sampler configuration is not correct.
If you absolutely sure that your application behaves as expected you can configure JMeter to be less restrictive by:
Choosing a more "relaxed" cookie policy, i.e. netscape
Adding the next line to user.properties file:
CookieManager.check.cookies=false
You can also add the next line to log4j2.xml file:
<Logger name="org.apache.jmeter.protocol.http.control" level="debug" />
this way you will get comprehensive information of the Cookie Manager's behaviour in the jmeter.log file
More information: HTTP Cookie Manager Advanced Usage - A Guide

Append cookies and sending to next request using cookie manager in jmeter

I am doing load test for my application. For login i am getting set-cookie in response headers. Is it possible to append all cookies using cookie manager and sending it in request header for another request
Just add cookie manager to you thread group.
Jmeter will automatically transfer the cookies to the further request correspondingly
Add HTTP Cookie Manager to your Thread Group, it should handle cookies automatically.
If it doesn't pick up all the cookies, there should be an issue with one or more cookies, i.e. Domain or Path mismatch or expiration date is in the past or whatever. If this is the case and you still want JMeter to consider the invalid cookies you can try adding the next line to user.properties file (located in JMeter's "bin" folder)
CookieManager.check.cookies=false
Given this property set to false JMeter won't check cookies before storing them and you should see "missing" ones, however I would recommend raising a defect against your application as the fact you are not seeing the cookies added by the HTTP Cookie Manager indicates that something is wrong with them

Resources