Skip to content

Modernize library for 4.x: security fixes, strict types, tooling updates#25

Merged
grasmash merged 1 commit into
4.xfrom
modernize-4x
Jun 11, 2026
Merged

Modernize library for 4.x: security fixes, strict types, tooling updates#25
grasmash merged 1 commit into
4.xfrom
modernize-4x

Conversation

@grasmash

Copy link
Copy Markdown
Owner

Summary

Multi-dimension review and modernization of the library for the 4.x major version. 55 candidate findings were adversarially verified; the 35 confirmed ones are fixed here, each behavior change developed test-first.

Bug and security fixes (each with a regression test)

  • Memory-exhaustion DoS: circular references with surrounding text (['a' => 'x${b}', 'b' => 'y${a}']) doubled the value length every pass until the process crashed. Expansion is now capped at 25 passes / 1 MiB.
  • ${env.*} no longer reads HTTP_* keys from $_SERVER — in a web context those come from client-supplied request headers (Symfony precedent).
  • Falsy env vars expand: VAR=0 previously failed a truthiness check on getenv().
  • Type preservation in reference mode: expandPropertyWithReferenceData() declared ?string, silently coercing booleans to "1" and numerics to strings. Now returns mixed.
  • Single-placeholder strings expanded twice, duplicating logger/stringifier side effects. Now expanded once.
  • PCRE error guard: a preg_replace_callback() failure now restores the original value instead of nulling it.

Modernization (BC breaks documented in RELEASE.md)

  • declare(strict_types=1) and full parameter/return types everywhere.
  • StringifierInterface::stringifyArray() is now an instance method.
  • expandArrayProperties() requires array $reference_array.

Tooling and CI

  • PHPUnit ^9^10.5 || ^11 || ^12 || ^13; config migrated (the old config silently ran zero tests under PHPUnit 13), tests converted to attributes with static providers, env-var fixtures cleaned up in tearDown().
  • phpstan level 5 added to composer test.
  • Dropped abandoned greg-1-anderson/composer-test-scenarios.
  • CI now triggers on main and *.x (pushes to 4.x previously never ran CI), adds PHP 8.5 to the matrix, a composer audit step, checkout@v6, and Dependabot for composer + GitHub Actions.
  • 100% line/method/class coverage (16 tests, 52 assertions, was 3/15).
  • Fixed README example syntax error, malformed .gitignore last line, stale RELEASE.md script references; added .editorconfig and composer metadata.

Test plan

  • composer test (lint + PHPUnit + phpcs + phpstan) passes locally on PHP 8.4
  • Coverage at 100% lines/methods/classes via pcov (same driver as CI)
  • README example verified end-to-end
  • CI matrix (PHP 8.2/8.3/8.4/8.5) green on this PR

🤖 Generated with Claude Code

Bug and security fixes (each with a regression test):
- Cap placeholder expansion at 25 passes / 1 MiB to prevent memory
  exhaustion from circular references with surrounding text
- Ignore HTTP_* keys in $_SERVER for ${env.*} expansion, since those
  originate from client-supplied request headers in a web context
- Expand falsy environment variables (e.g. VAR=0) correctly by checking
  getenv() against false instead of truthiness
- Preserve non-string types (bool, int, float) when expanding via
  reference data; expandPropertyWithReferenceData() now returns mixed
- Expand single-placeholder strings once instead of twice, eliminating
  duplicate logger/stringifier side effects
- Restore the original value if preg_replace_callback() fails

Modernization (BC breaks documented in RELEASE.md):
- Add declare(strict_types=1) and full type declarations everywhere
- Make StringifierInterface::stringifyArray() an instance method
- Require array type for expandArrayProperties() $reference_array

Tooling and CI:
- Update PHPUnit ^9 to ^10.5 || ^11 || ^12 || ^13; migrate config and
  convert tests to attributes with static data providers
- Add phpstan (level 5) to require-dev and the composer test script
- Drop abandoned greg-1-anderson/composer-test-scenarios
- Run CI on main and *.x branches; add PHP 8.5 to the matrix, a
  composer audit step, checkout@v6, and Dependabot config
- Reach 100% line/method/class coverage; clean up env-var fixtures
  between tests
- Fix README example syntax error, .gitignore malformed line, stale
  RELEASE.md script references; add .editorconfig and composer metadata

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@grasmash grasmash merged commit b29dda9 into 4.x Jun 11, 2026
4 checks passed
@grasmash grasmash deleted the modernize-4x branch June 11, 2026 12:49
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