payload: {"action":"created","comment":{"url":"https://api.github.com/repos/Weasyl/weasyl/pulls/comments/284319967","pull_request_review_id":237903025,"id":284319967,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI4NDMxOTk2Nw==","diff_hunk":"@@ -241,6 +243,37 @@ def http2_server_push(request):\n     return http2_server_push\n \n \n+def rate_limit_check_tween_factory(handler, registry):\n+    \"\"\"\n+    Enforces rate limiting for routes which have been designated as having a rate limit for non 200-status requests.\n+\n+    Only triggers if appropriate headers have been added by `weasyl.controllers.decorators.rate_limit_route()` on the\n+    route in question, and if the pyramid.response.status_code indicates a client error (4xx; e.g., 403 Forbidden, when\n+    a sign-in fails authentication).\n+\n+    When the limit is exceeded, subsequent calls against the rate-limited route will raise WeasylError(\"rateLimitExceeded\"),\n+    (HTTP 429), until the cached expiration_time passes.\n+    \"\"\"\n+    def limit_check(request):\n+        resp = handler(request)\n+        # Only process the tween if we have indicated that the route is subject to rate limiting\n+        if 'Wzl-RateLimit-Count' in request.headers and 'Wzl-RateLimit-Expiration' in request.headers:\n+            rate_limit_expiration = request.headers['Wzl-RateLimit-Expiration']\n+            rate_limit_max = request.headers['Wzl-RateLimit-Count']\n+            cache_key = \"mw_rlimit--{addr}|{route_path}\".format(addr=request.client_addr, route_path=request.current_route_path())","path":"weasyl/middleware.py","position":37,"original_position":37,"commit_id":"62e1950c4fe2c5ecb7f672bfa2308817cb85c509","original_commit_id":"62e1950c4fe2c5ecb7f672bfa2308817cb85c509","user":{"login":"charmander","id":1889843,"node_id":"MDQ6VXNlcjE4ODk4NDM=","avatar_url":"https://avatars1.githubusercontent.com/u/1889843?v=4","gravatar_id":"","url":"https://api.github.com/users/charmander","html_url":"https://github.com/charmander","followers_url":"https://api.github.com/users/charmander/followers","following_url":"https://api.github.com/users/charmander/following{/other_user}","gists_url":"https://api.github.com/users/charmander/gists{/gist_id}","starred_url":"https://api.github.com/users/charmander/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/charmander/subscriptions","organizations_url":"https://api.github.com/users/charmander/orgs","repos_url":"https://api.github.com/users/charmander/repos","events_url":"https://api.github.com/users/charmander/events{/privacy}","received_events_url":"https://api.github.com/users/charmander/received_events","type":"User","site_admin":false},"body":"Rate limiting by IP address seems kind of doomed. (We allow IPv6 too!)","created_at":"2019-05-15T15:35:31Z","updated_at":"2019-05-15T15:36:31Z","html_url":"https://github.com/Weasyl/weasyl/pull/510#discussion_r284319967","pull_request_url":"https://api.github.com/repos/Weasyl/weasyl/pulls/510","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/Weasyl/weasyl/pulls/comments/284319967"},"html":{"href":"https://github.com/Weasyl/weasyl/pull/510#discussion_r284319967"},"pull_request":{"href":"https://api.github.com/repos/Weasyl/weasyl/pulls/510"}}},"pull_request":{"url":"https://api.github.com/repos/Weasyl/weasyl/pulls/510","id":278095911,"node_id":"MDExOlB1bGxSZXF1ZXN0Mjc4MDk1OTEx","html_url":"https://github.com/Weasyl/weasyl/pull/510","diff_url":"https://github.com/Weasyl/weasyl/pull/510.diff","patch_url":"https://github.com/Weasyl/weasyl/pull/510.patch","issue_url":"https://api.github.com/repos/Weasyl/weasyl/issues/510","number":510,"state":"open","locked":false,"title":"Implement rate limiting tween/middleware/route decorator","user":{"login":"kfkitsune","id":19718911,"node_id":"MDQ6VXNlcjE5NzE4OTEx","avatar_url":"https://avatars3.githubusercontent.com/u/19718911?v=4","gravatar_id":"","url":"https://api.github.com/users/kfkitsune","html_url":"https://github.com/kfkitsune","followers_url":"https://api.github.com/users/kfkitsune/followers","following_url":"https://api.github.com/users/kfkitsune/following{/other_user}","gists_url":"https://api.github.com/users/kfkitsune/gists{/gist_id}","starred_url":"https://api.github.com/users/kfkitsune/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kfkitsune/subscriptions","organizations_url":"https://api.github.com/users/kfkitsune/orgs","repos_url":"https://api.github.com/users/kfkitsune/repos","events_url":"https://api.github.com/users/kfkitsune/events{/privacy}","received_events_url":"https://api.github.com/users/kfkitsune/received_events","type":"User","site_admin":false},"body":"Adds a new Pyramid middleware tween, which leverages the dogpile.cache to track requests which fail (via 4xx responses), and rate limits requests on a configurable cooldown window and failed request count.\r\n\r\nInspired, at least in part, by RoR's Rack::Attack, but I couldn't find any pre-made Pyramid middleware of a similar nature. While not as fully featured as Rack::Attack, it should function for our needs.\r\n\r\nThe middleware tween increments the failed counts on any response which has a value in the 4xx range.\r\n\r\nRate limiting is achieved by decorating a route in the following manner:\r\n```python\r\n# Implies 120 second rate limit window, and 5 failed attempts\r\n@rate_limit_route()\r\ndef route_a():\r\n    pass\r\n\r\n# The decorator can be configured as desired\r\n@rate_limit_route(expiration_time=60 * 1, limit=6)\r\ndef route_a():\r\n    pass\r\n```\r\n\r\nCurrently, the following routes are limited:\r\n1) /signin\r\n2) /signin/2fa-auth","created_at":"2019-05-13T01:10:14Z","updated_at":"2019-05-15T15:36:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5bcd97b70021d2ba2b0b0b1600896be5656443a2","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":372292702,"node_id":"MDU6TGFiZWwzNzIyOTI3MDI=","url":"https://api.github.com/repos/Weasyl/weasyl/labels/enhancement","name":"enhancement","color":"84b6eb","default":true},{"id":448717124,"node_id":"MDU6TGFiZWw0NDg3MTcxMjQ=","url":"https://api.github.com/repos/Weasyl/weasyl/labels/security","name":"security","color":"b60205","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/Weasyl/weasyl/pulls/510/commits","review_comments_url":"https://api.github.com/repos/Weasyl/weasyl/pulls/510/comments","review_comment_url":"https://api.github.com/repos/Weasyl/weasyl/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Weasyl/weasyl/issues/510/comments","statuses_url":"https://api.github.com/repos/Weasyl/weasyl/statuses/62e1950c4fe2c5ecb7f672bfa2308817cb85c509","head":{"label":"kfkitsune:add-rate-limiting","ref":"add-rate-limiting","sha":"62e1950c4fe2c5ecb7f672bfa2308817cb85c509","user":{"login":"kfkitsune","id":19718911,"node_id":"MDQ6VXNlcjE5NzE4OTEx","avatar_url":"https://avatars3.githubusercontent.com/u/19718911?v=4","gravatar_id":"","url":"https://api.github.com/users/kfkitsune","html_url":"https://github.com/kfkitsune","followers_url":"https://api.github.com/users/kfkitsune/followers","following_url":"https://api.github.com/users/kfkitsune/following{/other_user}","gists_url":"https://api.github.com/users/kfkitsune/gists{/gist_id}","starred_url":"https://api.github.com/users/kfkitsune/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kfkitsune/subscriptions","organizations_url":"https://api.github.com/users/kfkitsune/orgs","repos_url":"https://api.github.com/users/kfkitsune/repos","events_url":"https://api.github.com/users/kfkitsune/events{/privacy}","received_events_url":"https://api.github.com/users/kfkitsune/received_events","type":"User","site_admin":false},"repo":{"id":60300859,"node_id":"MDEwOlJlcG9zaXRvcnk2MDMwMDg1OQ==","name":"weasyl","full_name":"kfkitsune/weasyl","private":false,"owner":{"login":"kfkitsune","id":19718911,"node_id":"MDQ6VXNlcjE5NzE4OTEx","avatar_url":"https://avatars3.githubusercontent.com/u/19718911?v=4","gravatar_id":"","url":"https://api.github.com/users/kfkitsune","html_url":"https://github.com/kfkitsune","followers_url":"https://api.github.com/users/kfkitsune/followers","following_url":"https://api.github.com/users/kfkitsune/following{/other_user}","gists_url":"https://api.github.com/users/kfkitsune/gists{/gist_id}","starred_url":"https://api.github.com/users/kfkitsune/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kfkitsune/subscriptions","organizations_url":"https://api.github.com/users/kfkitsune/orgs","repos_url":"https://api.github.com/users/kfkitsune/repos","events_url":"https://api.github.com/users/kfkitsune/events{/privacy}","received_events_url":"https://api.github.com/users/kfkitsune/received_events","type":"User","site_admin":false},"html_url":"https://github.com/kfkitsune/weasyl","description":"The website.","fork":true,"url":"https://api.github.com/repos/kfkitsune/weasyl","forks_url":"https://api.github.com/repos/kfkitsune/weasyl/forks","keys_url":"https://api.github.com/repos/kfkitsune/weasyl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kfkitsune/weasyl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kfkitsune/weasyl/teams","hooks_url":"https://api.github.com/repos/kfkitsune/weasyl/hooks","issue_events_url":"https://api.github.com/repos/kfkitsune/weasyl/issues/events{/number}","events_url":"https://api.github.com/repos/kfkitsune/weasyl/events","assignees_url":"https://api.github.com/repos/kfkitsune/weasyl/assignees{/user}","branches_url":"https://api.github.com/repos/kfkitsune/weasyl/branches{/branch}","tags_url":"https://api.github.com/repos/kfkitsune/weasyl/tags","blobs_url":"https://api.github.com/repos/kfkitsune/weasyl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kfkitsune/weasyl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kfkitsune/weasyl/git/refs{/sha}","trees_url":"https://api.github.com/repos/kfkitsune/weasyl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kfkitsune/weasyl/statuses/{sha}","languages_url":"https://api.github.com/repos/kfkitsune/weasyl/languages","stargazers_url":"https://api.github.com/repos/kfkitsune/weasyl/stargazers","contributors_url":"https://api.github.com/repos/kfkitsune/weasyl/contributors","subscribers_url":"https://api.github.com/repos/kfkitsune/weasyl/subscribers","subscription_url":"https://api.github.com/repos/kfkitsune/weasyl/subscription","commits_url":"https://api.github.com/repos/kfkitsune/weasyl/commits{/sha}","git_commits_url":"https://api.github.com/repos/kfkitsune/weasyl/git/commits{/sha}","comments_url":"https://api.github.com/repos/kfkitsune/weasyl/comments{/number}","issue_comment_url":"https://api.github.com/repos/kfkitsune/weasyl/issues/comments{/number}","contents_url":"https://api.github.com/repos/kfkitsune/weasyl/contents/{+path}","compare_url":"https://api.github.com/repos/kfkitsune/weasyl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kfkitsune/weasyl/merges","archive_url":"https://api.github.com/repos/kfkitsune/weasyl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kfkitsune/weasyl/downloads","issues_url":"https://api.github.com/repos/kfkitsune/weasyl/issues{/number}","pulls_url":"https://api.github.com/repos/kfkitsune/weasyl/pulls{/number}","milestones_url":"https://api.github.com/repos/kfkitsune/weasyl/milestones{/number}","notifications_url":"https://api.github.com/repos/kfkitsune/weasyl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kfkitsune/weasyl/labels{/name}","releases_url":"https://api.github.com/repos/kfkitsune/weasyl/releases{/id}","deployments_url":"https://api.github.com/repos/kfkitsune/weasyl/deployments","created_at":"2016-06-02T22:13:26Z","updated_at":"2019-05-09T03:33:50Z","pushed_at":"2019-05-13T00:54:55Z","git_url":"git://github.com/kfkitsune/weasyl.git","ssh_url":"git@github.com:kfkitsune/weasyl.git","clone_url":"https://github.com/kfkitsune/weasyl.git","svn_url":"https://github.com/kfkitsune/weasyl","homepage":"https://www.weasyl.com/","size":4921,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"Weasyl:master","ref":"master","sha":"c0692c2d2ecdf6fc70426d3cf5fb3d2073884e96","user":{"login":"Weasyl","id":2838769,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI4Mzg3Njk=","avatar_url":"https://avatars0.githubusercontent.com/u/2838769?v=4","gravatar_id":"","url":"https://api.github.com/users/Weasyl","html_url":"https://github.com/Weasyl","followers_url":"https://api.github.com/users/Weasyl/followers","following_url":"https://api.github.com/users/Weasyl/following{/other_user}","gists_url":"https://api.github.com/users/Weasyl/gists{/gist_id}","starred_url":"https://api.github.com/users/Weasyl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Weasyl/subscriptions","organizations_url":"https://api.github.com/users/Weasyl/orgs","repos_url":"https://api.github.com/users/Weasyl/repos","events_url":"https://api.github.com/users/Weasyl/events{/privacy}","received_events_url":"https://api.github.com/users/Weasyl/received_events","type":"Organization","site_admin":false},"repo":{"id":58244355,"node_id":"MDEwOlJlcG9zaXRvcnk1ODI0NDM1NQ==","name":"weasyl","full_name":"Weasyl/weasyl","private":false,"owner":{"login":"Weasyl","id":2838769,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI4Mzg3Njk=","avatar_url":"https://avatars0.githubusercontent.com/u/2838769?v=4","gravatar_id":"","url":"https://api.github.com/users/Weasyl","html_url":"https://github.com/Weasyl","followers_url":"https://api.github.com/users/Weasyl/followers","following_url":"https://api.github.com/users/Weasyl/following{/other_user}","gists_url":"https://api.github.com/users/Weasyl/gists{/gist_id}","starred_url":"https://api.github.com/users/Weasyl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Weasyl/subscriptions","organizations_url":"https://api.github.com/users/Weasyl/orgs","repos_url":"https://api.github.com/users/Weasyl/repos","events_url":"https://api.github.com/users/Weasyl/events{/privacy}","received_events_url":"https://api.github.com/users/Weasyl/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/Weasyl/weasyl","description":"The website.","fork":false,"url":"https://api.github.com/repos/Weasyl/weasyl","forks_url":"https://api.github.com/repos/Weasyl/weasyl/forks","keys_url":"https://api.github.com/repos/Weasyl/weasyl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Weasyl/weasyl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Weasyl/weasyl/teams","hooks_url":"https://api.github.com/repos/Weasyl/weasyl/hooks","issue_events_url":"https://api.github.com/repos/Weasyl/weasyl/issues/events{/number}","events_url":"https://api.github.com/repos/Weasyl/weasyl/events","assignees_url":"https://api.github.com/repos/Weasyl/weasyl/assignees{/user}","branches_url":"https://api.github.com/repos/Weasyl/weasyl/branches{/branch}","tags_url":"https://api.github.com/repos/Weasyl/weasyl/tags","blobs_url":"https://api.github.com/repos/Weasyl/weasyl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Weasyl/weasyl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Weasyl/weasyl/git/refs{/sha}","trees_url":"https://api.github.com/repos/Weasyl/weasyl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Weasyl/weasyl/statuses/{sha}","languages_url":"https://api.github.com/repos/Weasyl/weasyl/languages","stargazers_url":"https://api.github.com/repos/Weasyl/weasyl/stargazers","contributors_url":"https://api.github.com/repos/Weasyl/weasyl/contributors","subscribers_url":"https://api.github.com/repos/Weasyl/weasyl/subscribers","subscription_url":"https://api.github.com/repos/Weasyl/weasyl/subscription","commits_url":"https://api.github.com/repos/Weasyl/weasyl/commits{/sha}","git_commits_url":"https://api.github.com/repos/Weasyl/weasyl/git/commits{/sha}","comments_url":"https://api.github.com/repos/Weasyl/weasyl/comments{/number}","issue_comment_url":"https://api.github.com/repos/Weasyl/weasyl/issues/comments{/number}","contents_url":"https://api.github.com/repos/Weasyl/weasyl/contents/{+path}","compare_url":"https://api.github.com/repos/Weasyl/weasyl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Weasyl/weasyl/merges","archive_url":"https://api.github.com/repos/Weasyl/weasyl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Weasyl/weasyl/downloads","issues_url":"https://api.github.com/repos/Weasyl/weasyl/issues{/number}","pulls_url":"https://api.github.com/repos/Weasyl/weasyl/pulls{/number}","milestones_url":"https://api.github.com/repos/Weasyl/weasyl/milestones{/number}","notifications_url":"https://api.github.com/repos/Weasyl/weasyl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Weasyl/weasyl/labels{/name}","releases_url":"https://api.github.com/repos/Weasyl/weasyl/releases{/id}","deployments_url":"https://api.github.com/repos/Weasyl/weasyl/deployments","created_at":"2016-05-07T01:53:26Z","updated_at":"2019-05-01T23:26:48Z","pushed_at":"2019-05-13T01:10:15Z","git_url":"git://github.com/Weasyl/weasyl.git","ssh_url":"git@github.com:Weasyl/weasyl.git","clone_url":"https://github.com/Weasyl/weasyl.git","svn_url":"https://github.com/Weasyl/weasyl","homepage":"https://www.weasyl.com/","size":4848,"stargazers_count":78,"watchers_count":78,"language":"Python","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":17,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":79,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":17,"open_issues":79,"watchers":78,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Weasyl/weasyl/pulls/510"},"html":{"href":"https://github.com/Weasyl/weasyl/pull/510"},"issue":{"href":"https://api.github.com/repos/Weasyl/weasyl/issues/510"},"comments":{"href":"https://api.github.com/repos/Weasyl/weasyl/issues/510/comments"},"review_comments":{"href":"https://api.github.com/repos/Weasyl/weasyl/pulls/510/comments"},"review_comment":{"href":"https://api.github.com/repos/Weasyl/weasyl/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Weasyl/weasyl/pulls/510/commits"},"statuses":{"href":"https://api.github.com/repos/Weasyl/weasyl/statuses/62e1950c4fe2c5ecb7f672bfa2308817cb85c509"}},"author_association":"MEMBER"}}
other: {"actor":{"display_login":"charmander"}}