【问题标题】:Amazon AWS bucket policy - Safari browser not sending referer information亚马逊 AWS 存储桶策略 - Safari 浏览器不发送推荐人信息
【发布时间】:2014-09-24 04:12:08
【问题描述】:

我有以下 AWS 存储桶策略来限制对我的 Amazon S3 网址的访问:

{
"Version": "2008-10-17",
"Statement": [
    {
        "Sid": "Allowinmydomains",
        "Effect": "Allow",
        "Principal": {
            "AWS": "*"
        },
        "Action": "s3:GetObject",
        "Resource": "arn:aws:s3:::MyBucket/*",
        "Condition": {
            "StringLike": {
                "aws:Referer": [
                    "http://www.example.com/*",
                    "http://example.com/*"
                ]
            }
        }
    },
    {
        "Sid": "Givenotaccessifrefererisnomysites",
        "Effect": "Deny",
        "Principal": {
            "AWS": "*"
        },
        "Action": "s3:GetObject",
        "Resource": "arn:aws:s3:::MyBucket/*",
        "Condition": {
            "StringNotLike": {
                "aws:Referer": [
                    "http://www.example.com/*",
                    "http://example.com/*"
                ]
            }
        }
    }
]
}

上述存储桶策略适用于除 Safari 之外的所有浏览器。在网上做研究,据说是因为 Safari 浏览器没有发送任何referer 标头而无法正常工作。

是否有任何方法可以使此存储桶策略适用于所有浏览器,或者是否有其他方法可以拒绝访问 Amazon 存储桶以防止从我的站点外进行热链接和下载文件?

谢谢!

【问题讨论】:

  • 您在哪里找到有关 Safari 不发送 Referer 标头的信息?你真的观察过这种行为吗?

标签: amazon-web-services amazon-s3 safari amazon


【解决方案1】:

尝试以下存储桶策略。您需要确保您的 ACL 不允许公开访问您的文件,并且您的存储桶策略中没有任何其他允许访问的规则(通过绕过这些规则):

{
  "Version":"2008-10-17",
  "Id":"Bucket policy",
  "Statement":[
    {
      "Sid":"Allow GET requests referred by www.example.com and example.com",
      "Effect":"Allow",
      "Principal":"*",
      "Action":"s3:GetObject",
      "Resource":"arn:aws:s3:::example-bucket/*",
      "Condition":{
        "StringLike":{
          "aws:Referer":[
            "http://www.example.com/*",
            "http://example.com/*"
          ]
        }
      }
    },
    {
      "Sid":"Allow GET requests that don't specify a referrer (e.g. from Safari, Flash, etc.)",
      "Effect":"Allow",
      "Principal":"*",
      "Action":"s3:GetObject",
      "Resource":"arn:aws:s3:::example-bucket/*",
      "Condition":{
        "Null":{
          "aws:Referer":true
        }
      }
    }
  ]
}

【讨论】:

    【解决方案2】:

    另一种选择是为 Safari 强制使用 referrer

    <meta name="referrer" content="always">
    

    或:

    <meta content="origin" id="mref" name="referrer">
    

    【讨论】:

      猜你喜欢
      • 2011-02-09
      • 1970-01-01
      • 1970-01-01
      • 2017-03-03
      • 2012-11-15
      • 2012-03-05
      • 1970-01-01
      • 1970-01-01
      • 2019-11-13
      相关资源
      最近更新 更多