amazon-cloudfront - Amazon Cloudfront 删除 Referer header

标签 amazon-cloudfront referer

我正在使用 Amazon CloudFront 传送一些 HDS 文件。我有一个原始服务器,它检查 HTTP HEADER REFERER,如果不允许,它会阻止它。

问题是云前端正在删除引用 header ,因此它不会转发到源。

是否可以告诉亚马逊不要这样做?

最佳答案

在写完下面的答案后几天内,Cloudfront 就已经宣布了更改。 Cloudfront 现在将传递您选择的 header ,并且可以添加一些自己的 header 。

但是,我下面所说的大部分内容仍然是正确的。请注意,在公告中,提供了一个选项来转发所有 header ,正如我所建议的那样,这将有效地禁用缓存。还有一个转发特定 header 的选项,这将导致 Cloudfront 根据完整的转发 header 集(而不仅仅是 uri)缓存对象,这意味着缓存的有效性会有所降低,因为 Cloudfront 别无选择,只能假设包含 header 可能会修改服务器将为该请求生成的响应。

Each of your CloudFront distributions now contains a list of headers that are to be forwarded to the origin server. You have three options:

None - This option requests the original behavior.

All - This option forwards all headers and effectively disables all caching at the edge.

Whitelist - This option give you full control of the headers that are to be forwarded. The list starts out empty, and grows as you add more headers. You can add common HTTP headers by choosing them from a list. You can also add "custom" headers by simply entering the name.

If you choose the Whitelist option, each header that you add to the list becomes part of the cache key for the URLs associated with the distribution. Adding a header to the list simply tells CloudFront that the value of the header can affect the content returned by the origin server.

http://aws.amazon.com/blogs/aws/enhanced-cloudfront-customization/

<小时/>

Cloudfront 确实删除了 Referer header 以及其他几个在缓存内容领域中没有特别意义(或者其存在会导致不合逻辑的后果)的 header 。

http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/RequestAndResponseBehaviorCustomOrigin.html

就像 cookies 一样,如果允许保留 Referer: header ,以便源端可以看到它并对其使用react,这意味着应该根据请求以及引用页面,这似乎在很大程度上破坏了对象的可缓存性。否则,如果源端确实对不需要的引用者使用react并发送无缓存响应,那么在第一个合法请求进入之前一切都很好,对其响应将提供给后续请求者,无论其引用者如何,也很大程度上违背了目的。

RFC-2616 第 13 节要求缓存返回一个已“检查与源服务器返回的内容是否相等”的响应,这意味着该响应基于全部有效请求中的 header 。

同样的事情也适用于 User-agent 和源服务器可能用来修改其响应的其他 header ...如果您需要在源服务器上对这些值使用react,那么没有什么明显的目的通过 CDN 为他们提供服务。

引用基于页面的测试是一种非常原始的措施,许多人使用它们的方式,因为标题很容易伪造。

如果您正在处理一个您无法控制的平台,并且这是您需要覆盖的内容(使用虚拟值,只是为了让现有系统“满意”),那么在该平台前面的反向代理源服务器可以达到这样的目的,Cloudfront 使用反向代理作为其源。

关于amazon-cloudfront - Amazon Cloudfront 删除 Referer header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24343001/

相关文章:

java - AWS Java SDK2 中 CloudFrontUrlSigner 的替代品

python - 无法使用 boto 签署云端 URL

java - 如何通过 Spring Rest api 生成 aws cloudfront url?

ruby-on-rails - 带有 anchor 的 request.referer

javascript - 在这个上下文中实现的这段JS代码有什么问题吗?

php - 如何仅允许白名单网站嵌入 iframe?

javascript - 我可以获得原始推荐网站的网址推荐吗?

angularjs - 更改 Cloudfront 下载分发源路径是否会导致缓存失效?

amazon-web-services - 是否可以通过 Cloudformation 在 CloundFront 中配置自定义对象缓存 TTL?

javascript - Mechanize + Python : how to follow a link in a simple javascript?