Only accept a positive integer as the partner id - #59
Merged
Conversation
The affiliate query parameter was cast to int without validation, so an empty or mangled value (a tracker rewriting the link) set the cookie to partner id 0, overwriting a legitimate attribution, and an array value (?paid[]=x) made InputBag::get() throw, turning any shop URL into a 400. The cookie value had the same leniency. A raw value is now only a partner id if it is a positive integer; the cookie handler treats anything else as absent, and the subscriber reads the raw value so arrays cannot throw. Fixes #51 Claude-Session: https://claude.ai/code/session_01Mt12J8vdGwwWg4V23uoEf9
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 3.x #59 +/- ##
============================================
+ Coverage 84.79% 84.90% +0.11%
- Complexity 104 106 +2
============================================
Files 21 22 +1
Lines 546 550 +4
============================================
+ Hits 463 467 +4
Misses 83 83 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Fixes #51.
What changed
PartnerIdParser::parse()(new,src/Parser) is the single place that turns a raw request value into a partner id: a positive integer, ornullfor anything else — empty, garbage, zero, negative, decimals, arrays. Usesfilter_var(FILTER_VALIDATE_INT, min_range 1), so no casts.SetCookieSubscribervalidates the affiliate query parameter through it and reads the raw value viaquery->all()instead ofquery->get(), so?paid[]=xno longer makesInputBag::get()throw aBadRequestException(a 400 for the whole page). A mangled affiliate link now simply sets no cookie — and, importantly, no longer overwrites a legitimate earlier attribution with partner id 0.CookieHandler:has()is now onlytruewhen the cookie holds a valid partner id;get()asserts the same contract (interface docblocks updated). A tampered cookie is treated as absent.CreateConversionSubscriber: thepartnerId <= 0guard is gone — the cookie handler now guarantees a valid id, so it was dead code.Tests
PartnerIdParserTest(data provider over valid/invalid inputs).SetCookieSubscriberTestandCookieHandlerTestgained data-provider cases for empty, garbage, zero, negative, decimal and array values, asserting no cookie is set and nothing throws.Note: this tightens
CookieHandlerInterface::has()semantics (a cookie with an invalid value now counts as absent) — deliberate, and in line with the major bump already on3.x.