Skip to content

Commit 8ac21d0

Browse files
committed
Securing uploads
1 parent 6839146 commit 8ac21d0

File tree

6 files changed

+27
-1
lines changed

6 files changed

+27
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class PrivateAssetsController < Admin::BaseController
2+
def download
3+
if ["png", "jpg", "jpeg", "bmp", "gif"].include? params[:extension] and ["id_document_file", "id_bill_file"].include? params[:filetype]
4+
send_file "#{Rails.root}/uploads/asset/#{params[:filetype]}/file/#{params[:id]}/#{params[:filename]}.#{params[:extension]}", type: "image/#{params[:extension]}", disposition: 'inline'
5+
end
6+
end
7+
end
8+

app/models/admin/ability.rb

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def initialize(user)
2424
can :manage, ::Withdraws::Bank
2525
can :manage, ::Withdraws::Satoshi
2626
can :manage, ::Withdraws::Ether
27+
can :download, Admin::PrivateAssetsController
2728

2829
end
2930
end

config/environments/production.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# config.action_dispatch.rack_cache = true
2121

2222
# Disable Rails's static asset server (Apache or nginx will already do this).
23-
config.serve_static_assets = false
23+
config.serve_static_assets = true
2424

2525
# Compress JavaScripts and CSS.
2626
config.assets.js_compressor = Uglifier.new(:mangle => false)

config/initializers/carrierwave.rb

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
CarrierWave.configure do |config|
22
config.storage = :file
3+
config.permissions = 0600
4+
config.directory_permissions = 0700
35
config.cache_dir = "#{Rails.root}/tmp/uploads"
6+
config.root = Rails.root
47
end

config/routes/admin.rb

+4
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,8 @@
4040
resource :deposits, :only => :show
4141
resource :withdraws, :only => :show
4242
end
43+
4344
end
45+
46+
get "/uploads/asset/:filetype/file/:id/:filename.:extension" , controller: "private_assets" , action: "download"
47+

init.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
sed -e "s/\${domain_url}/$DOMAIN/" -i config/application.yml
3+
sed -e "s/\${rpc_url}/$RPCUSER:$RPCPASS@$RPCHOST:$RPCPORT/" -i config/currencies.yml
4+
5+
bundle exec rake db:create
6+
bundle exec rake db:migrate
7+
bundle exec rake db:seed
8+
rm -rf /peatio/tmp/pids/*
9+
bundle exec rake daemons:start
10+
bundle exec rails server

0 commit comments

Comments
 (0)