omniauth-protect 1.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7b0f8ee48965b74bb3934bdb0b2fc9e1bb7944880223c36620547f0395b806f5
4
+ data.tar.gz: f35833309948e6e37da51fc8e3f288c961d9bd39d19b0d20d228b39c98eebc7c
5
+ SHA512:
6
+ metadata.gz: cf78c3c787274ac00d679295ae64f96e9ec6c84355511a90929e9cc4bc0b0e405fbcfdfe5266b4cd0ce07ecf6917f7553b7484dc38401293ed40b6d8845dc38b
7
+ data.tar.gz: bdc67f0584057ef2d8240e9e89d761e484040a6100b7be354fe09dbaffa9eae5b4b16d2c42c748b4edab3e9284c910a3865530b18f19e5b7719202481e3df639
@@ -0,0 +1,80 @@
1
+ version: 2
2
+
3
+ jobs:
4
+ style_check:
5
+ docker:
6
+ - image: rainforestapp/circlemator:latest
7
+ steps:
8
+ - checkout
9
+ - run:
10
+ name: Style check
11
+ command: circlemator style-check --base-branch=master
12
+
13
+ test:
14
+ docker:
15
+ - image: circleci/ruby:2.5.1
16
+ steps:
17
+ - checkout
18
+ - restore_cache:
19
+ key: v1-omniauth-protect-{{ checksum "Gemfile.lock" }}
20
+ - run:
21
+ name: Install Ruby gems
22
+ command: |
23
+ bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
24
+ - save_cache:
25
+ key: v1-omniauth-protect-{{ checksum "Gemfile.lock" }}
26
+ paths:
27
+ - ~/project/vendor/bundle
28
+ - run:
29
+ name: Set up test output directory
30
+ command: sudo install -o circleci -d ~/rspec
31
+ - run:
32
+ name: RSpec
33
+ command: |
34
+ bundle exec rspec \
35
+ --color \
36
+ --require spec_helper \
37
+ --format documentation \
38
+ --format RspecJunitFormatter \
39
+ --out ~/rspec/rspec.xml
40
+ - store_artifacts:
41
+ path: ~/rspec
42
+ - store_test_results:
43
+ path: ~/rspec
44
+
45
+ push_to_rubygems:
46
+ docker:
47
+ - image: circleci/ruby:2.5.1
48
+ steps:
49
+ - checkout
50
+ - run:
51
+ name: Create .gem/credentials file
52
+ command: |
53
+ mkdir ~/.gem
54
+ echo "---
55
+ :rubygems_api_key: $RUBYGEMS_API_KEY
56
+ " > ~/.gem/credentials
57
+ chmod 600 ~/.gem/credentials
58
+ - run:
59
+ name: Release omniauth-protect
60
+ command: |
61
+ gem build omniauth-protect
62
+ gem push omniauth-protect-*.gem
63
+ workflows:
64
+ version: 2
65
+ gem_release:
66
+ jobs:
67
+ - test
68
+ - style_check:
69
+ filters:
70
+ branches:
71
+ ignore:
72
+ - master
73
+ - push_to_rubygems:
74
+ filters:
75
+ branches:
76
+ ignore:
77
+ - /.*/
78
+ tags:
79
+ only:
80
+ - /^v.*/
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .byebug_history
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in omniauth-protect.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 sdogruyol
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.
@@ -0,0 +1,56 @@
1
+ # Omniauth::Protect
2
+
3
+ Protects your Rails app from Omniauth request phase CSRF vulnerability
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'omniauth-protect'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install omniauth-protect
20
+
21
+ ## Usage
22
+
23
+ Add this line to your `config/application.rb`
24
+
25
+ ```ruby
26
+ config.middleware.use Omniauth::Protect::Middleware
27
+ ```
28
+
29
+ ## Configuration
30
+
31
+ You need to create an initiliazer like `config/initializers/omniauth_protect.rb` for configuration
32
+
33
+ ```ruby
34
+ Omniauth::Protect.config[:message] = 'CSRF detected, Access Denied'
35
+ Omniauth::Protect.config[:paths] = ['/auth/twitter', '/auth/google' ,'/auth/github']
36
+ Omniauth::Protect.configure
37
+ ```
38
+
39
+ ## Development
40
+
41
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
42
+
43
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rainforestapp/omniauth-protect.
48
+
49
+ ## License
50
+
51
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
52
+
53
+
54
+ ## Thanks
55
+
56
+ Speacial thanks to [RainforestQA](https://www.rainforestqa.com/)
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "omniauth/protect"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+ require 'base64'
2
+ require 'rack'
3
+
4
+ module Omniauth
5
+ module Protect
6
+ class ConfigException < Exception
7
+ end
8
+
9
+ @config = {
10
+ message: '',
11
+ paths: []
12
+ }
13
+
14
+ def self.config
15
+ @config
16
+ end
17
+
18
+ # Adds / to the paths
19
+ def self.configure
20
+ raise ConfigException.new('message must be specified') if config[:message].empty?
21
+ raise ConfigException.new('paths must be specified') if config[:paths].empty?
22
+
23
+ config[:paths].each do |path|
24
+ next if path[-1] == '/'
25
+
26
+ config[:paths] << "#{path}/"
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ require 'omniauth/protect/middleware'
@@ -0,0 +1,48 @@
1
+ module Omniauth
2
+ module Protect
3
+ class Middleware
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ if !Omniauth::Protect.config[:paths].include?(env['PATH_INFO'])
10
+ @app.call(env)
11
+ else
12
+ access_denied = [403, { 'Content-Type' => 'text/plain'}, [ Omniauth::Protect.config[:message] ] ]
13
+ return access_denied if env['REQUEST_METHOD'] != 'POST'
14
+
15
+ req = Rack::Request.new(env)
16
+ encoded_masked_token = req.params['authenticity_token']
17
+
18
+ return access_denied if !encoded_masked_token
19
+
20
+ valid_csrf_token?(env, encoded_masked_token) ? @app.call(env) : access_denied
21
+ end
22
+ end
23
+ # This is mostly taken & adapted from https://github.com/rails/rails/blob/v4.2.0/actionpack/lib/action_controller/metal/request_forgery_protection.rb#L276
24
+ def valid_csrf_token?(env, encoded_masked_token)
25
+ begin
26
+ masked_token = Base64.strict_decode64(encoded_masked_token)
27
+ rescue ArgumentError # encoded_masked_token is invalid Base64
28
+ return false
29
+ end
30
+
31
+ token_length = ActionController::RequestForgeryProtection::AUTHENTICITY_TOKEN_LENGTH
32
+ if masked_token.length == token_length * 2
33
+ one_time_pad = masked_token[0...token_length]
34
+ encrypted_csrf_token = masked_token[token_length..-1]
35
+ csrf_token = one_time_pad.bytes.zip(encrypted_csrf_token.bytes).map { |(c1, c2)| c1 ^ c2 }.pack('c*')
36
+ session = session(env)
37
+ session[:_csrf_token] ||= SecureRandom.base64(token_length)
38
+ real_csrf_token = Base64.strict_decode64(session[:_csrf_token])
39
+ ActiveSupport::SecurityUtils.secure_compare(csrf_token, real_csrf_token)
40
+ end
41
+ end
42
+
43
+ def session(env)
44
+ env['rack.session']
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Protect
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
@@ -0,0 +1,34 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "omniauth/protect/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "omniauth-protect"
8
+ spec.version = Omniauth::Protect::VERSION
9
+ spec.authors = ["Serdar Dogruyol"]
10
+ spec.email = ["serdar@rainforestqa.com"]
11
+ spec.license = "MIT"
12
+
13
+ spec.summary = %q{Protect Omniauth from request phase CSRF}
14
+ spec.description = %q{Protects your Rails app from Omniauth request phase CSRF vulnerability.}
15
+ spec.homepage = "https://github.com/rainforestapp/omniauth-protect"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_runtime_dependency 'actionpack'
27
+ spec.add_runtime_dependency 'rack'
28
+
29
+ spec.add_development_dependency "bundler", '~> 1.10'
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec", "~> 3.0"
32
+ spec.add_development_dependency 'byebug'
33
+ spec.add_development_dependency 'rspec_junit_formatter'
34
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-protect
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Serdar Dogruyol
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionpack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec_junit_formatter
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Protects your Rails app from Omniauth request phase CSRF vulnerability.
112
+ email:
113
+ - serdar@rainforestqa.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".circleci/config.yml"
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - lib/omniauth/protect.rb
129
+ - lib/omniauth/protect/middleware.rb
130
+ - lib/omniauth/protect/version.rb
131
+ - omniauth-protect.gemspec
132
+ homepage: https://github.com/rainforestapp/omniauth-protect
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.7.7
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Protect Omniauth from request phase CSRF
156
+ test_files: []