@@ -64,11 +64,28 @@ public function initialize(): void
6464
6565 public function create (): ?Response
6666 {
67+ $ this ->disableAutoRender ();
68+ $ this ->response = $ this ->response
69+ ->withHeader ('Content-Type ' , 'application/json ' )
70+ ->withHeader ('X-Content-Type-Options ' , 'nosniff ' );
71+
6772 // Only allow POST requests
6873 $ this ->request ->allowMethod (['post ' ]);
6974
7075 $ requestBody = (string ) $ this ->request ->getBody ();
7176 $ bugReport = json_decode ($ requestBody , true );
77+
78+ if ($ bugReport === null || $ bugReport === false || $ requestBody === '' ) {
79+ $ response = ['success ' => false ];
80+
81+ $ this ->response = $ this ->response
82+ ->withStringBody (
83+ json_encode ($ response , JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES )
84+ );
85+
86+ return $ this ->response ;
87+ }
88+
7289 $ result = $ this ->Incidents ->createIncidentFromBugReport ($ bugReport );
7390
7491 $ sentryConfig = Configure::read ('Forwarding.Sentry ' );
@@ -81,20 +98,12 @@ public function create(): ?Response
8198 count ($ result ['incidents ' ]) > 0
8299 && ! in_array (false , $ result ['incidents ' ])
83100 ) {
84- $ response = [
85- 'success ' => true ,
86- ];
101+ $ response = ['success ' => true ];
87102 } else {
88- $ response = [
89- 'success ' => false ,
90- ];
103+ $ response = ['success ' => false ];
91104 }
92105
93- $ this ->disableAutoRender ();
94-
95106 $ this ->response = $ this ->response
96- ->withHeader ('Content-Type ' , 'application/json ' )
97- ->withHeader ('X-Content-Type-Options ' , 'nosniff ' )
98107 ->withStringBody (
99108 json_encode ($ response , JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES )
100109 );
0 commit comments