File tree Expand file tree Collapse file tree 4 files changed +25
-0
lines changed
tests/bundle/EventListener Expand file tree Collapse file tree 4 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -104,6 +104,10 @@ public function onKernelRequest(RequestEvent $event)
104104 return ;
105105 }
106106
107+ if (!$ event ->getRequest ()->attributes ->getBoolean ('csrf_protection ' , true )) {
108+ return ;
109+ }
110+
107111 if (!$ this ->checkCsrfToken ($ event ->getRequest ())) {
108112 throw new UnauthorizedException (
109113 'Missing or invalid CSRF token ' ,
@@ -143,6 +147,8 @@ protected function isLoginRequest($route)
143147 * @param string $route
144148 *
145149 * @return bool
150+ *
151+ * @deprecated since Ibexa DXP 3.3.7. Add csrf_protection: false attribute to route definition instead.
146152 */
147153 protected function isSessionRoute ($ route )
148154 {
Original file line number Diff line number Diff line change @@ -1118,18 +1118,21 @@ ezpublish_rest_createSession:
11181118 path : /user/sessions
11191119 defaults :
11201120 _controller : ezpublish_rest.controller.session:createSessionAction
1121+ csrf_protection : false
11211122 methods : [POST]
11221123
11231124ezpublish_rest_deleteSession :
11241125 path : /user/sessions/{sessionId}
11251126 defaults :
11261127 _controller : ezpublish_rest.controller.session:deleteSessionAction
1128+ csrf_protection : false
11271129 methods : [DELETE]
11281130
11291131ezpublish_rest_refreshSession :
11301132 path : /user/sessions/{sessionId}/refresh
11311133 defaults :
11321134 _controller : ezpublish_rest.controller.session:refreshSessionAction
1135+ csrf_protection : false
11331136 methods : [POST]
11341137
11351138
Original file line number Diff line number Diff line change @@ -137,6 +137,15 @@ public static function provideSessionRoutes()
137137 ];
138138 }
139139
140+ public function testSkipCsrfProtection (): void
141+ {
142+ $ this ->enableCsrfProtection = false ;
143+ $ this ->csrfTokenHeaderValue = null ;
144+
145+ $ listener = $ this ->getEventListener ();
146+ $ listener ->onKernelRequest ($ this ->getEvent ());
147+ }
148+
140149 public function testNoHeader ()
141150 {
142151 $ this ->expectException (UnauthorizedException::class);
Original file line number Diff line number Diff line change @@ -34,6 +34,8 @@ abstract class EventListenerTest extends TestCase
3434
3535 protected $ requestMethod = false ;
3636
37+ protected $ enableCsrfProtection = true ;
38+
3739 /**
3840 * @dataProvider provideExpectedSubscribedEventTypes
3941 */
@@ -87,6 +89,11 @@ protected function getRequestAttributesMock()
8789 ->method ('get ' )
8890 ->with ('is_rest_request ' )
8991 ->willReturn ($ this ->isRestRequest );
92+
93+ $ this ->requestAttributesMock
94+ ->method ('getBoolean ' )
95+ ->with ('csrf_protection ' , true )
96+ ->willReturn ($ this ->enableCsrfProtection );
9097 }
9198
9299 return $ this ->requestAttributesMock ;
You can’t perform that action at this time.
0 commit comments