Skip to content

Only accept a positive integer as the partner id - #59

Merged
loevgaard merged 1 commit into
3.xfrom
fix-partner-id-validation
Aug 31, 2026
Merged

Only accept a positive integer as the partner id#59
loevgaard merged 1 commit into
3.xfrom
fix-partner-id-validation

Conversation

@loevgaard

Copy link
Copy Markdown
Member

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, or null for anything else — empty, garbage, zero, negative, decimals, arrays. Uses filter_var(FILTER_VALIDATE_INT, min_range 1), so no casts.
  • SetCookieSubscriber validates the affiliate query parameter through it and reads the raw value via query->all() instead of query->get(), so ?paid[]=x no longer makes InputBag::get() throw a BadRequestException (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 only true when the cookie holds a valid partner id; get() asserts the same contract (interface docblocks updated). A tampered cookie is treated as absent.
  • CreateConversionSubscriber: the partnerId <= 0 guard is gone — the cookie handler now guarantees a valid id, so it was dead code.

Tests

  • New PartnerIdParserTest (data provider over valid/invalid inputs).
  • SetCookieSubscriberTest and CookieHandlerTest gained data-provider cases for empty, garbage, zero, negative, decimal and array values, asserting no cookie is set and nothing throws.
  • Infection: 100% MSI on the changed files.

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 on 3.x.

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

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.90%. Comparing base (defc7a0) to head (4507884).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@loevgaard
loevgaard merged commit dc045ab into 3.x Aug 31, 2026
94 checks passed
@loevgaard
loevgaard deleted the fix-partner-id-validation branch August 31, 2026 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Query parameter 'paid' is not validated: garbage overwrites valid attribution, array input causes 400 on any shop URL

1 participant