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

跨域 cross-origin 和跨站 cross-site 是不同的概念 #255

Open
islishude opened this issue Sep 6, 2023 · 0 comments
Open

跨域 cross-origin 和跨站 cross-site 是不同的概念 #255

islishude opened this issue Sep 6, 2023 · 0 comments
Labels

Comments

@islishude
Copy link
Owner

islishude commented Sep 6, 2023

跨域一般用于同源策略,不同的协议、主机以及端口都算作跨域:

  • 协议不同 http://example.comhttps://example.com
  • 主机不同,即使二级域名相同 https://www.example.comhttps://example.com
  • 端口不同 http://example.com:80http://example.com:8080

跨站一般用于 cookie 配置,不区分协议和端口:

比如 www.example.comexample.com 就是同站。

这并不是说不区分二级域名,例如很多带有国家顶级域名的 .com.cn,所以使用二级域名区分是行不通的。

严格意义上说,需要保证主机名后缀定义在 公共后缀列表 中。

例如,github.io 就被定义在这个列表中。

所以,first.github.iosecond.github.io 不能算作同站。

另外 chrome 会发送 Sec-Fetch-Site 请求头来标识当前请求的来源:

  • cross-site
  • same-site
  • same-origin
  • none
@islishude islishude added the Web label Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant