ruby-on-rails - Rails、Rackspace 云文件、Referrer ACL

标签 ruby-on-rails acl cloudfiles rackspace-cloud

我正在使用 Rackspace Cloud Files 作为我的应用程序的文件存储服务器。用户上传的文件必须从我的应用程序中获得授权,然后它会从 Controller 重定向到正确的 Rackspace 云文件 CDN URL。我正在尝试使用 Rackspace Cloud Files 的 Referrer ACL 进行授权。

所以让我添加一个非常简单的片段来阐明我想要完成的事情。

class FilesController < ApplicationController
  def download
    redirect_to(some_url_to_a_file_on_cloud_files_url)
  end
end

用户访问此下载操作的 URL 如下:

http://a-subdomain.domain.com/projects/:project_id/files/:file_id/download

因此,使用 CloudFiles gem,我设置了一个应该有效的 ACL Referrer 正则表达式。

http\:\/\/.+\.domain\.com\/projects\/\d+\/files\/\d+\/download

当用户点击 Web UI 中的链接时,它会将他们路由到上述 URL,并根据参数,从下载操作中将用户重定向到正确的 Rackspace Cloud Files 文件 URL。

嗯,我得到的是一个错误,说我未经授权(错误的 http referrer)。我有一种预感,因为我正在从下载操作直接重定向到云文件,它不会“算”为 HTTP 引荐来源网址,而不是使用此 URL 作为引荐来源网址,我认为它可能正在使用这个网址:

http\:\/\/.+\.domain\.com\/projects\/\d+\/files

因为这是您想要单击“下载”链接时所在的页面,它会将用户引导至 FilesController 中的下载操作。

当我为 Rackspace ACL 设置 HTTP Referrer 时:

http\:\/\/.+\.domain\.com\/projects\/\d+\/files

然后点击一个链接,我被授权下载。然而,这还不够安全,因为那时任何人都可以例如将 firebug 注入(inject) html 并注入(inject)文件的原始链接并获得访问权限。

所以我想我的问题是,有没有人知道我试图完成的事情是如何或为什么不起作用的,并且有任何建议/想法?正如我所说,我认为可能是当用户单击链接时,引荐来源网址被设置为单击文件的位置,而不是用户被重定向到云文件上实际文件的 url。

这样的事情可能吗?

class FilesController < ApplicationController
  def download
    # Dynamically set a HTTP Referrer here before
    # redirecting the user to the actual file on cloud files
    # so the user is authorized to download the file?
    redirect_to(some_url_to_a_file_on_cloud_files_url)
  end
end

非常感谢任何帮助和建议!

谢谢!

最佳答案

一般来说,Micahel 的评论足以解释为什么 S3 在这个问题上排在 rackspace 的首位,但是如果你真的想在你的 Rackspace 请求中添加一些特殊的 HTTP header ——做一个你自己的 HTTP 请求并手动获取文件:

class DownloadsController < ApplicationController
   def download
     send_data HTTParty.get(some_url_to_a_file_on_cloud_files_url, :headers => {"x-special-headers" => "AWESOME" }), :file_name => "myfile.something"
   end
end

是的,你可以更好地编写这个例子,但这是一般的想法。

关于ruby-on-rails - Rails、Rackspace 云文件、Referrer ACL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4020399/

相关文章:

mongodb - _rperm 的 parse 中的索引方法

rackspace - 获取新上传的 CloudFiles Assets 的公共(public) URL

ruby-on-rails - "undefined method ` 去救援web ui时处理路由'"

ruby-on-rails - 使用to_json时如何访问 ':has_many :though'连接表数据?

magento - 具有自定义角色的用户无法访问 Magento 管理界面中的自定义菜单项

cdn - 云文件 - 覆盖 CDN 发送到浏览器的过期和缓存控制 header ,但不覆盖 CDN 的 TTL

oauth-2.0 - 强制 OpenStack Swift token 过期

ruby-on-rails - PG::UndefinedTable:错误:关系 "users"不存在 - Azure 数据库

ruby-on-rails - rails : attr_accessor doesn't show up when try to render as JSON

php - 我如何使用 CodeIgniter ACL 库?