Skip to content

fix(php): keep rate-limit counters in the private temp directory - #19

Merged
mrgoonie merged 1 commit into
mainfrom
claude/elegant-maxwell-qbzdyl
Oct 31, 2026
Merged

mrgoonie merged 1 commit into
mainfrom
claude/elegant-maxwell-qbzdyl

Conversation

@mrgoonie

Copy link
Copy Markdown
Contributor

Closes #18.

The PHP backend's built-in rate limiter stored its counters in sys_get_temp_dir()/dewee-webchat-rl. On a shared host another account could create that directory first and then reset, inflate or redirect the counters.

Changes

  • Counters (rl-<hash>) now live in the per-user private directory from fix(php): isolate shared temp files and require a secret #16 (dewee-webchat-<uid>, 0700, not used when it is a link, foreign-owned or open to others). When that directory is unavailable, requests are not limited and error_log says why. This matches the existing fail-open behaviour.
  • New counter files are created with fopen(..., 'x+'), so a planted link is never followed, and set to 0600. An existing file is opened only when it is this user's own regular file and nobody else can write to it.
  • Cleanup now only touches rl-* files, so the cached CCP config and the legacy-warning marker in the same directory are left alone.
  • The README states where the counters are kept.

Verification

  • New test: a world-writable dewee-webchat-rl planted in the temp dir stays empty, and the counters land in the private directory with no group or other permissions. The test fails on the old code and passes with the fix.
  • pnpm test: 20 files, 267 tests pass. pnpm typecheck passes. php -l is clean.

Generated by Claude Code

The built-in limiter stored its counters in a fixed shared directory
(dewee-webchat-rl) under the system temp dir. On a shared host another
account could create it first and reset, inflate or redirect the
counters. Counters now live in the per-user private directory, new files
are created exclusively, and an existing file is used only when it is
this user's own and not writable by others.

Closes #18

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A1xMi7a6shAxFWLtFT4don
@mrgoonie
mrgoonie marked this pull request as ready for review October 31, 2026 05:39
@mrgoonie
mrgoonie merged commit 3482a95 into main Oct 31, 2026
2 checks passed
This was referenced Oct 31, 2026
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.

PHP backend: rate-limit files live in a shared temp directory

2 participants