Skip to content

Commit 8ef80e7

Browse files
committed
First go at fixing CVE-2015-9284
1 parent 857885a commit 8ef80e7

File tree

12 files changed

+266
-67
lines changed

12 files changed

+266
-67
lines changed

.rubocop.yml

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,55 @@
1+
Layout/AccessModifierIndentation:
2+
EnforcedStyle: outdent
3+
4+
Layout/SpaceInsideHashLiteralBraces:
5+
EnforcedStyle: no_space
6+
17
Metrics/BlockNesting:
28
Max: 2
39

4-
Metrics/ClassLength:
5-
CountComments: false
6-
Max: 120
7-
8-
Metrics/PerceivedComplexity:
9-
Max: 8
10+
Metrics/LineLength:
11+
AllowURI: true
12+
Enabled: false
1013

11-
Metrics/ModuleLength:
14+
Metrics/MethodLength:
1215
CountComments: false
13-
Max: 120
16+
Max: 10
1417

1518
Metrics/ParameterLists:
16-
Max: 3
19+
Max: 4
1720
CountKeywordArgs: true
1821

19-
Metrics/AbcSize:
20-
Enabled: false
21-
2222
Style/CollectionMethods:
2323
PreferredMethods:
24-
collect: 'map'
24+
map: 'collect'
2525
reduce: 'inject'
2626
find: 'detect'
2727
find_all: 'select'
2828

2929
Style/Documentation:
3030
Enabled: false
3131

32-
Style/DotPosition:
33-
EnforcedStyle: trailing
34-
3532
Style/DoubleNegation:
3633
Enabled: false
3734

38-
Style/EachWithObject:
39-
Enabled: false
40-
41-
Style/Encoding:
35+
Style/ExpandPathArguments:
4236
Enabled: false
4337

4438
Style/HashSyntax:
4539
EnforcedStyle: hash_rockets
4640

47-
Style/Lambda:
48-
Enabled: false
49-
50-
Style/SingleSpaceBeforeFirstArg:
41+
Style/StderrPuts:
5142
Enabled: false
5243

53-
Style/SpaceAroundOperators:
54-
MultiSpaceAllowedForOperators:
55-
- "="
56-
- "=>"
57-
- "||"
58-
- "||="
59-
- "&&"
60-
- "&&="
44+
Style/StringLiterals:
45+
EnforcedStyle: single_quotes
6146

62-
Style/SpaceInsideHashLiteralBraces:
63-
EnforcedStyle: no_space
47+
Style/TrailingCommaInArguments:
48+
EnforcedStyleForMultiline: comma
6449

65-
Style/StringLiterals:
66-
EnforcedStyle: double_quotes
50+
Style/TrailingCommaInHashLiteral:
51+
EnforcedStyleForMultiline: comma
6752

68-
Style/TrivialAccessors:
69-
Enabled: false
53+
Style/TrailingCommaInArrayLiteral:
54+
EnforcedStyleForMultiline: comma
55+

.travis.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
bundler_args: --without development
2+
before_install:
3+
- gem update --system
4+
- gem update bundler
5+
cache: bundler
6+
env:
7+
global:
8+
- JRUBY_OPTS="$JRUBY_OPTS --debug"
9+
language: ruby
10+
rvm:
11+
- jruby-9000
12+
- 2.3.5
13+
- 2.4.4
14+
- 2.5.3
15+
- jruby-head
16+
- ruby-head
17+
matrix:
18+
allow_failures:
19+
- rvm: jruby-head
20+
- rvm: ruby-head
21+
fast_finish: true
22+
sudo: false

Gemfile

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
source "https://rubygems.org"
1+
# frozen_string_literal: true
22

3-
# Specify your gem's dependencies in omniauth-rails.gemspec
4-
gemspec
3+
source 'https://rubygems.org'
4+
5+
gem 'rake'
56

6-
gem "rake"
7-
gem "rubocop"
7+
group :test do
8+
gem 'coveralls', :require => false
9+
gem 'rspec', '~> 3.5.0'
10+
gem 'rubocop'
11+
end
12+
13+
gemspec

Rakefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
require "bundler/gem_tasks"
2-
require "rubocop/rake_task"
1+
# frozen_string_literal: true
2+
require 'bundler/gem_tasks'
3+
require 'rspec/core/rake_task'
34

4-
RuboCop::RakeTask.new
5-
6-
task :default => :rubocop
5+
RSpec::Core::RakeTask.new(:spec)
6+
task :default => :spec

