大网数据广告活动
网站运营与故障问答

Is it possible to block cookies that are set by externally hosted content?

· 52CE 我爱测

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 sh…

问题原文

原帖链接 · 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2018-03-14)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。