Skip to content

Reject a client id that isn't UTF-8 - #26

Merged
loevgaard merged 1 commit into
1.xfrom
utf8-client-id-1.x
Nov 23, 2026
Merged

loevgaard merged 1 commit into
1.xfrom
utf8-client-id-1.x

Conversation

@loevgaard

Copy link
Copy Markdown
Member

Summary

PHP url-decodes cookie values, so a setono_client_id cookie holding %FF gives a client id with a byte that isn't UTF-8. The provider now treats it like an empty client id or one over 255 bytes (#20): as no cookie, so the visitor gets a new client id and a new cookie.

 RequestBasedCookieProvider::getCookie()
   Cookie::fromString(value)
-  if client id is empty or over 255 bytes
+  if client id is empty, over 255 bytes or not UTF-8
     return null   // visitor gets a new client id

The check is preg_match('//u', …), so it needs no ext-mbstring.

Found by setono/sylius-conversion-attribution-plugin's architecture review. The plugin writes the client id to varchar(255) and JSON columns at checkout, so a hand-edited cookie gives a 500 at checkout. The bundle's own metadata clientId column rejects these bytes too. The same rule goes into 2.x's ClientCookieJar::isValid() in a separate PR. This should be in v1.2.1 (the draft release targets 1.x).

Evidence

  • Before: with the src/ change stashed, the new tests fail:
    1) RequestBasedCookieProviderTest::it_returns_null_when_the_client_id_is_not_utf8
    2) ClientCookieTest::it_treats_a_visitor_whose_client_id_is_not_utf8_as_a_new_visitor
    
    After: all pass. A client id like client-id-ø is still accepted.
  • Full suite on PHP 8.4: 108 tests OK. PHPStan, ECS and composer-dependency-analyser are clean. Infection: 93 of 93 mutants killed (MSI 100%). The CI matrix (8.1/8.2, lowest) wasn't run locally.

Merge Danger

Door: two-way

Blast Radius: small

A visitor whose cookie holds a client id that isn't UTF-8 gets a new client id, and their metadata row (if any) is no longer found. Such a cookie can't come from the bundle, which issues UUIDs, and the database couldn't store such a row anyway.

PHP url-decodes cookie values, so a cookie holding %FF gives a client id with a byte that isn't UTF-8. The database rejects it, like a client id over 255 characters, and an application that writes the client id to its own tables fails the request. The cookie provider now treats such a cookie as no cookie, so the visitor gets a new client id and a new cookie.
@loevgaard
loevgaard merged commit 1c2fb5c into 1.x Nov 23, 2026
19 checks passed
@loevgaard
loevgaard deleted the utf8-client-id-1.x branch November 23, 2026 09:12
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.

1 participant