eggjs / eggjs/egg

egg-security 是否应该支持 csrf 设置 sameSite 呢?

Open
#4,939 0 comments 0 reactions 0 assignees View on GitHub
Inactive
Dominant language
TypeScript
Stars
19k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

## 场景描述

在外部平台 a.com 通过 iframe 嵌入我方应用 b.com 时,自然会出现cookie sameSite 的问题。cookie 的 sameSite 已通过 config.session 去设置 sameSite 解决。
但发现 csrf 使用的是 cookie 存储的,所以这个 csrf 的值自然无法自然的设置成 sameSite: none.

[security 关于 cookie csrf 的操作的源代码](https://github.com/eggjs/egg-security/blob/61a5543391d6a29050ddf12d39d3997811143852/app/extend/context.js#L113)

## 期望

- [ ] 提供可以设置 sameSite 的方式。

是否可以
```ts
const cookieOpts = {
domain: cookieDomain && cookieDomain(this),
signed: false,
httpOnly: false,
+++ sameSite: config.session.sameSite,
overwrite: true,
};
```

## 相关环境信息
- **操作系统**: 无关
- **Node 版本**:无关
- **Egg 版本**:latest

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.