-
Notifications
You must be signed in to change notification settings - Fork 9
First attempt at fixing CVE-2015-9284 #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tmilewski
wants to merge
7
commits into
master
Choose a base branch
from
CVE-2015-9284
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8ef80e7
First go at fixing CVE-2015-9284
tmilewski 28473b0
Update test name; Allow for validate_request_phase, if available
tmilewski c69f990
Implement CircleCI
tmilewski a12d15b
Implement CircleCI
tmilewski 604d596
Force CI build
tmilewski 3d95cad
Update naming; Remove invalid Ruby/Rails CI combos
tmilewski 9001e18
Additional specs for Railtie integration
tmilewski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,55 @@ | ||
Layout/AccessModifierIndentation: | ||
EnforcedStyle: outdent | ||
|
||
Layout/SpaceInsideHashLiteralBraces: | ||
EnforcedStyle: no_space | ||
|
||
Metrics/BlockNesting: | ||
Max: 2 | ||
|
||
Metrics/ClassLength: | ||
CountComments: false | ||
Max: 120 | ||
|
||
Metrics/PerceivedComplexity: | ||
Max: 8 | ||
Metrics/LineLength: | ||
AllowURI: true | ||
Enabled: false | ||
|
||
Metrics/ModuleLength: | ||
Metrics/MethodLength: | ||
CountComments: false | ||
Max: 120 | ||
Max: 10 | ||
|
||
Metrics/ParameterLists: | ||
Max: 3 | ||
Max: 4 | ||
CountKeywordArgs: true | ||
|
||
Metrics/AbcSize: | ||
Enabled: false | ||
|
||
Style/CollectionMethods: | ||
PreferredMethods: | ||
collect: 'map' | ||
map: 'collect' | ||
reduce: 'inject' | ||
find: 'detect' | ||
find_all: 'select' | ||
|
||
Style/Documentation: | ||
Enabled: false | ||
|
||
Style/DotPosition: | ||
EnforcedStyle: trailing | ||
|
||
Style/DoubleNegation: | ||
Enabled: false | ||
|
||
Style/EachWithObject: | ||
Enabled: false | ||
|
||
Style/Encoding: | ||
Style/ExpandPathArguments: | ||
Enabled: false | ||
|
||
Style/HashSyntax: | ||
EnforcedStyle: hash_rockets | ||
|
||
Style/Lambda: | ||
Enabled: false | ||
|
||
Style/SingleSpaceBeforeFirstArg: | ||
Style/StderrPuts: | ||
Enabled: false | ||
|
||
Style/SpaceAroundOperators: | ||
MultiSpaceAllowedForOperators: | ||
- "=" | ||
- "=>" | ||
- "||" | ||
- "||=" | ||
- "&&" | ||
- "&&=" | ||
Style/StringLiterals: | ||
EnforcedStyle: single_quotes | ||
|
||
Style/SpaceInsideHashLiteralBraces: | ||
EnforcedStyle: no_space | ||
Style/TrailingCommaInArguments: | ||
EnforcedStyleForMultiline: comma | ||
|
||
Style/StringLiterals: | ||
EnforcedStyle: double_quotes | ||
Style/TrailingCommaInHashLiteral: | ||
EnforcedStyleForMultiline: comma | ||
|
||
Style/TrivialAccessors: | ||
Enabled: false | ||
Style/TrailingCommaInArrayLiteral: | ||
EnforcedStyleForMultiline: comma | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
bundler_args: --without development | ||
before_install: | ||
- gem update --system | ||
- gem update bundler | ||
cache: bundler | ||
env: | ||
global: | ||
- JRUBY_OPTS="$JRUBY_OPTS --debug" | ||
language: ruby | ||
rvm: | ||
- jruby-9000 | ||
- 2.3.5 | ||
- 2.4.4 | ||
- 2.5.3 | ||
- jruby-head | ||
- ruby-head | ||
matrix: | ||
allow_failures: | ||
- rvm: jruby-head | ||
- rvm: ruby-head | ||
fast_finish: true | ||
sudo: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
source "https://rubygems.org" | ||
# frozen_string_literal: true | ||
|
||
# Specify your gem's dependencies in omniauth-rails.gemspec | ||
gemspec | ||
source 'https://rubygems.org' | ||
|
||
gem 'rake' | ||
|
||
gem "rake" | ||
gem "rubocop" | ||
group :test do | ||
gem 'coveralls', :require => false | ||
gem 'rspec', '~> 3.5.0' | ||
gem 'rubocop' | ||
end | ||
|
||
gemspec |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
require "bundler/gem_tasks" | ||
require "rubocop/rake_task" | ||
# frozen_string_literal: true | ||
require 'bundler/gem_tasks' | ||
require 'rspec/core/rake_task' | ||
|
||
RuboCop::RakeTask.new | ||
|
||
task :default => :rubocop | ||
RSpec::Core::RakeTask.new(:spec) | ||
task :default => :spec |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'omniauth-rails/version' | ||
require 'omniauth-rails/railtie' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
require 'rails' | ||
|
||
module OmniAuth | ||
module Rails | ||
class Railtie < ::Rails::Railtie | ||
initializer 'OmniAuth request_forgery_protection' do | ||
OmniAuth.config.allowed_request_methods = [:post] | ||
OmniAuth.config.before_request_phase do |env| | ||
OmniAuth::Rails::RequestForgeryProtection.call(env) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
require 'action_controller' | ||
|
||
module OmniAuth | ||
module Rails | ||
module RequestForgeryProtection | ||
class Controller < ActionController::Base | ||
protect_from_forgery :with => :exception, :prepend => true | ||
|
||
rescue_from ActionController::InvalidAuthenticityToken do |e| | ||
# Log warning | ||
raise e | ||
end | ||
|
||
def index | ||
head :ok | ||
end | ||
end | ||
|
||
def self.app | ||
@app ||= Controller.action(:index) | ||
end | ||
|
||
def self.call(env) | ||
app.call(env) | ||
end | ||
|
||
def self.verified?(env) | ||
call(env) | ||
|
||
true | ||
rescue ActionController::InvalidAuthenticityToken | ||
false | ||
end | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
module OmniAuthRails | ||
VERSION = "1.0.0" | ||
# frozen_string_literal: true | ||
|
||
module OmniAuth | ||
module Rails | ||
VERSION = '1.0.0' | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,27 @@ | ||
# coding: utf-8 | ||
lib = File.expand_path("../lib", __FILE__) | ||
# frozen_string_literal: true | ||
lib = File.expand_path('../lib', __FILE__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
require "omniauth-rails/version" | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = "omniauth-rails" | ||
spec.version = OmniAuthRails::VERSION | ||
spec.authors = ["Erik Michaels-Ober", "Douwe Maan"] | ||
spec.email = ["sferik@gmail.com", "douwe@gitlab.com"] | ||
require 'omniauth-rails/version' | ||
|
||
spec.description = "Ruby on Rails extensions to OmniAuth" | ||
spec.summary = spec.description | ||
spec.homepage = "https://github.com/intridea/omniauth-rails" | ||
spec.license = "MIT" | ||
Gem::Specification.new do |gem| | ||
gem.authors = ['Tom Milewski'] | ||
gem.email = ['tmilewski@gmail.com'] | ||
gem.description = 'Official Rails OmniAuth gem.' | ||
gem.summary = gem.description | ||
gem.homepage = 'https://github.com/omniauth/omniauth-rails' | ||
gem.license = 'MIT' | ||
|
||
spec.files = `git ls-files -z`.split("\x0") | ||
spec.require_paths = ["lib"] | ||
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } | ||
gem.files = `git ls-files`.split("\n") | ||
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | ||
gem.name = 'omniauth-rails' | ||
gem.require_paths = %w[lib] | ||
gem.version = OmniAuth::Rails::VERSION | ||
|
||
spec.add_dependency "omniauth" | ||
spec.add_dependency "rails" | ||
spec.add_development_dependency "bundler", "~> 1.9" | ||
gem.add_dependency 'omniauth', '~> 1.0' | ||
gem.add_dependency 'rails' | ||
gem.add_development_dependency 'rack-test' | ||
gem.add_development_dependency 'rspec', '~> 3.5' | ||
gem.add_development_dependency 'simplecov' | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
require 'spec_helper' | ||
|
||
describe OmniAuth::Rails::Railtie do | ||
before do | ||
OmniAuth::Rails::Railtie.initializers.each(&:run) | ||
end | ||
|
||
it 'should only allow POST requests' do | ||
expect(OmniAuth.config.allowed_request_methods).to eq([:post]) | ||
end | ||
|
||
it 'should only allow POST requests' do | ||
tmilewski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
env = {} | ||
expect(OmniAuth::Rails::RequestForgeryProtection).to receive(:call).with(env) | ||
OmniAuth.config.before_request_phase.call(env) | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# frozen_string_literal: true | ||
require 'spec_helper' | ||
|
||
describe OmniAuth::Rails::RequestForgeryProtection do | ||
let(:csrf_token) { SecureRandom.base64(ActionController::RequestForgeryProtection::AUTHENTICITY_TOKEN_LENGTH) } | ||
let(:env) do | ||
{ | ||
'rack.input' => '', | ||
'rack.session' => { | ||
:_csrf_token => csrf_token, | ||
}, | ||
} | ||
end | ||
|
||
describe '.call' do | ||
context 'when the request method is GET' do | ||
before do | ||
env['REQUEST_METHOD'] = 'GET' | ||
end | ||
|
||
it 'does not raise an exception' do | ||
expect { described_class.call(env) }.not_to raise_exception | ||
end | ||
end | ||
|
||
context 'when the request method is POST' do | ||
before do | ||
env['REQUEST_METHOD'] = 'POST' | ||
end | ||
|
||
context 'when the CSRF token is valid' do | ||
before do | ||
env['HTTP_X_CSRF_TOKEN'] = csrf_token | ||
end | ||
|
||
it 'does not raise an exception' do | ||
expect { described_class.call(env) }.not_to raise_exception | ||
end | ||
end | ||
|
||
context 'when the CSRF token is invalid' do | ||
before do | ||
env['HTTP_X_CSRF_TOKEN'] = 'foo' | ||
end | ||
|
||
it 'raises an ActionController::InvalidAuthenticityToken exception' do | ||
expect { described_class.call(env) }.to raise_exception(ActionController::InvalidAuthenticityToken) | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe '.verified?' do | ||
context 'when the request method is GET' do | ||
before do | ||
env['REQUEST_METHOD'] = 'GET' | ||
end | ||
|
||
it 'returns true' do | ||
expect(described_class.verified?(env)).to be_truthy | ||
end | ||
end | ||
|
||
context 'when the request method is POST' do | ||
before do | ||
env['REQUEST_METHOD'] = 'POST' | ||
end | ||
|
||
context 'when the CSRF token is valid' do | ||
before do | ||
env['HTTP_X_CSRF_TOKEN'] = csrf_token | ||
end | ||
|
||
it 'returns true' do | ||
expect(described_class.verified?(env)).to be_truthy | ||
end | ||
end | ||
|
||
context 'when the CSRF token is invalid' do | ||
before do | ||
env['HTTP_X_CSRF_TOKEN'] = 'foo' | ||
end | ||
|
||
it 'returns false' do | ||
expect(described_class.verified?(env)).to be_falsey | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
$:.unshift File.expand_path('..', __FILE__) | ||
$:.unshift File.expand_path('../../lib', __FILE__) | ||
|
||
require 'simplecov' | ||
SimpleCov.start | ||
|
||
require 'rspec' | ||
require 'rack/test' | ||
require 'omniauth' | ||
|
||
require 'omniauth-rails/railtie' | ||
require 'omniauth-rails/request_forgery_protection' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.