grape-forgery_protection 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9fb63a608198901713fb9808e8ef70047bd2ccd96ebd316d5e013ac4035dedf8
4
+ data.tar.gz: a6ae6b6d6068c8b1efc5410f9d7adff7ac12826bf3d4ca37b74232fe84faffa6
5
+ SHA512:
6
+ metadata.gz: c654df233d9042c882a61ec57d5f3058cdc7a34b4703bd1bd5ef16d2932fea52d810463e1819e8f4c89c842eeb82efd45cd8ff1d44922892523f3fbadb49fdb8
7
+ data.tar.gz: bda519d826113a3dae65202ee63e776b77707998266a54428bd1cc5b7182b233cc35d299cf505500e5fb262e08759d4d035fc9a35782a423fff38d2d78f131d7
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # Grape ForgeryProtection
2
+
3
+ This gem is your Rails app's payment model.
4
+
5
+ ## Install
6
+
7
+ Add in your application `Gemfile`:
8
+
9
+ ```rb
10
+ gem 'grape-forgery_protection'
11
+ ```
12
+
13
+ ## Release
14
+
15
+ To release a new version, update the `CHANGELOG.md` and change the version
16
+ number in `lib/sporran/version.rb`.
17
+
18
+ Then, the following command will add these two files, commit, tag with the
19
+ version and push to github:
20
+
21
+ ```sh
22
+ $ rake grape-forgery_protection_release
23
+ ```
24
+
25
+ Finally, upload the new `pkg/grape-forgery_protection-*.gem` file to rubygems.
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # Load gems
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ # RDOc
9
+ require 'rdoc/task'
10
+ RDoc::Task.new(:rdoc) do |rdoc|
11
+ rdoc.rdoc_dir = 'rdoc'
12
+ rdoc.title = 'Grape::ForgeryProtection'
13
+ rdoc.options << '--line-numbers'
14
+ rdoc.rdoc_files.include('README.rdoc')
15
+ rdoc.rdoc_files.include('lib/**/*.rb')
16
+ end
17
+
18
+ # Engine
19
+ APP_RAKEFILE = File.expand_path('spec/dummy/Rakefile', __dir__)
20
+ load 'rails/tasks/engine.rake'
21
+
22
+ # Bundler
23
+ Bundler::GemHelper.install_tasks
24
+
25
+ # Rubocop
26
+ require 'rubocop/rake_task'
27
+ RuboCop::RakeTask.new
28
+
29
+ # Specs
30
+ require 'rspec/core'
31
+ require 'rspec/core/rake_task'
32
+ RSpec::Core::RakeTask.new(:spec)
33
+
34
+ desc "Commit, create tag v#{Grape::ForgeryProtection::VERSION}, " \
35
+ 'build and push (make sure you update version.rb and CHANGELOG.md ' \
36
+ 'beforehand)'
37
+ task grape_forgery_protection_release: :build do
38
+ sh 'git add lib/grape/forgery_protection/version.rb CHANGELOG.md'
39
+ sh "git commit -m v#{Grape::ForgeryProtection::VERSION}"
40
+ sh "git tag v#{Grape::ForgeryProtection::VERSION}"
41
+ sh 'git push'
42
+ sh 'git push --tags'
43
+ puts
44
+ puts 'Done! You can now upload ' \
45
+ "pkg/grape-forgery_protection-#{Grape::ForgeryProtection::VERSION}.gem "\
46
+ 'to rubygems'
47
+ end
48
+
49
+ task default: %i[spec rubocop]
@@ -0,0 +1,21 @@
1
+ # Engine configuration.
2
+ module Grape
3
+ module ForgeryProtection
4
+ class << self
5
+ attr_writer :configuration
6
+
7
+ def configuration
8
+ @configuration ||= Configuration.new
9
+ end
10
+
11
+ def configure
12
+ yield(configuration)
13
+ end
14
+ end
15
+
16
+ # Configuration variables and defaults.
17
+ class Configuration
18
+ def initialize; end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,36 @@
1
+ module Grape
2
+ module ForgeryProtection
3
+ module Helpers
4
+ def session
5
+ env['rack.session']
6
+ end
7
+
8
+ def protect_against_forgery
9
+ error!('Unauthorized', 401) unless verified_request?
10
+ end
11
+
12
+ def verified_request?
13
+ !protect_against_forgery? || request.get? || request.head? ||
14
+ form_authenticity_token == csrf_token_from_headers
15
+ end
16
+
17
+ def csrf_token_from_headers
18
+ request.headers['X-CSRF-Token'].presence ||
19
+ request.headers['X-Csrf-Token']
20
+ end
21
+
22
+ def form_authenticity_token
23
+ session[:_csrf_token] ||= SecureRandom.base64(32)
24
+ end
25
+
26
+ def protect_against_forgery?
27
+ allow_forgery_protection = Rails
28
+ .configuration
29
+ .action_controller
30
+ .allow_forgery_protection
31
+
32
+ allow_forgery_protection.nil? || allow_forgery_protection
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ module Grape
2
+ module ForgeryProtection
3
+ VERSION = '0.0.1'.freeze
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ require 'grape/forgery_protection/version'
2
+
3
+ module Grape
4
+ module ForgeryProtection
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grape-forgery_protection
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Cyril LEPAGNOT
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-11-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: grape
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: fashion_police
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: test-unit
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Protect your Grape API from forgery attacks like Rails.
84
+ email:
85
+ - cyril.lepagnot@kisskissbankbank.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - LICENSE
91
+ - README.md
92
+ - Rakefile
93
+ - lib/grape-forgery_protection.rb
94
+ - lib/grape/forgery_protection/configuration.rb
95
+ - lib/grape/forgery_protection/helpers.rb
96
+ - lib/grape/forgery_protection/version.rb
97
+ homepage: https://github.com/KissKissBankBank/grape-forgery_protection
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.7.7
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Protect your Grape API from forgery attacks.
121
+ test_files: []