imperva-rails 0.1.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.
- checksums.yaml +7 -0
- data/.circleci/config.yml +54 -0
- data/.github/dependabot.yml +8 -0
- data/.gitignore +15 -0
- data/.rspec +4 -0
- data/.rubocop.yml +5 -0
- data/.rubocop_airbnb.yml +2 -0
- data/.rubocop_todo.yml +51 -0
- data/Appraisals +15 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +51 -0
- data/Rakefile +24 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/rails_5.2.gemfile +7 -0
- data/gemfiles/rails_6.0.gemfile +7 -0
- data/gemfiles/rails_6.1.gemfile +7 -0
- data/gemfiles/rails_7.0.gemfile +7 -0
- data/imperva-rails.gemspec +40 -0
- data/lib/imperva/rails/railtie.rb +114 -0
- data/lib/imperva/rails/version.rb +5 -0
- data/lib/imperva/rails.rb +10 -0
- metadata +268 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 632f707c626a71ce88564695c4104e9dc59400c7dc7704110ac0800de8c7b536
|
|
4
|
+
data.tar.gz: bb5b30cb6d595b52c4235c6ac80dea8fa7d149017ec405c4c2ac47b2a8652f5a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 5e42a43b326ee2cdb332a67e9391dc5cb34d8f299f48a335a30159945304f2d7e3cb67e4ae072e365e4b142fc6cf700e972ff42ec259a7ec85f1865956a31e8c
|
|
7
|
+
data.tar.gz: 91087d59a53f21e98947308841f456bdc5538095552428dba2608b43646e92d2505e99578da2d8cfcc6635fc117ad7b2c30a2e887505534334fa6c041be7d2c1
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Ruby CircleCI 2.0 configuration file
|
|
2
|
+
#
|
|
3
|
+
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
|
|
4
|
+
#
|
|
5
|
+
version: 2
|
|
6
|
+
jobs:
|
|
7
|
+
build:
|
|
8
|
+
docker:
|
|
9
|
+
# specify the version you desire here
|
|
10
|
+
- image: cimg/ruby:2.7
|
|
11
|
+
|
|
12
|
+
working_directory: ~/repo
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- checkout
|
|
16
|
+
|
|
17
|
+
# Download and cache dependencies
|
|
18
|
+
- restore_cache:
|
|
19
|
+
keys:
|
|
20
|
+
- v1-dependencies-{{ checksum "cloudflare-rails.gemspec" }}-{{ checksum "Appraisals" }}
|
|
21
|
+
# fallback to using the latest cache if no exact match is found
|
|
22
|
+
- v1-dependencies-
|
|
23
|
+
|
|
24
|
+
- run:
|
|
25
|
+
name: install bundler
|
|
26
|
+
command: |
|
|
27
|
+
gem install bundler -v $(grep bundler cloudflare-rails.gemspec |awk {'print $4'}|sed 's/"//g')
|
|
28
|
+
|
|
29
|
+
- run:
|
|
30
|
+
name: install dependencies
|
|
31
|
+
command: |
|
|
32
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
|
33
|
+
|
|
34
|
+
- run:
|
|
35
|
+
name: install appraisal versions
|
|
36
|
+
command: |
|
|
37
|
+
bundle exec appraisal install
|
|
38
|
+
|
|
39
|
+
- save_cache:
|
|
40
|
+
paths:
|
|
41
|
+
- ./vendor/bundle
|
|
42
|
+
key: v1-dependencies-{{ checksum "cloudflare-rails.gemspec" }}-{{ checksum "Appraisals" }}
|
|
43
|
+
|
|
44
|
+
# run tests!
|
|
45
|
+
- run:
|
|
46
|
+
name: run tests
|
|
47
|
+
command: |
|
|
48
|
+
bundle exec appraisal rake
|
|
49
|
+
# collect reports
|
|
50
|
+
- store_test_results:
|
|
51
|
+
path: tmp/rspec
|
|
52
|
+
- store_artifacts:
|
|
53
|
+
path: tmp/rspec
|
|
54
|
+
destination: test-results
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.rubocop_airbnb.yml
ADDED
data/.rubocop_todo.yml
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# This configuration was generated by
|
|
2
|
+
# `rubocop --auto-gen-config`
|
|
3
|
+
# on 2022-04-14 23:18:15 UTC using RuboCop version 0.93.1.
|
|
4
|
+
# The point is for the user to remove these configuration records
|
|
5
|
+
# one by one as the offenses are removed from the code base.
|
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
|
8
|
+
|
|
9
|
+
# Offense count: 4
|
|
10
|
+
# Cop supports --auto-correct.
|
|
11
|
+
Layout/MultilineBlockLayout:
|
|
12
|
+
Exclude:
|
|
13
|
+
- 'spec/cloudflare/rails_spec.rb'
|
|
14
|
+
|
|
15
|
+
# Offense count: 4
|
|
16
|
+
# Cop supports --auto-correct.
|
|
17
|
+
# Configuration parameters: EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
|
|
18
|
+
# SupportedStyles: space, no_space
|
|
19
|
+
# SupportedStylesForEmptyBraces: space, no_space
|
|
20
|
+
Layout/SpaceInsideBlockBraces:
|
|
21
|
+
EnforcedStyle: space
|
|
22
|
+
|
|
23
|
+
# Offense count: 1
|
|
24
|
+
# Cop supports --auto-correct.
|
|
25
|
+
Rails/ApplicationController:
|
|
26
|
+
Exclude:
|
|
27
|
+
- 'spec/cloudflare/rails_spec.rb'
|
|
28
|
+
|
|
29
|
+
# Offense count: 1
|
|
30
|
+
# Cop supports --auto-correct.
|
|
31
|
+
Rails/NegateInclude:
|
|
32
|
+
Exclude:
|
|
33
|
+
- 'lib/cloudflare/rails/railtie.rb'
|
|
34
|
+
|
|
35
|
+
# Offense count: 4
|
|
36
|
+
# Cop supports --auto-correct.
|
|
37
|
+
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners, BracesRequiredMethods.
|
|
38
|
+
# SupportedStyles: line_count_based, semantic, braces_for_chaining
|
|
39
|
+
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
|
|
40
|
+
# FunctionalMethods: let, let!, subject, watch
|
|
41
|
+
# IgnoredMethods: lambda, proc, it
|
|
42
|
+
Style/BlockDelimiters:
|
|
43
|
+
Exclude:
|
|
44
|
+
- 'spec/cloudflare/rails_spec.rb'
|
|
45
|
+
|
|
46
|
+
# Offense count: 9
|
|
47
|
+
# Cop supports --auto-correct.
|
|
48
|
+
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
|
49
|
+
# URISchemes: http, https
|
|
50
|
+
Layout/LineLength:
|
|
51
|
+
Max: 126
|
data/Appraisals
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
appraise "rails-5.2" do
|
|
2
|
+
gem "rails", "~> 5.2.0"
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
appraise "rails-6.0" do
|
|
6
|
+
gem "rails", "~> 6.0.0"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
appraise "rails-6.1" do
|
|
10
|
+
gem "rails", "~> 6.1.0"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
appraise "rails-7.0" do
|
|
14
|
+
gem "rails", git: "https://github.com/rails/rails", branch: "main"
|
|
15
|
+
end
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
All notable changes to this project will be documented in this file.
|
|
3
|
+
|
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [0.1.0] - 2020-09-29
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- Cloning cloudflare-rails but for imperva with imperva download.
|
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014-2017 jonathan schatz
|
|
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,51 @@
|
|
|
1
|
+
# Imperva::Rails [](https://badge.fury.io/rb/imperva-rails) [](https://circleci.com/gh/modosc/imperva-rails/tree/main)
|
|
2
|
+
This gem correctly configures Rails for [Imperva](https://www.imperva.com) so that `request.remote_ip` / `request.ip` both work correctly.
|
|
3
|
+
|
|
4
|
+
## Rails Compatibility
|
|
5
|
+
|
|
6
|
+
This gem requires `railties`, `activesupport`, and `actionpack` >= `5.2`.
|
|
7
|
+
|
|
8
|
+
For Rails `5.0` and `5.1` use `2.0.0`.
|
|
9
|
+
|
|
10
|
+
For Rails `4.2` use `0.1.x`.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
Add this line to your application's `Gemfile`:
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
17
|
+
group :production do
|
|
18
|
+
# or :staging or :beta or whatever environments you are using imperva in.
|
|
19
|
+
# you probably don't want this for :test or :development
|
|
20
|
+
gem 'imperva-rails'
|
|
21
|
+
end
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
And then execute:
|
|
25
|
+
|
|
26
|
+
$ bundle
|
|
27
|
+
|
|
28
|
+
## Problem
|
|
29
|
+
|
|
30
|
+
Using Imperva means it's hard to identify the IP address of incoming requests since all requests are proxied through Imperva's infrastructure. Imperva provides a [Incap-Client-IP](https://docs.imperva.com/bundle/cloud-application-security/page/onboarding/setup-checklist.htm#:~:text=When%20working%20with%20Imperva%20your,7.) header which can be used to identify the originating IP address of a request. However, this header alone doesn't verify a request is legitimate. If an attacker has found the actual IP address of your server they could spoof this header and masquerade as legitimate traffic.
|
|
31
|
+
|
|
32
|
+
`imperva-rails` mitigates this attack by checking that the originating ip address of any incoming connection is from one of Imperva's ip address ranges. If so, the incoming `X-Forwarded-For` header is trusted and used as the ip address provided to `rack` and `rails` (via `request.ip` and `request.remote_ip`). If the incoming connection does not originate from a Imperva server then the `X-Forwarded-For` header is ignored and the actual remote ip address is used.
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
This codef will fetch Imperva's current [IPv4 and IPv6](https://my.imperva.com/api/integration/v1/ips) list, store them in `Rails.cache`, and add them to `config.imperva.ips`. The `X-Forwarded-For` header will then be trusted only from those ip addresses.
|
|
36
|
+
|
|
37
|
+
You can configure the HTTP `timeout` and `expires_in` cache parameters inside of your rails config:
|
|
38
|
+
```ruby
|
|
39
|
+
config.imperva.expires_in = 12.hours # default value
|
|
40
|
+
config.imperva.timeout = 5.seconds # default value
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Development
|
|
44
|
+
|
|
45
|
+
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.
|
|
46
|
+
|
|
47
|
+
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).
|
|
48
|
+
|
|
49
|
+
## Contributing
|
|
50
|
+
|
|
51
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/modosc/imperva-rails.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
|
2
|
+
require "rspec/core/rake_task"
|
|
3
|
+
|
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
5
|
+
|
|
6
|
+
task :without_rack_attack do
|
|
7
|
+
ENV.delete 'RACK_ATTACK'
|
|
8
|
+
Rake::Task["spec"].reenable
|
|
9
|
+
Rake::Task["spec"].invoke
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
task :with_rack_attack_first do
|
|
13
|
+
ENV['RACK_ATTACK'] = 'first'
|
|
14
|
+
Rake::Task["spec"].reenable
|
|
15
|
+
Rake::Task["spec"].invoke
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
task :with_rack_attack_last do
|
|
19
|
+
ENV['RACK_ATTACK'] = 'last'
|
|
20
|
+
Rake::Task["spec"].reenable
|
|
21
|
+
Rake::Task["spec"].invoke
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
task :default => [:without_rack_attack, :with_rack_attack_first, :with_rack_attack_last]
|
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "imperva/rails"
|
|
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
|
data/bin/setup
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
+
require 'imperva/rails/version'
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |spec|
|
|
8
|
+
spec.name = "imperva-rails"
|
|
9
|
+
spec.version = Imperva::Rails::VERSION
|
|
10
|
+
spec.authors = ["jonathan schatz/jorge cuevas"]
|
|
11
|
+
spec.email = ["jocuman@users.noreply.github.com"]
|
|
12
|
+
|
|
13
|
+
spec.summary = "This gem configures Rails for Imperva so that request.ip and request.remote_ip and work correctly."
|
|
14
|
+
spec.description = ""
|
|
15
|
+
spec.homepage = "https://github.com/jocuman/imperva-rails"
|
|
16
|
+
spec.license = "MIT"
|
|
17
|
+
|
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
19
|
+
spec.bindir = "exe"
|
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
21
|
+
spec.require_paths = ["lib"]
|
|
22
|
+
|
|
23
|
+
spec.add_development_dependency "bundler", ">= 2.1.2"
|
|
24
|
+
spec.add_development_dependency "rake", "~> 13.0.1"
|
|
25
|
+
spec.add_development_dependency "rspec_junit_formatter", "~> 0.5.1"
|
|
26
|
+
spec.add_development_dependency "rspec-rails", "~> 5.0.1"
|
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.11.0"
|
|
28
|
+
spec.add_development_dependency "rubocop-airbnb", "~> 4.0.0"
|
|
29
|
+
spec.add_development_dependency "webmock", "~> 3.14.0"
|
|
30
|
+
spec.add_development_dependency "rack-attack", "~> 6.6.1"
|
|
31
|
+
spec.add_development_dependency "pry-byebug"
|
|
32
|
+
spec.add_development_dependency "appraisal"
|
|
33
|
+
|
|
34
|
+
spec.add_dependency "railties", ">= 5.2", "< 7.1.0"
|
|
35
|
+
spec.add_dependency "activesupport", ">= 5.2", "< 7.1.0"
|
|
36
|
+
spec.add_dependency "actionpack", ">= 5.2", "< 7.1.0"
|
|
37
|
+
|
|
38
|
+
# we need Module#prepend
|
|
39
|
+
spec.required_ruby_version = '>= 2.0'
|
|
40
|
+
end
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
require "active_support/core_ext/integer/time"
|
|
2
|
+
|
|
3
|
+
module Imperva
|
|
4
|
+
module Rails
|
|
5
|
+
class Railtie < ::Rails::Railtie
|
|
6
|
+
# patch rack::request::helpers to use our imperva ips - this way request.ip is
|
|
7
|
+
# correct inside of rack and rails
|
|
8
|
+
module CheckTrustedProxies
|
|
9
|
+
def trusted_proxy?(ip)
|
|
10
|
+
matching = ::Rails.application.config.imperva.ips.any? do |proxy|
|
|
11
|
+
begin
|
|
12
|
+
proxy === ip
|
|
13
|
+
rescue IPAddr::InvalidAddressError
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
matching || super
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# patch ActionDispatch::RemoteIP to use our imperva ips - this way
|
|
21
|
+
# request.remote_ip is correct inside of rails
|
|
22
|
+
module RemoteIpProxies
|
|
23
|
+
def proxies
|
|
24
|
+
super + ::Rails.application.config.imperva.ips
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class Importer
|
|
29
|
+
# Exceptions contain the Net::HTTP
|
|
30
|
+
# response object accessible via the {#response} method.
|
|
31
|
+
class ResponseError < StandardError
|
|
32
|
+
# Returns the response of the last request
|
|
33
|
+
# @return [Net::HTTPResponse] A subclass of Net::HTTPResponse, e.g.
|
|
34
|
+
# Net::HTTPOK
|
|
35
|
+
attr_reader :response
|
|
36
|
+
|
|
37
|
+
# Instantiate an instance of ResponseError with a Net::HTTPResponse object
|
|
38
|
+
# @param [Net::HTTPResponse]
|
|
39
|
+
def initialize(response)
|
|
40
|
+
@response = response
|
|
41
|
+
super(response)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
BASE_URL = 'https://my.imperva.com/api/integration/v1/ips'.freeze
|
|
46
|
+
|
|
47
|
+
class << self
|
|
48
|
+
def fetch
|
|
49
|
+
uri = URI("#{BASE_URL}")
|
|
50
|
+
|
|
51
|
+
resp = Net::HTTP.start(uri.host,
|
|
52
|
+
uri.port,
|
|
53
|
+
use_ssl: true,
|
|
54
|
+
read_timeout: 5) do |http|
|
|
55
|
+
req = Net::HTTP::Post.new(uri)
|
|
56
|
+
req.set_form_data('resp_format' => 'text')
|
|
57
|
+
|
|
58
|
+
http.request(req)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
if resp.is_a?(Net::HTTPSuccess)
|
|
62
|
+
resp.body.split("\n").reject(&:blank?).map { |ip| IPAddr.new ip }
|
|
63
|
+
else
|
|
64
|
+
raise ResponseError, resp
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def fetch_with_cache
|
|
69
|
+
::Rails.cache.fetch("imperva-rails:ips", expires_in: ::Rails.application.config.imperva.expires_in) do
|
|
70
|
+
send :fetch
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# setup defaults before we configure our app.
|
|
77
|
+
DEFAULTS = {
|
|
78
|
+
expires_in: 12.hours,
|
|
79
|
+
timeout: 5.seconds,
|
|
80
|
+
ips: [],
|
|
81
|
+
}.freeze
|
|
82
|
+
|
|
83
|
+
config.before_configuration do |app|
|
|
84
|
+
app.config.imperva = ActiveSupport::OrderedOptions.new
|
|
85
|
+
app.config.imperva.reverse_merge! DEFAULTS
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# we set config.imperva.ips after_initialize so that our cache will
|
|
89
|
+
# be correctly setup. we rescue and log errors so that failures won't prevent
|
|
90
|
+
# rails from booting
|
|
91
|
+
config.after_initialize do |app|
|
|
92
|
+
begin
|
|
93
|
+
::Rails.application.config.imperva.ips = Importer.fetch_with_cache
|
|
94
|
+
rescue Importer::ResponseError => e
|
|
95
|
+
::Rails.logger.error "Imperva::Rails: Couldn't import ip blocks from Imperva: #{e.response}"
|
|
96
|
+
rescue StandardError => e
|
|
97
|
+
::Rails.logger.error "Imperva::Rails: Got exception importing: #{e}"
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
initializer "my_railtie.configure_rails_initialization" do
|
|
101
|
+
Rack::Request::Helpers.prepend Imperva::Rails::Railtie::CheckTrustedProxies
|
|
102
|
+
|
|
103
|
+
ObjectSpace.each_object(Class).
|
|
104
|
+
select do |c|
|
|
105
|
+
c.included_modules.include?(Rack::Request::Helpers) &&
|
|
106
|
+
!c.included_modules.include?(Imperva::Rails::Railtie::CheckTrustedProxies)
|
|
107
|
+
end.
|
|
108
|
+
map { |c| c .prepend Imperva::Rails::Railtie::CheckTrustedProxies }
|
|
109
|
+
|
|
110
|
+
ActionDispatch::RemoteIp.prepend Imperva::Rails::Railtie::RemoteIpProxies
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: imperva-rails
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- jonathan schatz/jorge cuevas
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2022-08-26 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: 2.1.2
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 2.1.2
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 13.0.1
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 13.0.1
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec_junit_formatter
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 0.5.1
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 0.5.1
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rspec-rails
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 5.0.1
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 5.0.1
|
|
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.11.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.11.0
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rubocop-airbnb
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: 4.0.0
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: 4.0.0
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: webmock
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: 3.14.0
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: 3.14.0
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: rack-attack
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - "~>"
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: 6.6.1
|
|
118
|
+
type: :development
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - "~>"
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: 6.6.1
|
|
125
|
+
- !ruby/object:Gem::Dependency
|
|
126
|
+
name: pry-byebug
|
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
|
128
|
+
requirements:
|
|
129
|
+
- - ">="
|
|
130
|
+
- !ruby/object:Gem::Version
|
|
131
|
+
version: '0'
|
|
132
|
+
type: :development
|
|
133
|
+
prerelease: false
|
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
135
|
+
requirements:
|
|
136
|
+
- - ">="
|
|
137
|
+
- !ruby/object:Gem::Version
|
|
138
|
+
version: '0'
|
|
139
|
+
- !ruby/object:Gem::Dependency
|
|
140
|
+
name: appraisal
|
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
|
142
|
+
requirements:
|
|
143
|
+
- - ">="
|
|
144
|
+
- !ruby/object:Gem::Version
|
|
145
|
+
version: '0'
|
|
146
|
+
type: :development
|
|
147
|
+
prerelease: false
|
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
149
|
+
requirements:
|
|
150
|
+
- - ">="
|
|
151
|
+
- !ruby/object:Gem::Version
|
|
152
|
+
version: '0'
|
|
153
|
+
- !ruby/object:Gem::Dependency
|
|
154
|
+
name: railties
|
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
|
156
|
+
requirements:
|
|
157
|
+
- - ">="
|
|
158
|
+
- !ruby/object:Gem::Version
|
|
159
|
+
version: '5.2'
|
|
160
|
+
- - "<"
|
|
161
|
+
- !ruby/object:Gem::Version
|
|
162
|
+
version: 7.1.0
|
|
163
|
+
type: :runtime
|
|
164
|
+
prerelease: false
|
|
165
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
166
|
+
requirements:
|
|
167
|
+
- - ">="
|
|
168
|
+
- !ruby/object:Gem::Version
|
|
169
|
+
version: '5.2'
|
|
170
|
+
- - "<"
|
|
171
|
+
- !ruby/object:Gem::Version
|
|
172
|
+
version: 7.1.0
|
|
173
|
+
- !ruby/object:Gem::Dependency
|
|
174
|
+
name: activesupport
|
|
175
|
+
requirement: !ruby/object:Gem::Requirement
|
|
176
|
+
requirements:
|
|
177
|
+
- - ">="
|
|
178
|
+
- !ruby/object:Gem::Version
|
|
179
|
+
version: '5.2'
|
|
180
|
+
- - "<"
|
|
181
|
+
- !ruby/object:Gem::Version
|
|
182
|
+
version: 7.1.0
|
|
183
|
+
type: :runtime
|
|
184
|
+
prerelease: false
|
|
185
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
186
|
+
requirements:
|
|
187
|
+
- - ">="
|
|
188
|
+
- !ruby/object:Gem::Version
|
|
189
|
+
version: '5.2'
|
|
190
|
+
- - "<"
|
|
191
|
+
- !ruby/object:Gem::Version
|
|
192
|
+
version: 7.1.0
|
|
193
|
+
- !ruby/object:Gem::Dependency
|
|
194
|
+
name: actionpack
|
|
195
|
+
requirement: !ruby/object:Gem::Requirement
|
|
196
|
+
requirements:
|
|
197
|
+
- - ">="
|
|
198
|
+
- !ruby/object:Gem::Version
|
|
199
|
+
version: '5.2'
|
|
200
|
+
- - "<"
|
|
201
|
+
- !ruby/object:Gem::Version
|
|
202
|
+
version: 7.1.0
|
|
203
|
+
type: :runtime
|
|
204
|
+
prerelease: false
|
|
205
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
206
|
+
requirements:
|
|
207
|
+
- - ">="
|
|
208
|
+
- !ruby/object:Gem::Version
|
|
209
|
+
version: '5.2'
|
|
210
|
+
- - "<"
|
|
211
|
+
- !ruby/object:Gem::Version
|
|
212
|
+
version: 7.1.0
|
|
213
|
+
description: ''
|
|
214
|
+
email:
|
|
215
|
+
- jocuman@users.noreply.github.com
|
|
216
|
+
executables: []
|
|
217
|
+
extensions: []
|
|
218
|
+
extra_rdoc_files: []
|
|
219
|
+
files:
|
|
220
|
+
- ".circleci/config.yml"
|
|
221
|
+
- ".github/dependabot.yml"
|
|
222
|
+
- ".gitignore"
|
|
223
|
+
- ".rspec"
|
|
224
|
+
- ".rubocop.yml"
|
|
225
|
+
- ".rubocop_airbnb.yml"
|
|
226
|
+
- ".rubocop_todo.yml"
|
|
227
|
+
- Appraisals
|
|
228
|
+
- CHANGELOG.md
|
|
229
|
+
- Gemfile
|
|
230
|
+
- LICENSE
|
|
231
|
+
- README.md
|
|
232
|
+
- Rakefile
|
|
233
|
+
- bin/console
|
|
234
|
+
- bin/setup
|
|
235
|
+
- gemfiles/.bundle/config
|
|
236
|
+
- gemfiles/rails_5.2.gemfile
|
|
237
|
+
- gemfiles/rails_6.0.gemfile
|
|
238
|
+
- gemfiles/rails_6.1.gemfile
|
|
239
|
+
- gemfiles/rails_7.0.gemfile
|
|
240
|
+
- imperva-rails.gemspec
|
|
241
|
+
- lib/imperva/rails.rb
|
|
242
|
+
- lib/imperva/rails/railtie.rb
|
|
243
|
+
- lib/imperva/rails/version.rb
|
|
244
|
+
homepage: https://github.com/jocuman/imperva-rails
|
|
245
|
+
licenses:
|
|
246
|
+
- MIT
|
|
247
|
+
metadata: {}
|
|
248
|
+
post_install_message:
|
|
249
|
+
rdoc_options: []
|
|
250
|
+
require_paths:
|
|
251
|
+
- lib
|
|
252
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
253
|
+
requirements:
|
|
254
|
+
- - ">="
|
|
255
|
+
- !ruby/object:Gem::Version
|
|
256
|
+
version: '2.0'
|
|
257
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
258
|
+
requirements:
|
|
259
|
+
- - ">="
|
|
260
|
+
- !ruby/object:Gem::Version
|
|
261
|
+
version: '0'
|
|
262
|
+
requirements: []
|
|
263
|
+
rubygems_version: 3.1.6
|
|
264
|
+
signing_key:
|
|
265
|
+
specification_version: 4
|
|
266
|
+
summary: This gem configures Rails for Imperva so that request.ip and request.remote_ip
|
|
267
|
+
and work correctly.
|
|
268
|
+
test_files: []
|