github_detail: Limit bot to 5 requests per message.
Fixes .
MODIFY
zulip_bots/zulip_bots/bots/github_detail/github_detail.py
zulip_bots/zulip_bots/bots/github_detail/github_detail.py
@@ -74,9 +74,15 @@ class GithubHandler(object):
return
# Capture owner, repo, id
- issue_prs = re.finditer(
- self.HANDLE_MESSAGE_REGEX, message['content'])
+ issue_prs = list(re.finditer(
+ self.HANDLE_MESSAGE_REGEX, message['content']))
bot_messages = []
+ if len(issue_prs) > 5:
+ # We limit to 5 requests to prevent denial-of-service
+ bot_message = 'Please ask for <=5 links in any one request'
+ bot_handler.send_reply(message, bot_message)
+ return
+
for issue_pr in issue_prs:
owner, repo = self.get_owner_and_repo(issue_pr)
if owner and repo:

MODIFY
zulip_bots/zulip_bots/bots/github_detail/test_github_detail.py
zulip_bots/zulip_bots/bots/github_detail/test_github_detail.py
@@ -81,3 +81,11 @@ class TestGithubDetailBot(BotTestCase):
with self.mock_config_info(self.mock_config):
self.verify_reply(request, bot_response)
+
+ def test_too_many_request(self) -> None:
+ request = 'zulip/zulip#1 zulip/zulip#1 zulip/zulip#1 zulip/zulip#1 '\
+ 'zulip/zulip#1 zulip/zulip#1 zulip/zulip#1 zulip/zulip#1'
+ bot_response = 'Please ask for <=5 links in any one request'
+
+ with self.mock_config_info(self.mock_config):
+ self.verify_reply(request, bot_response)

github_detail: Limit bot to 5 requests per message.

Fixes #172 .