carrierwave-bombshelter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 700d345483ef7c2c623b84ab5e3d47879dfdd64f
4
+ data.tar.gz: 9781395177285938e4a2acb621c8f5fb27ac2a47
5
+ SHA512:
6
+ metadata.gz: dc2531ba686c6d1883f998c0b315a4f4684718bacb2afd70ed476d99e357e85cc6de75603c536671d90bef5cf04f69b77ee3a2910b01f7a8c2ef0ea94f242697
7
+ data.tar.gz: baabc062473db3af6dda55c45b984b4a0ee4446f12dd963eb7d626b7424cd2fee77cf7ad56ec0f9673a590b8b23caf810e216139faf4f8cb5e728763c6f2289e
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in carrierwave-bombshelter.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 DarthSim
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # CarrierWave::BombShelter
2
+
3
+ BombShelter is a module which protects your uploaders from image bombs. It checks pixel dimensions of uploaded image before ImageMagick touches it.
4
+
5
+ ## How it works
6
+
7
+ BombShelter uses [fastimage](https://github.com/sdsykes/fastimage) gem, which reads just a header of an image to get info about it. BombShelter compares pixel dimensions of the uploaded image with maximum allowed ones and raises integrity error if image is too big. Works perfectly with ActiveRecord validators.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'carrierwave-bombshelter'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install carrierwave-bombshelter
24
+
25
+ ## Usage
26
+
27
+ Just include `CarrierWave::BombShelter` to your uploader and you're done:
28
+
29
+ ```ruby
30
+ class YourUploader < CarrierWave::Uploader::Base
31
+ include CarrierWave::BombShelter
32
+ end
33
+ ```
34
+
35
+ By default BombShelter sets maximum allowed dimensions to 4096x4096, but you can set your own ones by defining `max_pixel_dimentions` method:
36
+
37
+ ```ruby
38
+ class YourUploader < CarrierWave::Uploader::Base
39
+ include CarrierWave::BombShelter
40
+
41
+ def max_pixel_dimentions
42
+ [1024, 1024]
43
+ end
44
+ end
45
+ ```
46
+
47
+ ## Contributing
48
+
49
+ Bug reports and pull requests are welcome on GitHub at https://github.com/DarthSim/carrierwave-bombshelter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
50
+
51
+ ## License
52
+
53
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'carrierwave/bombshelter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'carrierwave-bombshelter'
8
+ spec.version = CarrierWave::BombShelter::VERSION
9
+ spec.authors = ['DarthSim']
10
+ spec.email = ['darthsim@gmail.com']
11
+
12
+ spec.summary = 'Protect your carrierwave from image bombs'
13
+ spec.homepage = 'https://github.com/DarthSim/carrierwave-bombshelter'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.10'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'minitest'
24
+
25
+ spec.add_dependency 'activesupport', '>= 3.2.0'
26
+ spec.add_dependency 'fastimage'
27
+ spec.add_dependency 'carrierwave'
28
+ end
@@ -0,0 +1 @@
1
+ require 'carrierwave/bombshelter'
@@ -0,0 +1,39 @@
1
+ require 'carrierwave/bombshelter/version'
2
+
3
+ require 'fastimage'
4
+ require 'i18n'
5
+ require 'carrierwave'
6
+
7
+ files = Dir[File.expand_path(
8
+ '../../locale/*.yml', __FILE__
9
+ )]
10
+ I18n.load_path = files.concat I18n.load_path
11
+
12
+ module CarrierWave
13
+ module BombShelter
14
+ extend ActiveSupport::Concern
15
+
16
+ included do
17
+ before :cache, :check_pixel_dimentions!
18
+ end
19
+
20
+ def max_pixel_dimentions
21
+ [4096, 4096]
22
+ end
23
+
24
+ private
25
+
26
+ def check_pixel_dimentions!(new_file)
27
+ sizes = FastImage.size(new_file.path)
28
+ max_sizes = max_pixel_dimentions
29
+
30
+ return if !sizes || (sizes[0] <= max_sizes[0] && sizes[1] <= max_sizes[1])
31
+
32
+ fail CarrierWave::IntegrityError,
33
+ I18n.translate(
34
+ :'errors.messages.pixel_dimentions_error',
35
+ x_size: max_sizes[0], y_size: max_sizes[1]
36
+ )
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ module CarrierWave
2
+ module BombShelter
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
data/lib/locale/en.yml ADDED
@@ -0,0 +1,5 @@
1
+ en:
2
+ errors:
3
+ messages:
4
+ pixel_dimentions_error: "Image size should be less than or equal to %{x_size}x%{y_size}"
5
+ not_image: "File is not an image"
data/lib/locale/ru.yml ADDED
@@ -0,0 +1,5 @@
1
+ en:
2
+ errors:
3
+ messages:
4
+ pixel_dimentions_error: "Изображение не должно превышать размера %{x_size}x%{y_size}"
5
+ not_image: "Файл не является изображением"
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carrierwave-bombshelter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - DarthSim
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 3.2.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 3.2.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: fastimage
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: carrierwave
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - darthsim@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".travis.yml"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - carrierwave-bombshelter.gemspec
111
+ - lib/carrierwave-bombshelter.rb
112
+ - lib/carrierwave/bombshelter.rb
113
+ - lib/carrierwave/bombshelter/version.rb
114
+ - lib/locale/en.yml
115
+ - lib/locale/ru.yml
116
+ homepage: https://github.com/DarthSim/carrierwave-bombshelter
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.4.5.1
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Protect your carrierwave from image bombs
140
+ test_files: []