Skip to content

fix: rate limit unsupported source issue creation - #321

Open
kentoku24 wants to merge 1 commit into
mainfrom
codex/fix-github-issue-spamming-vulnerability
Open

fix: rate limit unsupported source issue creation#321
kentoku24 wants to merge 1 commit into
mainfrom
codex/fix-github-issue-spamming-vulnerability

Conversation

@kentoku24

Copy link
Copy Markdown
Owner

Motivation

  • The /add flow invoked GitHub issue creation on every unsupported-source error with no local gating, enabling spam and GitHub API token/rate exhaustion.
  • Introduce a minimal in-process guard to reduce abuse while preserving existing user-visible behavior and reporter semantics.

Description

  • Add a host-based cooldown to AddCommandHandler with a default of DEFAULT_UNSUPPORTED_SOURCE_REPORT_COOLDOWN_SECONDS = 3600 and a configurable unsupported_source_report_cooldown_seconds property.
  • Implement _last_reported_hosts tracking and a now injection point so the cooldown check uses now() and is testable.
  • Short-circuit calls to unsupported_source_reporter.report_unsupported_source when the host was reported recently and return a user-facing rate-limit message via UNSUPPORTED_SOURCE_REPORT_RATE_LIMIT_MESSAGE while keeping existing error/result messages intact.
  • Add a deterministic unit test test_start_rate_limits_unsupported_source_issue_reporting_per_host to validate throttling and update imports/constants used by tests.

Testing

  • Ran python -m unittest tests.test_discord_add tests.test_discord_interactions tests.test_github_issue_reporting and all tests passed (36 tests ran and returned OK).
  • New unit test exercises time-injected paths to assert the reporter is called only once across rapid repeated unsupported-source submissions for the same host.

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2d5005d20b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +90 to +94
last_reported_at = self._last_reported_hosts.get(host)
if (
self.unsupported_source_report_cooldown_seconds > 0
and last_reported_at is not None
and (current_time - last_reported_at)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Guard host cooldown map with a lock

_report_unsupported_source performs a read-then-write on _last_reported_hosts without synchronization, so concurrent requests can both pass the cooldown check and both call report_unsupported_source for the same host. In this repo the service runs on ThreadingHTTPServer (manga_watch/run_service.py), so this race is reachable in production and undermines the new rate-limit goal (extra GitHub API calls and possible duplicate issue creation under burst traffic). Please make the check/update atomic (e.g., lock per handler or per-host reservation) so the throttle is effective across threads.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant