Skip to content

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

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

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

Conversation

@loevgaard

Copy link
Copy Markdown
Member

Summary

The 2.x counterpart of #26. PHP url-decodes cookie values, so a client cookie holding %FF gives a client id with a byte that isn't UTF-8. That breaks the bundle's metadata column, and any application table that stores the client id. ClientCookieJar::isValid() now requires UTF-8 next to the existing rules, so the rule applies on both sides:

 ClientCookieJar::isValid(clientId)
   not empty
   at most 255 bytes
+  valid UTF-8          // preg_match('//u'), no ext-mbstring needed

 read()   invalid → no cookie → the visitor gets a new client id
 write()  invalid → LogicException ("must be a non-empty UTF-8 string of at most 255 bytes")

README, UPGRADE-2.0.md and CLAUDE.md state the rule with UTF-8.

Evidence

  • Before: with the src/ change stashed, these fail:
    ClientCookieJarTest::it_reads_nothing_when_the_client_id_is_not_utf8
    ClientCookieJarTest::it_refuses_to_write_a_client_id_that_is_not_utf8
    ClientCookieTest::it_treats_a_visitor_whose_client_id_is_not_utf8_as_a_new_visitor
    ClientCookieJarTest::it_refuses_to_write_an_empty_client_id            (message now says UTF-8)
    DecoratedClientContextTest::it_refuses_to_store_a_current_client_id_that_is_not_valid  (same)
    
    After: all pass, and client-id-ø is still read.
  • Full suite on PHP 8.4: 125 tests OK. PHPStan, ECS and composer-dependency-analyser are clean. Infection: 111 of 111 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 with such a cookie gets a new client id. An application whose client context decorator returns an id that isn't UTF-8 now gets a LogicException when the cookie is stored, like an empty id or one over 255 bytes already does on 2.x.

PHP url-decodes cookie values, so a cookie holding %FF gives a client id with a byte that isn't UTF-8, which the database rejects like a client id over 255 bytes. ClientCookieJar now treats such a client id as invalid: read() ignores the cookie, so the visitor gets a new client id, and write() refuses to store one that a decorated client context returns.
@loevgaard
loevgaard merged commit 15065f2 into 2.x Nov 23, 2026
19 checks passed
@loevgaard
loevgaard deleted the utf8-client-id-2.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