Review main Abandoned

94795[TASK] Use Symfony IpUtils for IP matching in GeneralUtility

Georg Ringer CR -1 V +1 Normal +6 −47 updated 08/16/26, 08:48

Commit message

The hand-rolled IPv4/IPv6 matching in GeneralUtility::cmpIPv4() and
cmpIPv6() is replaced by Symfony\Component\HttpFoundation\IpUtils, a
hard Core dependency providing well-tested equivalents. cmpIPv6() now
delegates to IpUtils::checkIp6() and the cmpIPv4() CIDR branch to
IpUtils::checkIp4(). The TYPO3-specific IPv4 wildcard syntax
("192.168.*.*" and the shortened form) is kept, as IpUtils does not
support it.

The public API and behavior stay unchanged.

Review

  • Code review CR -1
    • Stefan Bürk -1
    • Josua Vogel +1
    • Joschua Ngo +1
    • Ravi Sachaniya +1
    • Benni Mack +1
  • Verified V +1
    • Josua Vogel +1
    • Joschua Ngo +1
    • Ravi Sachaniya +1
    • Benni Mack +1
    • core-ci +1 CI

Issues 1

Files 1

Review log 1314

  1. Georg Ringer uploaded patch set 1 07/15/26, 20:44

  2. core-ci voted on patch set 1 V +1 07/15/26, 20:55 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/104808

  3. Georg Ringer commented on patch set 1 07/15/26, 21:40

    This change is ready for review.
  4. Benni Mack voted on patch set 1 CR +1 V +1 07/16/26, 09:35

  5. Ayke Halder commented on patch set 1 07/20/26, 17:26

    GeneralUtility.php:148

    ```suggestion if (str_contains($test, '/')) { // "192.168.3.0/24" $yes = IpUtils::checkIp4($baseIP, $test); } else { ``` Does this simplification still cover all cases?
  6. Ayke Halder commented on patch set 1 07/20/26, 17:31

    GeneralUtility.php:148 Reply

    Or implement an inverse logic: ``` if (str_contains($test, '*')) { // "192.168.*.*" $IPparts = explode('.', $test); […] } else { // "192.168.0.123" // "192.168.3.0/24" $yes = IpUtils::checkIp4($baseIP, $test); } ```
  7. Georg Ringer commented on patch set 1 08/05/26, 10:12

    GeneralUtility.php:148 Reply

    Thanks for the suggestions! I tried both, but kept the current logic on purpose — both variants change behavior for some inputs: str_contains($test, '/') variant: degenerate masks are no longer caught by the wildcard branch and go straight to IpUtils. Behavior changes, e.g.: - 9.9.9.9 vs 1.2.3.4/0 → now true (Symfony treats /0 as match-all), was false (exact match only) - 1.2.3.4/ and 1.2.3.4/abc → now false, were true Inverse *-check variant: this breaks the shortened form, which has no *: - 192.168.1.1 vs 192.168 → would go to IpUtils::checkIp4($ip, '192.168'), where ip2long('192.168') fails → always false Since this is a behavior-preserving [TASK], I'd rather keep the wildcard/shortened-form handling exactly as it is.
  8. Ayke Halder commented on patch set 1 08/05/26, 16:33

    GeneralUtility.php:148 Reply

    Thank you for looking into this. * About str_contains($test, '/') variant: Acknowledged. * About inverse-check and shortened form "192.168": The shortended form with missing dots currently returns always false: ```php $IPpartsReq = explode('.', $baseIP); if (count($IPpartsReq) === 4) { […] } return false; ```
  9. Ayke Halder commented on patch set 1 08/05/26, 16:45

    GeneralUtility.php:148 Reply

    Sorry, this was all about the baseIP … so everything is fine.
  10. Josua Vogel voted on patch set 1 CR +1 V +1 08/06/26, 05:05

  11. Ravi Sachaniya voted on patch set 1 CR +1 V +1 08/06/26, 05:43

  12. Joschua Ngo voted on patch set 1 CR +1 V +1 08/06/26, 19:07

  13. Stefan Bürk commented on patch set 1 CR -1 08/15/26, 18:07

    Unresolved

    Thanks for tackling this - replacing the hand-rolled bit fiddling with IpUtils is the right direction, and I like that the wildcard/shortened-form handling and the full unit-test data providers are kept untouched. I ran the pre- and post-patch implementations side by side over ~100 (address, list) pairs. Everything that is a well-formed configuration is identical: all CIDR cases, 192.168.*.*, 192.168.*, 192.*, the bare 192.168 prefix, '*', '', whitespace in lists, mixed v4/v6 lists, IPv6 case and zero-compression variants, /0, zone ids, leading-zero octets. 17 pairs do change, though, so "The public API and behavior stay unchanged" in the commit message does not hold. 1) IPv6 netmask is not normalized, IPv4 is. The v4 branch passes $test . '/' . (int)$mask, the v6 branch passes $test raw. Symfony compares the netmask as a string against integers, so "64abc" > "128" is a string comparison and checkIp6() bails out: 2001:db8::1 vs 2001:db8::1/ true -> false 2001:db8::1 vs 2001:db8::1/abc true -> false 2001:db8::1 vs 2001:db8::/64abc true -> false 2001:db8::1 vs 2001:db8::1/-1 true -> false while the identical v4 inputs keep working: 192.168.1.1 vs 192.168.1.1/abc true -> true 192.168.1.1 vs 192.168.1.1/24abc true -> true Same malformed input, opposite result depending on address family. Since you rejected Ayke's str_contains('/') variant in this very thread precisely because it broke 1.2.3.4/ and 1.2.3.4/abc, I assume this is an oversight rather than a decision. 2) Out-of-range masks: the old code clamped, the new one rejects. 192.168.1.1 vs 192.168.1.1/33 true -> false (substr(..., 0, 33) degraded to /32) 2001:db8::1 vs 2001:db8::1/129 true -> false (the old path also emitted a PHP 8.5 deprecation via ord(''), so rejecting is arguably better) 3) Two genuine fixes I would keep, but which are behaviour changes and belong in a changelog: 0.0.0.1 vs garbage/8 true -> false ((int)ip2long('garbage') === 0, i.e. a typo in devIPmask used to mean 0.0.0.0/8) 999.999.999.999 vs 0.0.0.0/8 true -> false (same defect on the base-IP side) ::ffff:192.168.1.1 vs ::ffff:c0a8:101 false -> true (the old exact-match branch compared the normalizeIPv6() string, so two spellings of one address did not match) Note the last one is the only case that becomes more permissive. Direction matters here: cmpIP() gates [SYS][devIPmask], [BE][IPmaskList] (LockedBackendGuard), [SYS][reverseProxyIP] (NormalizedParams, i.e. whether X-Forwarded-For is trusted), the rate limiter and the TypoScript ip() condition. All of 1) and 2) fail closed - a previously working mask silently stops matching, which for IPmaskList means a backend lockout and for reverseProxyIP means a proxy silently stops being trusted. Suggestion: normalize the mask in both branches, which removes 6 of the 17 divergences outright and brings the rest down to one accidental case - in cmpIPv4 pass min(max((int)$mask, 1), 32), and in cmpIPv6 split $test on '/', validate the address part, return true early for mask '0', and pass min((int)$mask ?: 128, 128). Whatever divergence you decide to keep after that, please add: * a changelog entry (Important-110203-*.rst under Documentation/Changelog/15.0/, or Breaking plus [!!!] if you prefer to keep the current strictness), and * data-provider rows pinning the new semantics - /33, /129, /abc, /64abc, garbage/8, ::ffff:c0a8:101, 192.168.1.1/24abc. None of the existing 33 rows touches any of the changed paths, which is why CI is green; without them the suite also cannot catch a future Symfony change. Two smaller things: * IpUtils::checkIp6() throws \RuntimeException when PHP is built with --disable-ipv6, where cmpIPv6() previously returned false. Practically unreachable, but worth a line in the commit message. * normalizeIPv6() loses its last production caller with this patch - a nice follow-up for a v15 deprecation, please not in this change. * Subject is 53 chars after the tag (limit 52); "[TASK] Use Symfony IpUtils for IP matching" fits. Nothing here questions the approach - with the mask normalization, a changelog and the extra test rows I would be happy to +1 this. Verified: leaving core-ci's +1, CI is genuinely green, which is exactly the problem.

    GeneralUtility.php:148 Reply Unresolved

    This thread turns out to be the crux of my -1, so following up here rather than only at patchset level. You rejected the str_contains($test, '/') variant because it broke 1.2.3.4/ and 1.2.3.4/abc - which is the right call. But the committed cmpIPv6() has exactly that defect anyway, just on the other address family: it passes $test to IpUtils::checkIp6() unsplit and unnormalized, while cmpIPv4() passes $test . '/' . (int)$mask. Symfony then compares the netmask as a string, so "64abc" > "128" is a string comparison and checkIp6() returns false. Measured against the pre-patch implementation: 2001:db8::1 vs 2001:db8::1/ true -> false 2001:db8::1 vs 2001:db8::1/abc true -> false 2001:db8::1 vs 2001:db8::/64abc true -> false while 192.168.1.1 vs 192.168.1.1/abc still returns true. So the same malformed mask is tolerated for IPv4 and rejected for IPv6. Casting in the v6 branch too - split on '/', then min((int)$mask ?: 128, 128) - restores symmetry and keeps the fail-closed direction from silently locking someone out of the backend via [BE][IPmaskList].
  14. Georg Ringer abandoned the change 08/16/26, 08:48