Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

194
Visualizações
Is it possible to rename the XSRF-TOKEN cookie that Laravel is creating?

My Laravel application is hosted on the same domain name (one application on only one subdomain, the other one on multiple subdomains) as another web application that use a XSRF-TOKEN cookie. The two cookies are conflicting. Is there any way to rename Laravel's cookie to something like XSRF-TOKEN_Second? I am using Laravel version 6. I apologize if the question was asked before, couldn't find an answer. Thanks!


My solution

The problem was, in .env APP_NAME had same value on both projects. Rename one and it will change the name of the session and no more conflicts.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You can set your own token by modifying the response:

$response->headers->setCookie(
  new Cookie(
    'NEW-XSRF-TOKEN-NAME', 
    $request->session()->token(), 
    $this->availableAt(60 * $config['lifetime']),
    $config['path'], 
    $config['domain'], 
    $config['secure'], 
    false, 
    false, 
    $config['same_site'] ?? null
    )
);

And you should update your middleware for checking the new token. X-XSRF-TOKEN, as per their docs, is just there for developer convenience. However, I still urge you not to write your own csrf logic.

over 4 years ago · Santiago Trujillo Relatório

0

I was facing the same problem with 2 laravel apps on the same domain that communicate with each other, eg:

https://example.com/store/
https://example.com/gateway/

The CSRF tokens were competing with each other. It turns out that the easiest way to fix it was to set the session cookie path in config/session.php as follows:

    /*
    |--------------------------------------------------------------------------
    | Session Cookie Path
    |--------------------------------------------------------------------------
    |
    | The session cookie path determines the path for which the cookie will
    | be regarded as available. Typically, this will be the root path of
    | your application but you are free to change this when necessary.
    |
    */

    // fixes conflicts between store and gateway CSRF tokens
    'path' => '/store/',

and the same on the gateway:

    'path' => '/gateway/',

Update: It's actually better not to hardcode the session cookie path, so the APP_URL can be changed later without breaking. Here's the code update:

    'path' => parse_url(env('APP_URL'), PHP_URL_PATH),
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda