Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: enable csrf token to be read from request headers #2586

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public function onKernelRequest(RequestEvent $event): void
}

$tokenId = $request->request->get('_token');
if ($request->headers->has('x-csrf-token')) {
$tokenId = $request->headers->get('x-csrf-token');
}

if (null === $tokenId) {
$this->messageBag->add('dev', 'error.csrf.missing', ['uri' => $request->getRequestUri()]);
$this->logger->info('CSRF token missing', ['uri' => $request->getRequestUri()]);
Expand All @@ -44,6 +48,7 @@ public function onKernelRequest(RequestEvent $event): void
}

$token = $this->csrfTokenManager->getToken($tokenId);

if ($token instanceof CsrfToken && $this->csrfTokenManager->isTokenValid($token)) {
// all clear, token is set and valid
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ window.dplan = {
roles: "{{ currentUser.roles|default([])|json_encode }}"
},
sentryDsn : "{{ sentry_dsn|default }}",
csrfToken : "{{ csrf_token('csrf')|json_encode }}",
jwtToken : "{{ jwtToken|default }}",

defaultProjectionLabel : "{{ defaultProjectionLabel() }}",
Expand Down