Test the fbc/fbp parsing against Meta's own parameter builder - #23
Merged
Merged
Conversation
facebook/capi-param-builder-php is added as a dev dependency and used as a test oracle: every _fbc and _fbp value the builder writes must be parsed by Fbc/Fbp and written back byte for byte. The cases are a new fbc from an fbclid (including base64url click ids), a replaced fbc, a generated fbp, legacy cookies the builder upgrades with an appendix, cookies it passes through unchanged (every appendix kind and the six legacy language tokens), and hosts that yield different subdomain indexes. The check is deliberately one-directional, since the builder's own parser is only structural and accepts 'a.b.c.d'. The oracle found a gap straight away: for a deep host such as a.b.example.co.uk the builder writes fb.3., while the value objects only accepted a subdomain index of 0, 1 or 2 and rejected the cookie. The subdomain index is the number of dots in the cookie domain, so any non-negative index without a leading zero is now accepted. Dependabot also watches the new package, and the build workflow runs weekly: no composer.lock is committed, so a builder release inside the allowed range is only noticed when CI runs.
loevgaard
commented
Sep 21, 2026
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.
Summary
The bug behind #13 was drift: our regexes no longer matched what Meta writes into
_fbcand_fbp. Meta's ownfacebook/capi-param-builder-phpis the best machine-checkable statement of that format, so this PR adds it as a dev dependency and uses it as a test oracle. It is never used insrc/, so it adds nothing at runtime.The invariant
Everything the builder writes,
Fbc/Fbpparse and write back byte for byte.It is deliberately one-directional rather than "the same parsing". The builder's own parser is private and only structural; it accepts
a.b.c.das a valid cookie, so matching it would mean loosening the value objects. There is also one place where we are more lenient on purpose: as a two-character appendix the builder only accepts six language tokens, while the value objects accept any 2 to 8 characters, because that list can grow.ParamBuilderConformanceTestrunsprocessRequest()and feeds the results tofromString():fbcbuilt from anfbclid, including base64url click ids with-and_, asserting click id, subdomain index, creation time and appendixfbcthe builder replaces when thefbclidchangesfbp, 20 rounds per host because the random number varies in lengthlocalhostand an IP addressThe oracle found a bug straight away
For a deep host such as
a.b.example.co.ukthe builder writesfb.3.…, and the value objects only accepted a subdomain index of 0, 1 or 2, so they rejected a cookie Meta's own code produces. The index is the number of dots in the cookie domain; 0 to 2 are merely the examples Meta documents.Fixed in this PR, since shipping the tests with a hole cut around the case would defeat their purpose:
Fbc::fromString()/Fbp::fromString()accept0|[1-9]\d{0,2}: any index up to three digits, without a leading zero, so the value still round-trips byte for byte.Fb::withSubdomainIndex()accepts any non-negative integer. The threeSUBDOMAIN_INDEX_*constants stay, with a docblock explaining they are examples.This only relaxes validation, so it is not a BC break (Roave: none).
Dependabot
facebook/capi-param-builder-phpis added to theallowlist in.github/dependabot.yml. That covers a new major, where Dependabot widens the constraint and CI runs the conformance tests against it.A release inside
^1.3.1produces no Dependabot PR, because nocomposer.lockis committed. Thehighestjobs install it the next time CI runs, so a format change in a minor release is noticed at the next push or PR. An earlier revision of this PR added a weekly scheduled run to shorten that; it was dropped in review.Limits
Passing these tests proves agreement with Meta's PHP builder, not with the browser pixel script that writes most cookies in the wild.
Test plan
composer normalizegreen; Infection MSI 95 % / covered 95 %, no new escaped mutantsloweston PHP 8.1:php-business-sdk25.0.0 next to the builder 1.3.1, PHPUnit and PHPStan green