django - 从 AWS S3 加载的 iframe 同源问题

标签 django amazon-web-services amazon-s3 cross-domain same-origin-policy

我刚刚将我的博客从 wordpress 更改为 django-zinnia。 Zinnia 在 django-admin 中使用 WYMeditor ( https://github.com/wymeditor/wymeditor ) iframe 用于博客文章文本和内容输入,现在由于同源问题我无法访问 iframe。我在浏览器控制台中看到的错误是:

Blocked a frame with origin "http://www.mydomain.com" from accessing a frame with origin "http://mybucket.s3.amazonaws.com". 
Protocols, domains, and ports must match.
WYMeditor.WymClassSafari.initIframe 
onload

我可以在存储桶的 CORS 配置中更新一个参数以允许 iframe 加载跨源吗?我已经有了

 <AllowedOrigin>http://www.mydomain.com</AllowedOrigin> 

在我当前的 CORS 规则中:

<?xml version="1.0" encoding="UTF-8"?>
    <CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
         <CORSRule>
             <AllowedOrigin>http://mydomain.herokuapp.com</AllowedOrigin>
             <AllowedOrigin>http://mydomain.com</AllowedOrigin>
             <AllowedOrigin>http://www.mydomain.com</AllowedOrigin>
             <AllowedMethod>GET</AllowedMethod>
             <MaxAgeSeconds>3000</MaxAgeSeconds>
             <AllowedHeader>Content-*</AllowedHeader>
             <AllowedHeader>Host</AllowedHeader>
             <AllowedHeader>Authorization</AllowedHeader>
        </CORSRule>
   </CORSConfiguration>

最佳答案

CORS header 不会影响 Safari 中 iframe 的同源策略。

您可以使用 postMessage 在框架之间进行通信,或者您可以将 mydomain.com 的子域附加到您的 S3 存储桶并通过设置 放宽同源策略>document.domain(该方法只对同域的子域间通信有效,不同域间无效)

您可以从 StackOverflow 上的这个答案中了解有关 iframe 通信的更多信息:

Ways to circumvent the same-origin policy

关于django - 从 AWS S3 加载的 iframe 同源问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18946822/

相关文章:

django - 如何在字段集中显示 Django 管理内联模型?

node.js - 放大初始化错误 - ✖ 根堆栈创建失败初始化失败 TypeError : Cannot redefine property: default

php - 使用 AWS SES 和 PHP 发送电子邮件

amazon-s3 - 我收到 s3 错误 : An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied

php - 使用 PHP 的 CreateSignedURL 失败 AWS SSE-C

python - 主从 postgresql,具有 django 应用程序的日志记录和监控功能

python - Django - 将值从模型上的 pre_save 传递到 post_save 方法

python - Django-对 admin 所做的更改不会在不重新启动服务器的情况下反射(reflect)在模板中

ios - 使用 AWS SDK iOS 版本 2.6.1 登录后无法访问用户详细信息 userName 和 imageURL

php - AWS lambda函数:put event is not triggered in direct browser upload in php