3737use OC \Authentication \Exceptions \PasswordLoginForbiddenException ;
3838use OC \Authentication \TwoFactorAuth \Manager ;
3939use OC \Security \Bruteforce \Throttler ;
40+ use OC \Security \CSRF \CsrfValidator ;
4041use OC \User \Session ;
4142use OCA \DAV \Connector \Sabre \Exception \PasswordLoginForbidden ;
4243use OCA \DAV \Connector \Sabre \Exception \TooManyRequests ;
@@ -60,17 +61,21 @@ class Auth extends AbstractBasic {
6061 private Manager $ twoFactorManager ;
6162 private Throttler $ throttler ;
6263
64+ private CsrfValidator $ csrfValidator ;
65+
6366 public function __construct (ISession $ session ,
6467 Session $ userSession ,
6568 IRequest $ request ,
6669 Manager $ twoFactorManager ,
6770 Throttler $ throttler ,
71+ CsrfValidator $ csrfValidator ,
6872 string $ principalPrefix = 'principals/users/ ' ) {
6973 $ this ->session = $ session ;
7074 $ this ->userSession = $ userSession ;
7175 $ this ->twoFactorManager = $ twoFactorManager ;
7276 $ this ->request = $ request ;
7377 $ this ->throttler = $ throttler ;
78+ $ this ->csrfValidator = $ csrfValidator ;
7479 $ this ->principalPrefix = $ principalPrefix ;
7580
7681 // setup realm
@@ -190,7 +195,7 @@ private function requiresCSRFCheck(): bool {
190195 private function auth (RequestInterface $ request , ResponseInterface $ response ): array {
191196 $ forcedLogout = false ;
192197
193- if (!$ this ->request -> passesCSRFCheck ( ) &&
198+ if (!$ this ->csrfValidator -> validate ( $ this -> request ) &&
194199 $ this ->requiresCSRFCheck ()) {
195200 // In case of a fail with POST we need to recheck the credentials
196201 if ($ this ->request ->getMethod () === 'POST ' ) {
@@ -223,7 +228,7 @@ private function auth(RequestInterface $request, ResponseInterface $response): a
223228
224229 if (!$ this ->userSession ->isLoggedIn () && in_array ('XMLHttpRequest ' , explode (', ' , $ request ->getHeader ('X-Requested-With ' ) ?? '' ))) {
225230 // do not re-authenticate over ajax, use dummy auth name to prevent browser popup
226- $ response ->addHeader ('WWW-Authenticate ' ,'DummyBasic realm=" ' . $ this ->realm . '" ' );
231+ $ response ->addHeader ('WWW-Authenticate ' , 'DummyBasic realm=" ' . $ this ->realm . '" ' );
227232 $ response ->setStatus (401 );
228233 throw new \Sabre \DAV \Exception \NotAuthenticated ('Cannot authenticate over ajax calls ' );
229234 }
0 commit comments