safer_send_file 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT_LICENSE +20 -0
- data/README.rdoc +27 -0
- data/lib/safer_send_file.rb +13 -0
- data/lib/safer_send_file/railtie.rb +10 -0
- data/lib/safer_send_file/streaming.rb +14 -0
- metadata +101 -0
data/MIT_LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Hubert Łępicki
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
= Overview
|
2
|
+
|
3
|
+
This little gem adds "safer_send_file" method, that wraps Rails' "send_file" and checks if file being sent is in one of white-listed directories. This is to prevent Rails application from sending /etc/passwd or any other sensitive data.
|
4
|
+
|
5
|
+
= Installation
|
6
|
+
|
7
|
+
Edit your Gemfile, and add:
|
8
|
+
|
9
|
+
gem "safer_send_file", "0.0.1"
|
10
|
+
|
11
|
+
and run:
|
12
|
+
|
13
|
+
$ bundle install
|
14
|
+
|
15
|
+
= Configuration
|
16
|
+
|
17
|
+
Create file #{Rails.root}/config/initializers/safe_send_file and specify allowed directories. Default is not to allow serving any files!
|
18
|
+
|
19
|
+
Example initializer file:
|
20
|
+
|
21
|
+
SaferSendFile.allowed_directories = [
|
22
|
+
File.join(Rails.root, "uploads")
|
23
|
+
]
|
24
|
+
|
25
|
+
= License
|
26
|
+
|
27
|
+
MIT, see MIT_LICENSE for details.
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module SaferSendFile
|
2
|
+
class NotAllowed < RuntimeError; end
|
3
|
+
def self.allowed_directories=(some_directories)
|
4
|
+
@@allowed_directories = some_directories.collect { |dir| File.expand_path(dir) }
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.allowed_directories
|
8
|
+
defined?(@@allowed_directories) ? @@allowed_directories : []
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'safer_send_file/streaming'
|
13
|
+
require 'safer_send_file/railtie'
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'rails'
|
2
|
+
module SaferSendFile
|
3
|
+
class Railtie < Rails::Railtie
|
4
|
+
initializer "safer_send_file.include_helpers" do |app|
|
5
|
+
ActiveSupport.on_load(:action_controller) do
|
6
|
+
ActionController::Base.send(:include, SaferSendFile::Streaming)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module SaferSendFile
|
2
|
+
module Streaming
|
3
|
+
def safer_send_file(path, options = {})
|
4
|
+
full_path = File.expand_path(path)
|
5
|
+
if SaferSendFile.allowed_directories.any? { |dir| dir == full_path[0..dir.size-1] }
|
6
|
+
send_file full_path, options
|
7
|
+
else
|
8
|
+
raise SaferSendFile::NotAllowed
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: safer_send_file
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- "Hubert \xC5\x81\xC4\x99picki"
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-09-26 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rails
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 3
|
30
|
+
- 0
|
31
|
+
version: "3.0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rspec
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - "="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 2
|
44
|
+
- 0
|
45
|
+
- 0
|
46
|
+
- beta
|
47
|
+
- 22
|
48
|
+
version: 2.0.0.beta.22
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
description: implements safer_send_file method that allows sending files only from specified directories
|
52
|
+
email:
|
53
|
+
- hubert.lepicki@amberbit.com
|
54
|
+
executables: []
|
55
|
+
|
56
|
+
extensions: []
|
57
|
+
|
58
|
+
extra_rdoc_files: []
|
59
|
+
|
60
|
+
files:
|
61
|
+
- lib/safer_send_file/railtie.rb
|
62
|
+
- lib/safer_send_file/streaming.rb
|
63
|
+
- lib/safer_send_file.rb
|
64
|
+
- MIT_LICENSE
|
65
|
+
- README.rdoc
|
66
|
+
has_rdoc: true
|
67
|
+
homepage: http://amberbit.com
|
68
|
+
licenses: []
|
69
|
+
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
segments:
|
89
|
+
- 1
|
90
|
+
- 3
|
91
|
+
- 6
|
92
|
+
version: 1.3.6
|
93
|
+
requirements: []
|
94
|
+
|
95
|
+
rubyforge_project: safer_send_file
|
96
|
+
rubygems_version: 1.3.7
|
97
|
+
signing_key:
|
98
|
+
specification_version: 3
|
99
|
+
summary: Safer send_file for Rails 3
|
100
|
+
test_files: []
|
101
|
+
|