Repository navigation
v0.9.0 — Security hardening: signed actions, session-bound snapshots, validated markup
Highlights
A security-hardening release. A server-side audit (issues #31, #37–#43, #49, #52, #53) and a client-script audit (#35) found that the browser could tamper with hook state, plant snapshots into other users' sessions, make the server execute arbitrary PHP functions through event props, and break out of tags via attribute names. All of them are fixed, the trust boundaries are documented, and the test suite now actually runs to completion.
⚠️ Breaking changes
- Actions are signed (#47). Every rendered action form carries
_usephp_action_sig, an HMAC over the instance id, the exact action JSON and the session id.doHandleAction()rejects any non-restoreaction without a valid signature. The key is the snapshot secret whensetSnapshotSecret()was called, otherwise a random per-session key. Apps with no secret and no PHP session now get400on every action until they callsetSnapshotSecret(). Custom form rendering and hand-written tests must callUsePHP::signAction($instanceId, $json). - Event props accept only
Actionor\Closure(#46).createElement()no longer runsis_callable()ononClick/onChange/ …; strings, arrays, invokable objects and ints throwInvalidArgumentException. TheH::*$on*parameters are narrowed toAction|\Closure|null. - Tag and attribute names are validated (#50). Tag names must match
[A-Za-z][A-Za-z0-9-]*, attribute names[A-Za-z_:][A-Za-z0-9:_.-]*, and any string prop namedon*(onclick,onerror,onLoadas a string) is refused. Violations throwRuntimeException.data-*,aria-*, SVG names,xlink:href,viewBox, custom elements all pass unchanged. - Failed partial submits are not replayed (#35). A non-2xx or thrown partial POST no longer falls back to
form.submit(). A cancelableusephp:submit-errorevent is dispatched and the component getsdata-usephp-error. setDeferPrefix()users must pass the same prefix torenderClientScript($src, $deferPrefix)(#35), which now emitswindow.usePHP.deferPrefix.session_regenerate_id()invalidates previously rendered action signatures and stored Session/Shared snapshots, same as the CSRF token.
Security fixes
- Client-writable hook state / storageType / instance id (#37, #41, #42 → #47).
Action::fromArray()validates every field's shape; malformed JSON is400 Invalid action datainstead of an uncaughtTypeError. Hook index is bounded to[0, 255],_usephp_componentmust contain#, be ≤ 255 bytes and carry no control characters, and the snapshot memo must name the posted instance. - Open redirect via
REQUEST_URI(#38 → #44). The post-action303 Locationis built bynormalizeRedirectPath(): exactly one leading/, no\, no query string, fallback to/on control characters.usephp.jsonly follows same-origin redirects. - Session snapshot injection (#39 → #48). Session/Shared snapshots are HMAC-bound to
session_id()viaSnapshotSerializer::withContext(). A?_snapshot=on a Session route is ignored and logged. The empty context is byte-identical to the old payload, so Persistent and plain Snapshot round trips are unchanged. - Session/Shared snapshots were never restored (#52, #53 → #54).
handleSnapshotRestoration()returned early without?_snapshot=, so Shared only restored by accident and Session state was write-only. Both now restore from$_SESSIONon every GET through the session-bound serializer. onClickstring callable executed (#40 → #46) and tag/attribute name injection (#31 → #50), see breaking changes above.- Client script (#35).
data-usephp-defer-urlis only hydrated when same-origin, under the defer prefix, andtext/html. Fragments containing a usePHP form, CSRF token or snapshot are never written tolocalStorageeven withDefer::$localCache.
Docs
- README (en/ja): new "What usePHP does not protect (trust boundaries)" section (#45), plus subsections for signed actions, the deferred fetch guard, non-replayed partial submits, tag/attribute validation, and the session binding of snapshots.
docs/: UsePHP decomposition design note (#36).
Tests
- The PRG redirect
exitindoHandleAction()used to kill the PHPUnit process silently with exit code 0, so roughly 80 tests never ran and CI stayed green (#49 → #51).UsePHP::withExitHandler()/withHeaderEmitter()are the test seams; the suite now completes. - 357 → 464 tests, 1122 assertions, all green. PHPStan and php-cs-fixer clean.
Full Changelog: v0.8.0...v0.9.0