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

234
Visualizações
Cookie set with javascript disappears after refresh

I'm setting my cookies like this:

document.cookie = `${cookieName}=${JSON.stringify(cookieObject)};path=/;SameSite=Strict;Secure=true;expires=${someDate.toUTCString()};`

Everything is fine at first. But when I refresh, the cookie disappears and firefox console tells me a message:

Cookie “thecookiename” will be soon rejected because it has the “SameSite” attribute set to “None” or an invalid value, without the “secure” attribute.

If I refresh again, the message disappears and the cookie is also gone.

Chrome acts the same, but minus the message.

Edit

I realized, the problem might be related to the fact, that I'm overriding the document.cookie setter.

document.setCookie = document.__lookupSetter__('cookie');
document.newCookieSetter= (cookie) => {
    // here I check, whether a cookie is allowed or not. Calls for an api endpoint to get the information.

    if (cookieDataRecieved() && cookieIsAllowed(cookie)) {
        return document.setCookie(cookie);
    }
    cacheCookie(cookie); // If cookie data has loaded, try checking again.  
}

document.__defineSetter__('cookie', document.newCookieSetter);

The problem applies to every cookie added through the document.cookie = "somecookie";

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The Secure attribute has no value, it's just a bare attribute (present or absent), so just replace Secure=true with Secure.

about 4 years ago · Juan Pablo Isaza 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