问题原文
原帖链接 · jamieweb · CC BY-SA 3.0
Is it possible to block cookies that are set by externally hosted content embedded in a page?
For example if I embed an image from a CDN, the response for this image may contain a Set-Cookie header, which results in the cookie showing up for my site.
Just to clarify, I am not asking whether it's possible to do this with client-side browser configurations. I'm asking whether there is something I can do as the website owner in order to prevent cookies being set by images hosted on a separate server.
I don't believe this is possible, I am just asking here in case I missed something.
已采纳解答
原帖链接 · MrWhite · CC BY-SA 3.0
You have no control over cookies that might be set by an external resource on a different domain. These (third party) cookies are set on the "external domain", not the domain of your site. Fundamental browser/cookie security prevents you from accessing these cookies (client-side) and the browser will never send these cookies back to your domain, so you will not see them server-side.
However, the user can disable third-party cookies in their browser if they wish.
Theoretically, instead of linking directly to the external resource/CDN, you could link to a URL-path on your own domain (or a subdomain) instead. You then setup a reverse proxy on your server to make requests to the external resource and send this to the client. Then, any cookies the external resource tries to set will fail (domain mismatch) - or you could strip the Set-Cookie header in the response. However, this really defeats some of the advantages of using a CDN in the first place, since the request is being routed via your server.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
