Every Bearer API request unnecessarily starts a new PHP session #83

Open
opened 2026-09-01 00:07:15 -04:00 by jared · 0 comments
Owner

Severity: Low

RateLimitMiddleware::check() calls session_start() unconditionally, before ApiKeyAuth even runs. A Bearer-only client that never sends a session cookie back gets a fresh session ID and a new session file written to session.save_path on every single request, cleaned up only by PHP's own session GC — continuous session-file churn for zero benefit at sustained automation volume (e.g. hwmonDaemon or a triage tool polling frequently). Each response also sends an unnecessary Set-Cookie header on what's meant to be a stateless API. Additionally, since this session_start() runs before AuthMiddleware.php's cookie-hardening (session.cookie_httponly etc.), which Bearer requests never reach, these sessions get whatever cookie defaults are in the server's php.ini rather than the app's hardened settings (unless already hardened at the server-config level).

Fix: Skip session_start() for Bearer-authenticated requests (detect via the Authorization: Bearer header before starting the session), and rate-limit those requests purely by the IP/API-key bucket instead.

**Severity:** Low `RateLimitMiddleware::check()` calls `session_start()` unconditionally, before `ApiKeyAuth` even runs. A Bearer-only client that never sends a session cookie back gets a fresh session ID and a new session file written to `session.save_path` on every single request, cleaned up only by PHP's own session GC — continuous session-file churn for zero benefit at sustained automation volume (e.g. hwmonDaemon or a triage tool polling frequently). Each response also sends an unnecessary `Set-Cookie` header on what's meant to be a stateless API. Additionally, since this `session_start()` runs before `AuthMiddleware.php`'s cookie-hardening (`session.cookie_httponly` etc.), which Bearer requests never reach, these sessions get whatever cookie defaults are in the server's `php.ini` rather than the app's hardened settings (unless already hardened at the server-config level). **Fix:** Skip `session_start()` for Bearer-authenticated requests (detect via the `Authorization: Bearer` header before starting the session), and rate-limit those requests purely by the IP/API-key bucket instead.
jared added the performancepriority/low labels 2026-09-08 10:15:48 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: LotusGuild/tinker_tickets#83