honeypot 0.0.7 → 0.0.8

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
data/honeypot.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{honeypot}
8
- s.version = "0.0.7"
8
+ s.version = "0.0.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Seamus Abshere"]
12
- s.date = %q{2010-07-02}
12
+ s.date = %q{2010-07-15}
13
13
  s.description = %q{Catch bad guys when they stick their hands in the honey.}
14
14
  s.email = %q{seamus@abshere.net}
15
15
  s.extra_rdoc_files = [
@@ -25,8 +25,8 @@ Gem::Specification.new do |s|
25
25
  "VERSION",
26
26
  "honeypot.gemspec",
27
27
  "lib/honeypot.rb",
28
+ "lib/honeypot/best_guess_routeable_remote_ip.rb",
28
29
  "lib/honeypot/ipaddr_ext.rb",
29
- "lib/honeypot/rack.rb",
30
30
  "lib/honeypot/rails.rb",
31
31
  "lib/honeypot/railtie.rb",
32
32
  "lib/honeypot/remote_host.rb",
data/lib/honeypot.rb CHANGED
@@ -13,9 +13,9 @@ require 'fast_timestamp'
13
13
  require 'honeypot/ipaddr_ext'
14
14
  require 'honeypot/remote_request'
15
15
  require 'honeypot/remote_host'
16
- require 'honeypot/rack'
16
+ require 'honeypot/best_guess_routeable_remote_ip'
17
17
 
18
- require 'honeypot/railtie' if defined?(Rails::Railtie)
18
+ require 'honeypot/railtie' if defined? ::Rails::Railtie
19
19
 
20
20
  module Honeypot
21
21
  def self.included(base)
@@ -26,12 +26,12 @@ module Honeypot
26
26
  end
27
27
 
28
28
  def log_action_dispatch_request(request)
29
- log_remote_request request.env['honeypot.remote_ip'], request.url, request.referer
29
+ log_remote_request request.env['honeypot.best_guess_routeable_remote_ip'], request.url, request.referer
30
30
  end
31
31
 
32
32
  def log_rack_env(env)
33
33
  request = ::Rack::Request.new env
34
- log_remote_request request.env['honeypot.remote_ip'], request.url, request.referer
34
+ log_remote_request request.env['honeypot.best_guess_routeable_remote_ip'], request.url, request.referer
35
35
  end
36
36
 
37
37
  def log_remote_request(ip_address, url, referer)
@@ -2,27 +2,27 @@
2
2
  # http://charlesmaxwood.com/sessions-in-rack-and-rails-metal/
3
3
  module Honeypot
4
4
  # Middleware for Rack applications. Remote hosts will be tied together with remote requests.
5
- class Rack
5
+ class BestGuessRouteableRemoteIp
6
6
  def initialize(app)
7
7
  @app = app
8
8
  end
9
9
 
10
10
  def call(env)
11
- remote_ip = _most_likely_remote_ip env
11
+ ip = _best_guess_remote_ip env
12
12
 
13
13
  # For the next request, in case the next time we see this session the remote ip is obscured
14
14
  # (for example, that happens if you're on engineyard and the request comes in over SSL)
15
- if env.has_key? 'rack.session' and remote_ip.routeable?
16
- env['rack.session']['honeypot.last_known_routeable_remote_ip'] = remote_ip.to_s
15
+ if env.has_key? 'rack.session' and ip.routeable?
16
+ env['rack.session']['honeypot.best_guess_routeable_remote_ip'] = ip.to_s
17
17
  end
18
18
 
19
19
  # For use by other middleware or the app itself
20
- env['honeypot.remote_ip'] = remote_ip.to_s
20
+ env['honeypot.best_guess_routeable_remote_ip'] = ip.to_s
21
21
 
22
22
  @app.call env
23
23
  end
24
24
 
25
- def _most_likely_remote_ip(env)
25
+ def _best_guess_remote_ip(env)
26
26
  candidates = _collect_possible_remote_ips env
27
27
  candidates.detect { |remote_ip| remote_ip.routeable? } || candidates.first
28
28
  end
@@ -39,9 +39,16 @@ module Honeypot
39
39
  end
40
40
  # saved by honeypot between requests
41
41
  if env.has_key? 'rack.session'
42
- candidates.push env['rack.session']['honeypot.last_known_routeable_remote_ip']
42
+ candidates.push env['rack.session']['honeypot.best_guess_routeable_remote_ip']
43
43
  end
44
- candidates.map! { |raw_ip_address| IPAddr.new raw_ip_address.to_s }
44
+ candidates.map! do |raw_ip_address|
45
+ begin
46
+ IPAddr.new raw_ip_address.to_s
47
+ rescue ArgumentError
48
+ # ignore it, maybe bad data got in here somehow
49
+ end
50
+ end
51
+ candidates.compact!
45
52
  candidates
46
53
  end
47
54
  end
@@ -1,5 +1,5 @@
1
1
  require 'honeypot'
2
2
 
3
- if defined?(::Rails.configuration) && ::Rails.configuration.respond_to?(:middleware)
4
- ::Rails.configuration.middleware.insert_after 'ActionController::Failsafe', ::Honeypot::Rack
5
- end
3
+ raise "rails 2.3 support isn't tested"
4
+
5
+ ::Rails.configuration.middleware.insert_after '::Rack::MethodOverride', '::Honeypot::BestGuessRouteableRemoteIp'
@@ -3,8 +3,7 @@ require 'rails'
3
3
 
4
4
  module Honeypot
5
5
  class Railtie < Rails::Railtie
6
- initializer 'honeypot.configure_rails_initialization' do |app|
7
- app.middleware.insert_after 'ActionDispatch::RemoteIp', ::Honeypot::Rack
8
- end
6
+ # more or less, this puts us after the rails helper stuff (ActionDispatch::RemoteIp) but before most custom middleware
7
+ config.app_middleware.insert_after '::Rack::MethodOverride', '::Honeypot::BestGuessRouteableRemoteIp'
9
8
  end
10
9
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: honeypot
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
9
+ - 8
10
+ version: 0.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Seamus Abshere
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-02 00:00:00 -04:00
18
+ date: 2010-07-15 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -116,8 +116,8 @@ files:
116
116
  - VERSION
117
117
  - honeypot.gemspec
118
118
  - lib/honeypot.rb
119
+ - lib/honeypot/best_guess_routeable_remote_ip.rb
119
120
  - lib/honeypot/ipaddr_ext.rb
120
- - lib/honeypot/rack.rb
121
121
  - lib/honeypot/rails.rb
122
122
  - lib/honeypot/railtie.rb
123
123
  - lib/honeypot/remote_host.rb