Audit fixes (2026-09) - #3
Merged
Merged
Conversation
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.
|
ePHPm Preview — removed Preview deployment has been torn down. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Audited KV/cache fixes for session-handler. Adopts
ephpm_kv_setnxwhere it was missing (atomicadd()/NX/locks), stops reporting OOM writes as success, fixes theincrByfalse->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).