{"action":"created","comment":{"url":"https://api.github.com/repos/nextcloud/server/pulls/comments/111488019","pull_request_review_id":32739212,"id":111488019,"diff_hunk":"@@ -0,0 +1,83 @@\n+<?php\n+/**\n+ * @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch>\n+ *\n+ * @license GNU AGPL version 3 or any later version\n+ *\n+ * This program is free software: you can redistribute it and/or modify\n+ * it under the terms of the GNU Affero General Public License as\n+ * published by the Free Software Foundation, either version 3 of the\n+ * License, or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU Affero General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU Affero General Public License\n+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.\n+ *\n+ */\n+\n+namespace OC\\AppFramework\\Middleware\\Security;\n+\n+use OC\\AppFramework\\Utility\\ControllerMethodReflector;\n+use OC\\Security\\Bruteforce\\Throttler;\n+use OCP\\AppFramework\\Http\\Response;\n+use OCP\\AppFramework\\Middleware;\n+use OCP\\IRequest;\n+\n+/**\n+ * Class BruteForceMiddleware performs the bruteforce protection for controllers\n+ * that are annotated with @BruteForceProtection(action=$action) whereas $action\n+ * is the action that should be logged within the database.\n+ *\n+ * @package OC\\AppFramework\\Middleware\\Security\n+ */\n+class BruteForceMiddleware extends Middleware {\n+\t/** @var ControllerMethodReflector */\n+\tprivate $reflector;\n+\t/** @var Throttler */\n+\tprivate $throttler;\n+\t/** @var IRequest */\n+\tprivate $request;\n+\n+\t/**\n+\t * @param ControllerMethodReflector $controllerMethodReflector\n+\t * @param Throttler $throttler\n+\t * @param IRequest $request\n+\t */\n+\tpublic function __construct(ControllerMethodReflector $controllerMethodReflector,\n+\t\t\t\t\t\t\t\tThrottler $throttler,\n+\t\t\t\t\t\t\t\tIRequest $request) {\n+\t\t$this->reflector = $controllerMethodReflector;\n+\t\t$this->throttler = $throttler;\n+\t\t$this->request = $request;\n+\t}\n+\n+\t/**\n+\t * {@inheritDoc}\n+\t */\n+\tpublic function beforeController($controller, $methodName) {\n+\t\tparent::beforeController($controller, $methodName);\n+\n+\t\tif($this->reflector->hasAnnotation('BruteForceProtection')) {\n+\t\t\t$action = $this->reflector->getAnnotationParameter('BruteForceProtection', 'action');\n+\t\t\t$this->throttler->sleepDelay($this->request->getRemoteAddress(), $action);","path":"lib/private/AppFramework/Middleware/Security/BruteForceMiddleware.php","position":66,"original_position":66,"commit_id":"8149945a916447b4e7dae8182dbf0c354e7d19e8","original_commit_id":"8149945a916447b4e7dae8182dbf0c354e7d19e8","user":{"login":"rullzer","id":45821,"avatar_url":"https://avatars1.githubusercontent.com/u/45821?v=3","gravatar_id":"","url":"https://api.github.com/users/rullzer","html_url":"https://github.com/rullzer","followers_url":"https://api.github.com/users/rullzer/followers","following_url":"https://api.github.com/users/rullzer/following{/other_user}","gists_url":"https://api.github.com/users/rullzer/gists{/gist_id}","starred_url":"https://api.github.com/users/rullzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rullzer/subscriptions","organizations_url":"https://api.github.com/users/rullzer/orgs","repos_url":"https://api.github.com/users/rullzer/repos","events_url":"https://api.github.com/users/rullzer/events{/privacy}","received_events_url":"https://api.github.com/users/rullzer/received_events","type":"User","site_admin":false},"body":"So you get hit two times with the sleepdelay if your request is thottlered?","created_at":"2017-04-13T21:11:03Z","updated_at":"2017-04-13T21:11:26Z","html_url":"https://github.com/nextcloud/server/pull/4346#discussion_r111488019","pull_request_url":"https://api.github.com/repos/nextcloud/server/pulls/4346","_links":{"self":{"href":"https://api.github.com/repos/nextcloud/server/pulls/comments/111488019"},"html":{"href":"https://github.com/nextcloud/server/pull/4346#discussion_r111488019"},"pull_request":{"href":"https://api.github.com/repos/nextcloud/server/pulls/4346"}}},"pull_request":{"url":"https://api.github.com/repos/nextcloud/server/pulls/4346","id":115840924,"html_url":"https://github.com/nextcloud/server/pull/4346","diff_url":"https://github.com/nextcloud/server/pull/4346.diff","patch_url":"https://github.com/nextcloud/server/pull/4346.patch","issue_url":"https://api.github.com/repos/nextcloud/server/issues/4346","number":4346,"state":"open","locked":false,"title":"Make BruteForceProtection annotation more clever","user":{"login":"LukasReschke","id":878997,"avatar_url":"https://avatars3.githubusercontent.com/u/878997?v=3","gravatar_id":"","url":"https://api.github.com/users/LukasReschke","html_url":"https://github.com/LukasReschke","followers_url":"https://api.github.com/users/LukasReschke/followers","following_url":"https://api.github.com/users/LukasReschke/following{/other_user}","gists_url":"https://api.github.com/users/LukasReschke/gists{/gist_id}","starred_url":"https://api.github.com/users/LukasReschke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LukasReschke/subscriptions","organizations_url":"https://api.github.com/users/LukasReschke/orgs","repos_url":"https://api.github.com/users/LukasReschke/repos","events_url":"https://api.github.com/users/LukasReschke/events{/privacy}","received_events_url":"https://api.github.com/users/LukasReschke/received_events","type":"User","site_admin":false},"body":"This makes the new `@BruteForceProtection` annotation more clever and moves the relevant code into it's own middleware.\r\n\r\nBasically you can now set `@BruteForceProtection(action=$key)` as annotation and that will make the controller bruteforce protected. However, the difference to before is that you need to call `$response->throttle()` to increase the counter. Before the counter was increased every time which leads to all kind of unexpected problems.\r\n\r\nWill create documentation once we agreed on this :)\r\n\r\nSigned-off-by: Lukas Reschke <lukas@statuscode.ch>","created_at":"2017-04-13T20:54:04Z","updated_at":"2017-04-13T21:11:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d022f72dc9cd43ec1cca1782598856609b595294","assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/nextcloud/server/milestones/10","html_url":"https://github.com/nextcloud/server/milestone/10","labels_url":"https://api.github.com/repos/nextcloud/server/milestones/10/labels","id":2136652,"number":10,"title":"Nextcloud 12.0","description":null,"creator":{"login":"jancborchardt","id":925062,"avatar_url":"https://avatars1.githubusercontent.com/u/925062?v=3","gravatar_id":"","url":"https://api.github.com/users/jancborchardt","html_url":"https://github.com/jancborchardt","followers_url":"https://api.github.com/users/jancborchardt/followers","following_url":"https://api.github.com/users/jancborchardt/following{/other_user}","gists_url":"https://api.github.com/users/jancborchardt/gists{/gist_id}","starred_url":"https://api.github.com/users/jancborchardt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jancborchardt/subscriptions","organizations_url":"https://api.github.com/users/jancborchardt/orgs","repos_url":"https://api.github.com/users/jancborchardt/repos","events_url":"https://api.github.com/users/jancborchardt/events{/privacy}","received_events_url":"https://api.github.com/users/jancborchardt/received_events","type":"User","site_admin":false},"open_issues":135,"closed_issues":729,"state":"open","created_at":"2016-11-15T13:57:13Z","updated_at":"2017-04-13T20:54:04Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/nextcloud/server/pulls/4346/commits","review_comments_url":"https://api.github.com/repos/nextcloud/server/pulls/4346/comments","review_comment_url":"https://api.github.com/repos/nextcloud/server/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nextcloud/server/issues/4346/comments","statuses_url":"https://api.github.com/repos/nextcloud/server/statuses/8149945a916447b4e7dae8182dbf0c354e7d19e8","head":{"label":"nextcloud:properly-do-bruteforce-protection-via-annotation","ref":"properly-do-bruteforce-protection-via-annotation","sha":"8149945a916447b4e7dae8182dbf0c354e7d19e8","user":{"login":"nextcloud","id":19211038,"avatar_url":"https://avatars2.githubusercontent.com/u/19211038?v=3","gravatar_id":"","url":"https://api.github.com/users/nextcloud","html_url":"https://github.com/nextcloud","followers_url":"https://api.github.com/users/nextcloud/followers","following_url":"https://api.github.com/users/nextcloud/following{/other_user}","gists_url":"https://api.github.com/users/nextcloud/gists{/gist_id}","starred_url":"https://api.github.com/users/nextcloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nextcloud/subscriptions","organizations_url":"https://api.github.com/users/nextcloud/orgs","repos_url":"https://api.github.com/users/nextcloud/repos","events_url":"https://api.github.com/users/nextcloud/events{/privacy}","received_events_url":"https://api.github.com/users/nextcloud/received_events","type":"Organization","site_admin":false},"repo":{"id":60243197,"name":"server","full_name":"nextcloud/server","owner":{"login":"nextcloud","id":19211038,"avatar_url":"https://avatars2.githubusercontent.com/u/19211038?v=3","gravatar_id":"","url":"https://api.github.com/users/nextcloud","html_url":"https://github.com/nextcloud","followers_url":"https://api.github.com/users/nextcloud/followers","following_url":"https://api.github.com/users/nextcloud/following{/other_user}","gists_url":"https://api.github.com/users/nextcloud/gists{/gist_id}","starred_url":"https://api.github.com/users/nextcloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nextcloud/subscriptions","organizations_url":"https://api.github.com/users/nextcloud/orgs","repos_url":"https://api.github.com/users/nextcloud/repos","events_url":"https://api.github.com/users/nextcloud/events{/privacy}","received_events_url":"https://api.github.com/users/nextcloud/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nextcloud/server","description":"☁️ Nextcloud server, a safe home for all your data","fork":false,"url":"https://api.github.com/repos/nextcloud/server","forks_url":"https://api.github.com/repos/nextcloud/server/forks","keys_url":"https://api.github.com/repos/nextcloud/server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nextcloud/server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nextcloud/server/teams","hooks_url":"https://api.github.com/repos/nextcloud/server/hooks","issue_events_url":"https://api.github.com/repos/nextcloud/server/issues/events{/number}","events_url":"https://api.github.com/repos/nextcloud/server/events","assignees_url":"https://api.github.com/repos/nextcloud/server/assignees{/user}","branches_url":"https://api.github.com/repos/nextcloud/server/branches{/branch}","tags_url":"https://api.github.com/repos/nextcloud/server/tags","blobs_url":"https://api.github.com/repos/nextcloud/server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nextcloud/server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nextcloud/server/git/refs{/sha}","trees_url":"https://api.github.com/repos/nextcloud/server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nextcloud/server/statuses/{sha}","languages_url":"https://api.github.com/repos/nextcloud/server/languages","stargazers_url":"https://api.github.com/repos/nextcloud/server/stargazers","contributors_url":"https://api.github.com/repos/nextcloud/server/contributors","subscribers_url":"https://api.github.com/repos/nextcloud/server/subscribers","subscription_url":"https://api.github.com/repos/nextcloud/server/subscription","commits_url":"https://api.github.com/repos/nextcloud/server/commits{/sha}","git_commits_url":"https://api.github.com/repos/nextcloud/server/git/commits{/sha}","comments_url":"https://api.github.com/repos/nextcloud/server/comments{/number}","issue_comment_url":"https://api.github.com/repos/nextcloud/server/issues/comments{/number}","contents_url":"https://api.github.com/repos/nextcloud/server/contents/{+path}","compare_url":"https://api.github.com/repos/nextcloud/server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nextcloud/server/merges","archive_url":"https://api.github.com/repos/nextcloud/server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nextcloud/server/downloads","issues_url":"https://api.github.com/repos/nextcloud/server/issues{/number}","pulls_url":"https://api.github.com/repos/nextcloud/server/pulls{/number}","milestones_url":"https://api.github.com/repos/nextcloud/server/milestones{/number}","notifications_url":"https://api.github.com/repos/nextcloud/server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nextcloud/server/labels{/name}","releases_url":"https://api.github.com/repos/nextcloud/server/releases{/id}","deployments_url":"https://api.github.com/repos/nextcloud/server/deployments","created_at":"2016-06-02T07:44:14Z","updated_at":"2017-04-13T17:24:17Z","pushed_at":"2017-04-13T21:05:42Z","git_url":"git://github.com/nextcloud/server.git","ssh_url":"git@github.com:nextcloud/server.git","clone_url":"https://github.com/nextcloud/server.git","svn_url":"https://github.com/nextcloud/server","homepage":"https://nextcloud.com","size":237072,"stargazers_count":1701,"watchers_count":1701,"language":"PHP","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":276,"mirror_url":null,"open_issues_count":758,"forks":276,"open_issues":758,"watchers":1701,"default_branch":"master"}},"base":{"label":"nextcloud:master","ref":"master","sha":"d0c0f6cfc1871c90cd43d3b005206a360b5bb540","user":{"login":"nextcloud","id":19211038,"avatar_url":"https://avatars2.githubusercontent.com/u/19211038?v=3","gravatar_id":"","url":"https://api.github.com/users/nextcloud","html_url":"https://github.com/nextcloud","followers_url":"https://api.github.com/users/nextcloud/followers","following_url":"https://api.github.com/users/nextcloud/following{/other_user}","gists_url":"https://api.github.com/users/nextcloud/gists{/gist_id}","starred_url":"https://api.github.com/users/nextcloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nextcloud/subscriptions","organizations_url":"https://api.github.com/users/nextcloud/orgs","repos_url":"https://api.github.com/users/nextcloud/repos","events_url":"https://api.github.com/users/nextcloud/events{/privacy}","received_events_url":"https://api.github.com/users/nextcloud/received_events","type":"Organization","site_admin":false},"repo":{"id":60243197,"name":"server","full_name":"nextcloud/server","owner":{"login":"nextcloud","id":19211038,"avatar_url":"https://avatars2.githubusercontent.com/u/19211038?v=3","gravatar_id":"","url":"https://api.github.com/users/nextcloud","html_url":"https://github.com/nextcloud","followers_url":"https://api.github.com/users/nextcloud/followers","following_url":"https://api.github.com/users/nextcloud/following{/other_user}","gists_url":"https://api.github.com/users/nextcloud/gists{/gist_id}","starred_url":"https://api.github.com/users/nextcloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nextcloud/subscriptions","organizations_url":"https://api.github.com/users/nextcloud/orgs","repos_url":"https://api.github.com/users/nextcloud/repos","events_url":"https://api.github.com/users/nextcloud/events{/privacy}","received_events_url":"https://api.github.com/users/nextcloud/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nextcloud/server","description":"☁️ Nextcloud server, a safe home for all your data","fork":false,"url":"https://api.github.com/repos/nextcloud/server","forks_url":"https://api.github.com/repos/nextcloud/server/forks","keys_url":"https://api.github.com/repos/nextcloud/server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nextcloud/server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nextcloud/server/teams","hooks_url":"https://api.github.com/repos/nextcloud/server/hooks","issue_events_url":"https://api.github.com/repos/nextcloud/server/issues/events{/number}","events_url":"https://api.github.com/repos/nextcloud/server/events","assignees_url":"https://api.github.com/repos/nextcloud/server/assignees{/user}","branches_url":"https://api.github.com/repos/nextcloud/server/branches{/branch}","tags_url":"https://api.github.com/repos/nextcloud/server/tags","blobs_url":"https://api.github.com/repos/nextcloud/server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nextcloud/server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nextcloud/server/git/refs{/sha}","trees_url":"https://api.github.com/repos/nextcloud/server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nextcloud/server/statuses/{sha}","languages_url":"https://api.github.com/repos/nextcloud/server/languages","stargazers_url":"https://api.github.com/repos/nextcloud/server/stargazers","contributors_url":"https://api.github.com/repos/nextcloud/server/contributors","subscribers_url":"https://api.github.com/repos/nextcloud/server/subscribers","subscription_url":"https://api.github.com/repos/nextcloud/server/subscription","commits_url":"https://api.github.com/repos/nextcloud/server/commits{/sha}","git_commits_url":"https://api.github.com/repos/nextcloud/server/git/commits{/sha}","comments_url":"https://api.github.com/repos/nextcloud/server/comments{/number}","issue_comment_url":"https://api.github.com/repos/nextcloud/server/issues/comments{/number}","contents_url":"https://api.github.com/repos/nextcloud/server/contents/{+path}","compare_url":"https://api.github.com/repos/nextcloud/server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nextcloud/server/merges","archive_url":"https://api.github.com/repos/nextcloud/server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nextcloud/server/downloads","issues_url":"https://api.github.com/repos/nextcloud/server/issues{/number}","pulls_url":"https://api.github.com/repos/nextcloud/server/pulls{/number}","milestones_url":"https://api.github.com/repos/nextcloud/server/milestones{/number}","notifications_url":"https://api.github.com/repos/nextcloud/server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nextcloud/server/labels{/name}","releases_url":"https://api.github.com/repos/nextcloud/server/releases{/id}","deployments_url":"https://api.github.com/repos/nextcloud/server/deployments","created_at":"2016-06-02T07:44:14Z","updated_at":"2017-04-13T17:24:17Z","pushed_at":"2017-04-13T21:05:42Z","git_url":"git://github.com/nextcloud/server.git","ssh_url":"git@github.com:nextcloud/server.git","clone_url":"https://github.com/nextcloud/server.git","svn_url":"https://github.com/nextcloud/server","homepage":"https://nextcloud.com","size":237072,"stargazers_count":1701,"watchers_count":1701,"language":"PHP","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":276,"mirror_url":null,"open_issues_count":758,"forks":276,"open_issues":758,"watchers":1701,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nextcloud/server/pulls/4346"},"html":{"href":"https://github.com/nextcloud/server/pull/4346"},"issue":{"href":"https://api.github.com/repos/nextcloud/server/issues/4346"},"comments":{"href":"https://api.github.com/repos/nextcloud/server/issues/4346/comments"},"review_comments":{"href":"https://api.github.com/repos/nextcloud/server/pulls/4346/comments"},"review_comment":{"href":"https://api.github.com/repos/nextcloud/server/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nextcloud/server/pulls/4346/commits"},"statuses":{"href":"https://api.github.com/repos/nextcloud/server/statuses/8149945a916447b4e7dae8182dbf0c354e7d19e8"}}}}
{"actor":{"display_login":"rullzer"}}