简体   繁体   English

Rails回形针S3隐藏附加文件的url

[英]Rails Paperclip S3 hide url of attached file

I am using paperclip to upload files directly to Aws s3 (following this guide: https://devcenter.heroku.com/articles/paperclip-s3 ). 我正在使用回形针将文件直接上传到Aws s3(遵循本指南: https : //devcenter.heroku.com/articles/paperclip-s3 )。

As shown below, a user can view a file in their browser using the "attachment.file.url" method. 如下所示,用户可以使用“ attachment.file.url”方法在其浏览器中查看文件。 Is it a security vulnerability to display the s3 url to a user? 向用户显示s3网址是否存在安全漏洞? If so, is there a way to hide this url without streaming the file to the app first or a "download_file" controller action? 如果是这样,有没有一种方法可以隐藏此URL,而无需先将文件流式传输到应用程序或“ download_file”控制器操作?

production.rb production.rb

Rails.application.configure do
  config.paperclip_defaults = {
    storage: :s3,
    s3_credentials: {
      bucket: ENV.fetch('S3_BUCKET_NAME'),
      access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
      secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
      s3_region: ENV.fetch('AWS_REGION'),
    }
  }
end

attachment.rb Attachment.rb

class Attachment < ActiveRecord::Base
  belongs_to :upload, polymorphic: true

  has_attached_file :file
  validates_attachment :file, content_type: { content_type: ["image/jpeg", "image/gif", "image/png", "application/pdf", "application/vnd.ms-excel",     
             "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
             "application/msword", 
             "application/vnd.openxmlformats-officedocument.wordprocessingml.document", 
             "text/plain"] }
end

view 视图

<h5>File Uploads</h5>
  <ul>
    <% @attachments.each do |attachment| %>
      <li>
        <%= link_to attachment.file_file_name, attachment.file.url, :target => '_blank' %> 
      </li>
    <% end %>
  </ul>
  <%= link_to "Add Files", new_attachment_path(:upload_type => 'Team'), class: "btn btn-md" %>

The S3 URL will be visible to anyone who can use dev tools anyway so exposing it is not a security vulnerability. 任何可以使用开发工具的人都可以看到S3 URL,因此公开它不是安全漏洞。 Some would argue it is bad UX but that is a discussion for another time. 有人会认为这是糟糕的用户体验,但这是另一次讨论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM