Home

boring / v2

publicBoring-Software-Inc/v2
Overview Code History Branches Pull requestsIssuesInsights Campfire Docs
main
HomeOverview Code PRsIssues

fix: validate and rate-limit recoverInstallation, prune stale access checks

closed
#185 opened by detail-app[bot]detail/bug-fix/fix-validate-and-rate-limit-recoverinstallation-pr-dabedd→main
Conversation5
detail-app[bot]
Commits
0
Files changed…
opened this pull request
Author
· 2 weeks ago

Detail bug report: View on Detail

Bug

recoverInstallation accepted an arbitrary, unvalidated installationId string from any authenticated user with no format validation, no rate limit, and no retention pruning on the installation_access_checks table. An attacker could rotate installation ids to enqueue unlimited recover-installation jobs (each costing at least one GitHub App API call), permanently grow the table (nothing ever pruned it), and flood Sentry with per-job failure warnings.

The root cause: the endpoint's inputValidator was a pass-through, the queue's singletonKey only coalesced identical in-flight jobs (distinct ids bypassed it), and the table had no TTL cleanup — the only deletion path was the ON DELETE CASCADE FK on user deletion.

Closes #172

Fix

  • Input validation: recoverInstallation's inputValidator now rejects non-numeric installationId values (/^\d+$/) before the handler runs — GitHub installation ids are positive integers.
  • Per-user rate limiting: The handler now calls countRecentInstallAccessChecks(db, userId, 60) before writing/enqueuing. If the user already has ≥ 5 distinct installation ids in the last 60 seconds, it throws a rate-limit error. The count is on distinct ids because the upsert on (user_id, forge, installation_id) collapses repeats — exactly the dimension an attacker rotates to burn quota.
  • TTL pruning: New pruneInstallAccessChecks(db, maxAgeDays) function deletes rows with verified_at < now() - maxAgeDays. A daily pg-boss schedule (prune-installation-access-checks, cron 30 3 * * *) calls it with INSTALL_ACCESS_CHECK_RETENTION_DAYS = 7 (new contracts constant), bounding table growth.

Testing

  • New integration tests for countRecentInstallAccessChecks and pruneInstallAccessChecks (9 tests) covering the rate-limit count semantics, per-user isolation, and the retention prune window.
  • Existing recover-installation integration test (11 tests) and organizations integration test (55 tests) pass with no regression.
  • Server-fn boundary structural test (19 tests) confirms recoverInstallation is still classified "authed" with the same middleware chain.
  • End-to-end verification against a real Postgres + pg-boss instance: confirmed invalid ids are rejected, the 6th distinct id in 60s is rate-limited, repeating the same id does not increase the count, an 8-day-old row is pruned while fresh rows remain, and the prune queue + cron schedule register in pg-boss.
  • Typecheck (all 16 workspaces), Biome lint/format, boundary check, and anti-slop all pass.

Automatic Fixes PRs can be configured here.

unkey-deploy[bot]commented· 2 weeks ago

The latest updates on your projects. Learn more about Unkey Deploy

NameStatusPreviewInspectUpdated (UTC)
tripwire / web (preview)ReadyVisit PreviewInspectNov 7, 2026 6:56am
capy-ai[bot]commented· 2 weeks ago

Capy couldn't review this pull request because grim's workspace is out of credits, add credits or enable auto-reload to resume automatic reviews.

Open in Capy

Changes requested

tripwire-sh[bot] · 2 weeks ago

Blocked. See the comment.

tripwire-sh[bot]commented· 2 weeks ago

@detail-app[bot], Tripwire blocked this change request.

Rate limit: You opened 59 change requests in a short time. Wait before you open another.

View on Tripwire

How do I fix this?

A new commit will not fix this.

If you think it should merge anyway, say so in a comment. A maintainer will decide.

detail-app[bot]commented· 2 weeks ago

Re: github.com/Boring-Software-Inc/…/185 — Tripwire's block is a rate limit on this bot opening change requests (59 in a short window), not a code issue; the run comment itself states a new commit will not fix it. No PR-side change can clear it, so a maintainer needs to decide whether to override the block.

Sign in to comment.

Merge readiness

Checking mergeability after the indexing worker computes the current branch state.

Autopilot

Debug

Reviews

Approved0
ReviewersNone yet

Configure an OpenRouter key in repository settings.