Don't send cookies after they reached their expiry time - #6756
Open
ashrafiucse wants to merge 2 commits into
Open
Don't send cookies after they reached their expiry time#6756ashrafiucse wants to merge 2 commits into
ashrafiucse wants to merge 2 commits into
Conversation
The cookie specs used by the HTTP Cookie Manager do not check the expiry date when matching cookies for an URL, so cookies that were valid when they were received kept being sent after they expired. Filter expired cookies in HC4CookieHandler#getCookiesForUrl, so they are not sent anymore. Session cookies, which have no expiry date, are not affected. Closes apache#6428
Contributor
|
@ashrafiucse Thanks for the fix (or new behavior?). The code change looks correct. But before merge: this changes affect a long-standing runtime behavior: JMeter has been sending expired cookies for years. Some test plans may rely on that, even without knowing it. This is especially true for long-running endurance This PR will be release with the next major release of JMeter (i.e. 6.0.0), so please improve the PR with:
Thanks |
Per review feedback on PR apache#6756: move the changes.xml entry from Bug fixes to a new Incompatible changes section and document the behavior change in the HTTP Cookie Manager reference, warning about the impact on long-running tests that outlive a cookie's expiry.
Author
|
Hi @milamberspace, thanks for the review! I've addressed both points in 29753f3:
|
ashrafiucse
force-pushed
the
fix/jmeter-6428-cookie-expiry
branch
from
September 1, 2026 11:13
da89807 to
29753f3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Skip cookies that have reached their expiry time when the
HTTP Cookie Managerbuilds theCookieheader for a request.HC4CookieHandler#getCookiesForUrlnow filters out expired cookies (viacookie.isExpired(...)) in addition to the existing domain/path/secure matching. Session cookies, which have no expiry date, are unaffected.Motivation and Context
Fixes #6428
Cookies that were valid when they were received kept being sent after their expiry time had passed:
HTTP Cookie Manager(with "Clear cookies each iteration?" unchecked)Expires/Max-Ageattribute in the past's future (e.g.Set-Cookie: session_id=abc123; Expires=<now + 60s>; Path=/)Root cause: the expiry date is only checked once, when the
Set-Cookieheader is parsed (addCookieFromHeader). The send path (getCookiesForUrl) filters cookies withcookieSpec.match(...), which matches on domain/path/secure only and never checksisExpired, so a cookie that was valid at reception time is sent forever.How Has This Been Tested?
TestHC4CookieManager:testCookieExpiredAfterReceptionIsNotSent: receives a valid cookie (future expiry), simulates the passing of time by moving the stored cookie's expiry into the past, and assertsgetCookieHeaderForURLreturnsnulltestSessionCookieWithoutExpiryIsStillSent: guards the session-cookie case (no expiry date → still sent):src:protocol:http:testsuite passes (854 tests, 0 failures)./gradlew classes stylepassesTypes of changes
Checklist:
xdocs/changes.xml)