3838use OCP \AppFramework \Utility \ITimeFactory ;
3939use OCP \BackgroundJob \IJobList ;
4040use OCP \IRequest ;
41+ use OCP \Security \Bruteforce \IThrottler ;
4142use OCP \Security \ISecureRandom ;
4243use Psr \Log \LoggerInterface ;
4344
@@ -56,6 +57,7 @@ class OCSAuthAPIController extends OCSController {
5657 private DbHandler $ dbHandler ;
5758 private LoggerInterface $ logger ;
5859 private ITimeFactory $ timeFactory ;
60+ private IThrottler $ throttler ;
5961
6062 public function __construct (
6163 string $ appName ,
@@ -65,7 +67,8 @@ public function __construct(
6567 TrustedServers $ trustedServers ,
6668 DbHandler $ dbHandler ,
6769 LoggerInterface $ logger ,
68- ITimeFactory $ timeFactory
70+ ITimeFactory $ timeFactory ,
71+ IThrottler $ throttler
6972 ) {
7073 parent ::__construct ($ appName , $ request );
7174
@@ -75,13 +78,15 @@ public function __construct(
7578 $ this ->dbHandler = $ dbHandler ;
7679 $ this ->logger = $ logger ;
7780 $ this ->timeFactory = $ timeFactory ;
81+ $ this ->throttler = $ throttler ;
7882 }
7983
8084 /**
8185 * Request received to ask remote server for a shared secret, for legacy end-points
8286 *
8387 * @NoCSRFRequired
8488 * @PublicPage
89+ * @BruteForceProtection(action=federationSharedSecret)
8590 *
8691 * @param string $url URL of the server
8792 * @param string $token Token of the server
@@ -100,6 +105,7 @@ public function requestSharedSecretLegacy(string $url, string $token): DataRespo
100105 *
101106 * @NoCSRFRequired
102107 * @PublicPage
108+ * @BruteForceProtection(action=federationSharedSecret)
103109 *
104110 * @param string $url URL of the server
105111 * @param string $token Token of the server
@@ -117,6 +123,7 @@ public function getSharedSecretLegacy(string $url, string $token): DataResponse
117123 *
118124 * @NoCSRFRequired
119125 * @PublicPage
126+ * @BruteForceProtection(action=federationSharedSecret)
120127 *
121128 * @param string $url URL of the server
122129 * @param string $token Token of the server
@@ -127,6 +134,7 @@ public function getSharedSecretLegacy(string $url, string $token): DataResponse
127134 */
128135 public function requestSharedSecret (string $ url , string $ token ): DataResponse {
129136 if ($ this ->trustedServers ->isTrustedServer ($ url ) === false ) {
137+ $ this ->throttler ->registerAttempt ('federationSharedSecret ' , $ this ->request ->getRemoteAddress ());
130138 $ this ->logger ->error ('remote server not trusted ( ' . $ url . ') while requesting shared secret ' , ['app ' => 'federation ' ]);
131139 throw new OCSForbiddenException ();
132140 }
@@ -159,6 +167,7 @@ public function requestSharedSecret(string $url, string $token): DataResponse {
159167 *
160168 * @NoCSRFRequired
161169 * @PublicPage
170+ * @BruteForceProtection(action=federationSharedSecret)
162171 *
163172 * @param string $url URL of the server
164173 * @param string $token Token of the server
@@ -169,11 +178,13 @@ public function requestSharedSecret(string $url, string $token): DataResponse {
169178 */
170179 public function getSharedSecret (string $ url , string $ token ): DataResponse {
171180 if ($ this ->trustedServers ->isTrustedServer ($ url ) === false ) {
181+ $ this ->throttler ->registerAttempt ('federationSharedSecret ' , $ this ->request ->getRemoteAddress ());
172182 $ this ->logger ->error ('remote server not trusted ( ' . $ url . ') while getting shared secret ' , ['app ' => 'federation ' ]);
173183 throw new OCSForbiddenException ();
174184 }
175185
176186 if ($ this ->isValidToken ($ url , $ token ) === false ) {
187+ $ this ->throttler ->registerAttempt ('federationSharedSecret ' , $ this ->request ->getRemoteAddress ());
177188 $ expectedToken = $ this ->dbHandler ->getToken ($ url );
178189 $ this ->logger ->error (
179190 'remote server ( ' . $ url . ') didn \'t send a valid token (got " ' . $ token . '" but expected " ' . $ expectedToken . '") while getting shared secret ' ,
0 commit comments