Skip to content

Suggestion: cooldown on the provider reset endpoint - #60

Open
JAG-UK wants to merge 1 commit into
mainfrom
suggestion/reset-cooldown
Open

JAG-UK wants to merge 1 commit into
mainfrom
suggestion/reset-cooldown

Conversation

@JAG-UK

@JAG-UK JAG-UK commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

This is a suggestion from a security read-through of the repo, not a required fix. Merge, change or close as you see fit.

Problem

POST /providers/{id}/reset needs no authentication and sets next_url_discovery_at / next_bms_test_at to now. Anyone can call it in a loop to keep re-queuing URL discovery and BMS bandwidth tests for any provider, which costs worker time and keeps load on that provider.

I did not add a bearer token because I don't know whether the sp-tool frontend calls this from the browser; a token would break that.

Change

A given provider's schedule can be reset once per 15 minutes (RESET_COOLDOWN). A repeat within that window returns 429.

  • Tracked per provider and schedule: resetting url_discovery does not block bms_test. all counts as both.
  • Only successful resets start a cooldown, so requests for unknown providers can't fill the map.
  • Kept in memory in AppState, so there is no migration.

Limits — your call

  • In-memory means per instance and cleared on restart. Production runs one instance, so that is enough today; it would need a DB column if that changes.
  • It limits how often one provider can be reset, not how many providers one caller can reset. Someone could still walk the whole provider list once per window.
  • 15 minutes is a guess. Change the constant if operators need to re-run tests more often.
  • If the endpoint is only ever used by operators, requiring the existing AUTH_TOKEN would be the stronger fix.

Testing

cargo fmt --check and cargo clippy --workspace pass. The providers_reset integration tests pass locally (9, including two new ones for the cooldown and for unknown providers). The rest of the integration suite was not run locally; CI runs it.

🤖 Generated with Claude Code

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@JAG-UK
JAG-UK deployed to production-fidl November 26, 2026 14:07 — with GitHub Actions Active

This branch was successfully deployed

1 active deployment
production-fidl — a0bab6de Deployed Nov 26, 2026 by JAG-UK via build-and-publish / build_and_push #208
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