diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/HC4CookieHandler.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/HC4CookieHandler.java
index 990b33ecca0..276d9134a31 100644
--- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/HC4CookieHandler.java
+++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/HC4CookieHandler.java
@@ -18,6 +18,7 @@
package org.apache.jmeter.protocol.http.control;
import java.net.URL;
+import java.time.Instant;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -228,7 +229,14 @@ List getCookiesForUrl(
CookieOrigin cookieOrigin = new CookieOrigin(host, port, path, secure);
List cookiesValid = new ArrayList<>();
+ // #6428 Cookies must not be sent after they reached their expiry time.
+ // The cookie specs used here do not check the expiry date in match(),
+ // so expired cookies have to be filtered out explicitly.
+ Date now = Date.from(Instant.now());
for (org.apache.http.cookie.Cookie cookie : cookies) {
+ if (cookie.isExpired(now)) {
+ continue;
+ }
if (cookieSpec.match(cookie, cookieOrigin)) {
cookiesValid.add(cookie);
}
diff --git a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestHC4CookieManager.java b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestHC4CookieManager.java
index 8b242540a47..14bd09959b2 100644
--- a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestHC4CookieManager.java
+++ b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestHC4CookieManager.java
@@ -259,6 +259,27 @@ public void testOldCookie() throws Exception {
assertNull(s);
}
+ // Test cookie that was valid when received is not sent anymore
+ // once its expiry time has passed (#6428)
+ @Test
+ public void testCookieExpiredAfterReceptionIsNotSent() throws Exception {
+ URL url = new URL("http://a.b.c/");
+ man.addCookieFromHeader("test=1; expires=Wed, 01-Jan-2099 00:00:00 GMT", url);
+ assertEquals(1, man.getCookieCount());
+ assertEquals("test=1", man.getCookieHeaderForURL(url));
+ // Simulate the passing of time: the cookie is expired by now
+ man.get(0).setExpires(System.currentTimeMillis() / 1000L - 3600L);
+ assertNull(man.getCookieHeaderForURL(url), "expired cookie must not be sent");
+ }
+
+ // Test session cookie (no expiry date) is still sent
+ @Test
+ public void testSessionCookieWithoutExpiryIsStillSent() throws Exception {
+ URL url = new URL("http://a.b.c/");
+ man.addCookieFromHeader("test=1", url);
+ assertEquals("test=1", man.getCookieHeaderForURL(url));
+ }
+
// Test New cookie is returned
@Test
public void testNewCookie() throws Exception {
diff --git a/xdocs/changes.xml b/xdocs/changes.xml
index 13e0d097e6d..b96031cd69c 100644
--- a/xdocs/changes.xml
+++ b/xdocs/changes.xml
@@ -58,9 +58,20 @@ Summary
+
+
+Incompatible changes
+
+ - 6428HTTP Cookie Manager no longer sends cookies after they reached their expiry time.
+ Previously, expired cookies kept being sent indefinitely. Long-running tests that outlive a cookie's
+ expiry time may experience authentication or session failures and must handle re-authentication
+ or session refresh.
+
+
Changes
General
diff --git a/xdocs/usermanual/component_reference.xml b/xdocs/usermanual/component_reference.xml
index 663b24fe6e4..783051d8bb1 100644
--- a/xdocs/usermanual/component_reference.xml
+++ b/xdocs/usermanual/component_reference.xml
@@ -3847,6 +3847,12 @@ This means that cross-domain cookies are not stored.
If you have bugged behaviour or want Cross-Domain cookies to be used, define the JMeter property "CookieManager.check.cookies=false".
+Cookies that reached their expiry time are no longer sent with requests.
+Be aware that long-running tests, such as endurance tests that outlive a cookie's expiry time,
+will no longer send the cookie once it has expired. This can lead to authentication or session
+errors, so such test plans must handle re-authentication or session refresh.
+
+
Received Cookies can be stored as JMeter thread variables.
To save cookies as variables, define the property "CookieManager.save.cookies=true".
Also, cookies names are prefixed with "COOKIE_" before they are stored (this avoids accidental corruption of local variables)