0

有没有办法填充 SameSite cookie 属性,以便我可以将此功能与旧版浏览器或特定浏览器的旧版本一起使用?

https://caniuse.com/#feat=same-site-cookie-attribute

4

1 回答 1

1

我想我必须在反向代理中解决这个问题:

const express = require('express');
const cp = require('cookie-parser');
const app = express();
app.use(cp());

app.get('/set', (req, res) => {
  // Set the new style cookie
  res.cookie('3pcookie', 'value', { sameSite: 'none', secure: true });
  // And set the same value in the legacy cookie
  res.cookie('3pcookie-legacy', 'value', { secure: true });
  res.end();
});

app.get('/', (req, res) => {
  let cookieVal = null;

  if (req.cookies['3pcookie']) {
    // check the new style cookie first
    cookieVal = req.cookies['3pcookie'];
  } else if (req.cookies['3pcookie-legacy']) {
    // otherwise fall back to the legacy cookie
    cookieVal = req.cookies['3pcookie-legacy'];
  }

  res.end();
});

app.listen(process.env.PORT);

https://web.dev/samesite-cookie-recipes/

于 2020-01-29T16:07:58.980 回答