Skip to content

Fix should-fix issues: TRUSTED_PROXIES, RateLimiter cap, reopen UX, backup - #1

Merged
REASON-labs merged 2 commits into
mainfrom
agent/fix-should-fix-issues
Oct 24, 2026
Merged

REASON-labs merged 2 commits into
mainfrom
agent/fix-should-fix-issues

Conversation

@REASON-labs

Copy link
Copy Markdown
Owner

Summary

Fixes 4 should-fix issues from the freestuff audit:

1. TRUSTED_PROXIES operational risk

Clamp TRUSTED_PROXIES to a hard max of 3. Values above 3 are almost certainly misconfigured and allow clients to forge X-Forwarded-For headers to bypass rate limiting. A warning is logged when clamping occurs.

2. RateLimiter memory growth

Added a hard cap (4096 keys) to RateLimiter._sweep() with graceful LRU eviction. Previously the dict could grow unbounded from sustained proxy-pool attacks even though individual keys age out after 1 hour.

3. admin_item_reopen UX

When an item is reopened (status gone → available), all old active claims are now cancelled. Previously the stale queue remained visible with no indication it was from a previous lifecycle of the item.

4. Backup strategy

Added backup.sh (executable, cron-ready) and BACKUP.md documentation. The script checkpoints the SQLite WAL before archiving the DB + uploads directory into a timestamped tarball.

Changes

  • app.py: TRUSTED_PROXIES clamping, admin_item_reopen cancels claims
  • hardening.py: RateLimiter hard cap in _sweep
  • tests/test_app.py: 4 new tests (73 total, all passing)
  • backup.sh: new backup script
  • BACKUP.md: backup strategy documentation
  • AGENTS.md: new repo documentation

Testing

All 73 tests pass locally.

REASON-labs and others added 2 commits October 23, 2026 10:37
…, admin item reopen UX, backup strategy

1. TRUSTED_PROXIES: clamp to max 3 with warning log. Prevents X-Forwarded-For
   forgery that bypasses rate limiting when misconfigured.

2. RateLimiter._sweep: add hard cap (4096 keys) with graceful LRU eviction.
   Prevents unbounded memory growth from proxy-pool attacks.

3. admin_item_reopen: cancel all active claims when reopening an item.
   Previously stale claims from the previous lifecycle remained visible in
   the queue with no indication they were obsolete.

4. Add backup.sh script and BACKUP.md documentation for the SQLite DB +
   uploads directory. Includes WAL checkpoint for consistency.

Tests: 73 passing (4 new).
backup.sh ran PRAGMA journal_mode=WAL on the live database (a lasting change to it) and then
tarred the file. feed's nightly Borg backup (reason.direct infra/server-backup) already takes a
consistent copy with SQLite's online-backup API, plus the uploads volume. The hardening fixes stay.
Tests: 73 passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FhuYBkdi4GZi3zBkmNm7Pj
@REASON-labs
REASON-labs merged commit f38a631 into main Oct 24, 2026
3 checks passed
@REASON-labs
REASON-labs deleted the agent/fix-should-fix-issues branch November 1, 2026 02:08
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