File tree Expand file tree Collapse file tree 4 files changed +35
-1
lines changed
Authentication/Authenticators Expand file tree Collapse file tree 4 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 1515use CodeIgniter \Shield \Entities \UserIdentity ;
1616use CodeIgniter \Shield \Exceptions \InvalidArgumentException ;
1717use CodeIgniter \Shield \Exceptions \LogicException ;
18+ use CodeIgniter \Shield \Exceptions \SecurityException ;
1819use CodeIgniter \Shield \Models \LoginModel ;
1920use CodeIgniter \Shield \Models \RememberModel ;
2021use CodeIgniter \Shield \Models \UserIdentityModel ;
2122use CodeIgniter \Shield \Models \UserModel ;
2223use CodeIgniter \Shield \Result ;
24+ use Config \Security ;
2325use Config \Services ;
2426use stdClass ;
2527
@@ -73,6 +75,25 @@ public function __construct(UserModel $provider)
7375 $ this ->loginModel = model (LoginModel::class);
7476 $ this ->rememberModel = model (RememberModel::class);
7577 $ this ->userIdentityModel = model (UserIdentityModel::class);
78+
79+ $ this ->checkSecurityConfig ();
80+ }
81+
82+ /**
83+ * Checks less secure Configuration.
84+ */
85+ private function checkSecurityConfig (): void
86+ {
87+ /** @var Security $securityConfig */
88+ $ securityConfig = config ('Security ' );
89+
90+ if ($ securityConfig ->csrfProtection === 'cookie ' ) {
91+ throw new SecurityException (
92+ 'Config\Security::$csrfProtection is set to \'cookie \'. '
93+ . ' Same-site attackers may bypass the CSRF protection. '
94+ . ' Please set it to \'session \'. '
95+ );
96+ }
7697 }
7798
7899 /**
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace CodeIgniter \Shield \Exceptions ;
4+
5+ use RuntimeException ;
6+
7+ class SecurityException extends RuntimeException
8+ {
9+ }
Original file line number Diff line number Diff line change @@ -30,7 +30,6 @@ protected function setUp(): void
3030 parent ::setUp ();
3131
3232 helper ('auth ' );
33- Factories::reset ();
3433
3534 // Add auth routes
3635 $ routes = service ('routes ' );
Original file line number Diff line number Diff line change @@ -33,5 +33,10 @@ protected function setUp(): void
3333 $ config = config ('Auth ' );
3434 $ config ->actions = ['login ' => null , 'register ' => null ];
3535 Factories::injectMock ('config ' , 'Auth ' , $ config );
36+
37+ // Set Config\Security::$csrfProtection to 'session'
38+ $ config = config ('Security ' );
39+ $ config ->csrfProtection = 'session ' ;
40+ Factories::injectMock ('config ' , 'Security ' , $ config );
3641 }
3742}
You can’t perform that action at this time.
0 commit comments