Skip to content

Audit fixes (2026-09) - #3

Merged
luthermonson merged 2 commits into
mainfrom
fix/audit-2026-09
Sep 11, 2026
Merged

Audit fixes (2026-09)#3
luthermonson merged 2 commits into
mainfrom
fix/audit-2026-09

Conversation

@luthermonson

Copy link
Copy Markdown
Contributor

Audited KV/cache fixes for session-handler. Adopts ephpm_kv_setnx where it was missing (atomic add()/NX/locks), stops reporting OOM writes as success, fixes the incrBy false->0 cast across the copied KvOps, and refreshes docs/CI. Every behavioral change has a test (agent ran the suite green in WSL PHP 8.5).

SapiKvOps::incrBy did (int) ephpm_kv_incr_by(...); (int) false === 0
silently collapsed the SAPI's not-an-integer signal into a legitimate
counter value. Capture the result and throw a RuntimeException on false,
matching the KvOpsInterface Throws contract that InMemoryKvOps already
models.

Add setnx(key, value, ttl) across the interface, SapiKvOps
(ephpm_kv_setnx), and InMemoryKvOps (insert-or-fail on a live entry) as
the atomic lock primitive the opt-in session lock builds on.
Add an opt-in per-session lock (lockSessions, default off, behavior
unchanged): read() acquires <prefix>lock:<id> via a bounded ephpm_kv_setnx
spin and close() releases it. Lock TTL, spin interval, and max-wait are
configurable. Release is best-effort (no CAS to verify the owner token);
the TTL is the backstop, matching Files-handler advisory-flock parity.
On spin timeout the request proceeds lock-free.

Generate session ids directly in create_sid() instead of delegating to
session_create_id(). When this handler is active PHP dispatches id
creation to create_sid(), so calling session_create_id() from inside it
is a re-entrancy trap that only current PHP's core guard saves. Generate
the id from a CSPRNG honoring session.sid_length and
session.sid_bits_per_character, removing the hazard entirely.

Tests cover locking (default creates no lock, acquire+TTL, held lock
blocks then releases, TTL expiry frees it) and a separate-process
regression pinning create_sid() against recursion under a live
session_start(). README: current release v0.10.2; document the opt-in
lock and its caveats.
@luthermonson
luthermonson merged commit 7a6d25e into main Sep 11, 2026
3 checks passed
@luthermonson
luthermonson deleted the fix/audit-2026-09 branch September 11, 2026 06:47
@ephpm

ephpm Bot commented Sep 11, 2026

Copy link
Copy Markdown

ePHPm Preview — removed

Preview deployment has been torn down.

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