loadComponent('Flash'); } /** * Security headers for every HTML response. * * @param \Cake\Event\EventInterface<\Cake\Controller\Controller> $event Event * @return void */ public function beforeRender(EventInterface $event): void { parent::beforeRender($event); $this->response = $this->response ->withHeader('X-Content-Type-Options', 'nosniff') ->withHeader('X-Frame-Options', 'SAMEORIGIN') ->withHeader('Referrer-Policy', 'same-origin'); } /** * Returns a JSON response without going through the view layer. * * @param array $data Payload * @param int $status HTTP status * @return \Cake\Http\Response */ protected function json(array $data, int $status = 200): Response { return $this->response ->withStatus($status) ->withType('application/json') ->withHeader('Cache-Control', 'no-store') ->withStringBody((string)json_encode($data, JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR)); } }