lib/omiauth-rails.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# frozen_string_literal: true
2+
3+
require 'omniauth-rails/version'
4+
require 'omniauth-rails/railtie'

lib/omniauth-rails/railtie.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
require 'rails'
3+
4+
module OmniAuth
5+
module Rails
6+
class Railtie < ::Rails::Railtie
7+
initializer 'OmniAuth request_forgery_protection' do
8+
OmniAuth.config.allowed_request_methods = [:post]
9+
OmniAuth.config.before_request_phase do |env|
10+
OmniAuth::Rails::RequestForgeryProtection.call(env)
11+
end
12+
end
13+
end
14+
end
15+
end
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# frozen_string_literal: true
2+
require 'action_controller'
3+
4+
module OmniAuth
5+
module Rails
6+
module RequestForgeryProtection
7+
class Controller < ActionController::Base
8+
protect_from_forgery :with => :exception, :prepend => true
9+
10+
rescue_from ActionController::InvalidAuthenticityToken do |e|
11+
# Log warning
12+
raise e
13+
end
14+
15+
def index
16+
head :ok
17+
end
18+
end
19+
20+
def self.app
21+
@app ||= Controller.action(:index)
22+
end
23+
24+
def self.call(env)
25+
app.call(env)
26+
end
27+
28+
def self.verified?(env)
29+
call(env)
30+
31+
true
32+
rescue ActionController::InvalidAuthenticityToken
33+
false
34+
end
35+
end
36+
end
37+
end

lib/omniauth-rails/version.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
module OmniAuthRails
2-
VERSION = "1.0.0"
1+
# frozen_string_literal: true
2+
3+
module OmniAuth
4+
module Rails
5+
VERSION = '1.0.0'
6+
end
37
end

omniauth-rails.gemspec

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
1-
# coding: utf-8
2-
lib = File.expand_path("../lib", __FILE__)
1+
# frozen_string_literal: true
2+
lib = File.expand_path('../lib', __FILE__)
33
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4-
require "omniauth-rails/version"
54

6-
Gem::Specification.new do |spec|
7-
spec.name = "omniauth-rails"
8-
spec.version = OmniAuthRails::VERSION
9-
spec.authors = ["Erik Michaels-Ober", "Douwe Maan"]
10-
5+
require 'omniauth-rails/version'
116

12-
spec.description = "Ruby on Rails extensions to OmniAuth"
13-
spec.summary = spec.description
14-
spec.homepage = "https://github.com/intridea/omniauth-rails"
15-
spec.license = "MIT"
7+
Gem::Specification.new do |gem|
8+
gem.authors = ['Tom Milewski']
9+
gem.email = ['[email protected]']
10+
gem.description = 'Official Rails OmniAuth gem.'
11+
gem.summary = gem.description
12+
gem.homepage = 'https://github.com/omniauth/omniauth-rails'
13+
gem.license = 'MIT'
1614

17-
spec.files = `git ls-files -z`.split("\x0")
18-
spec.require_paths = ["lib"]
15+
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
16+
gem.files = `git ls-files`.split("\n")
17+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18+
gem.name = 'omniauth-rails'
19+
gem.require_paths = %w[lib]
20+
gem.version = OmniAuth::Rails::VERSION
1921

20-
spec.add_dependency "omniauth"
21-
spec.add_dependency "rails"
22-
spec.add_development_dependency "bundler", "~> 1.9"
22+
gem.add_dependency 'omniauth', '~> 1.0'
23+
gem.add_dependency 'rails'
24+
gem.add_development_dependency 'rack-test'
25+
gem.add_development_dependency 'rspec', '~> 3.5'
26+
gem.add_development_dependency 'simplecov'
2327
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
require 'spec_helper'
3+
4+
describe OmniAuth::Rails::Railtie do
5+
before do
6+
OmniAuth::Rails::Railtie.initializers.each(&:run)
7+
end
8+
9+
it 'should only allow POST requests' do
10+
expect(OmniAuth.config.allowed_request_methods).to eq([:post])
11+
end
12+
13+
it 'should only allow POST requests' do
14+
env = {}
15+
expect(OmniAuth::Rails::RequestForgeryProtection).to receive(:call).with(env)
16+
OmniAuth.config.before_request_phase.call(env)
17+
end
18+
end

0 commit comments

Comments
 (0)