Skip to content

Commit a9d168c

Browse files
authored
Merge pull request #26 from securenative/dev
Fix proxy headers and code cleanups
2 parents f4055fb + e36c1fb commit a9d168c

File tree

6 files changed

+17
-12
lines changed

6 files changed

+17
-12
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
securenative (0.1.31)
4+
securenative (0.1.32)
55

66
GEM
77
remote: https://rubygems.org/

lib/securenative/utils/request_utils.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,26 @@ def self.get_secure_header_from_request(headers)
1717
end
1818

1919
def self.get_client_ip_from_request(request, options)
20-
unless options.nil?
21-
for header in options.proxy_headers do
20+
unless options.proxy_headers.nil?
21+
options.proxy_headers.each { |header|
2222
begin
2323
h = request.env[header]
24-
unless !h.nil?
24+
if h.nil?
2525
h = request.env[self.parse_ip(header)]
2626
end
2727
return h.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless h.nil?
2828
rescue NoMethodError
2929
begin
3030
h = request[header]
31-
unless !h.nil?
31+
if h.nil?
3232
h = request.env[self.parse_ip(header)]
3333
end
3434
return h.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless h.nil?
3535
rescue NoMethodError
36+
# Ignored
3637
end
3738
end
38-
end
39+
}
3940
end
4041

4142
begin
@@ -46,6 +47,7 @@ def self.get_client_ip_from_request(request, options)
4647
x_forwarded_for = request['HTTP_X_FORWARDED_FOR']
4748
return x_forwarded_for.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless x_forwarded_for.nil?
4849
rescue NoMethodError
50+
# Ignored
4951
end
5052
end
5153

@@ -57,6 +59,7 @@ def self.get_client_ip_from_request(request, options)
5759
x_forwarded_for = request['HTTP_X_REAL_IP']
5860
return x_forwarded_for.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless x_forwarded_for.nil?
5961
rescue NoMethodError
62+
# Ignored
6063
end
6164
end
6265

@@ -68,12 +71,14 @@ def self.get_client_ip_from_request(request, options)
6871
x_forwarded_for = request['REMOTE_ADDR']
6972
return x_forwarded_for.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless x_forwarded_for.nil?
7073
rescue NoMethodError
74+
# Ignored
7175
end
7276
end
7377

7478
begin
7579
return request.ip unless request.ip.nil?
7680
rescue NoMethodError
81+
# Ignored
7782
end
7883

7984
''

lib/securenative/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module SecureNative
4-
VERSION = '0.1.31'
4+
VERSION = '0.1.32'
55
end

spec/securenative/spec_api_manager.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
5656
'Authorization' => 'YOUR_API_KEY',
5757
'Content-Type' => 'application/json',
58-
'Sn-Version' => '0.1.31',
58+
'Sn-Version' => '0.1.32',
5959
'User-Agent' => 'SecureNative-ruby'
6060
}
6161
).to_return(status: 200, body: '', headers: {})

spec/securenative/spec_event_manager.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def initialize
2929
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
3030
'Authorization' => 'YOUR_API_KEY',
3131
'Content-Type' => 'application/json',
32-
'Sn-Version' => '0.1.31',
32+
'Sn-Version' => '0.1.32',
3333
'User-Agent' => 'SecureNative-ruby'
3434
})
3535
.to_return(status: 200, body: '', headers: {})
@@ -53,7 +53,7 @@ def initialize
5353
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
5454
'Authorization' => 'YOUR_API_KEY',
5555
'Content-Type' => 'application/json',
56-
'Sn-Version' => '0.1.31',
56+
'Sn-Version' => '0.1.32',
5757
'User-Agent' => 'SecureNative-ruby'
5858
})
5959
.to_return(status: 401, body: '', headers: {})
@@ -74,7 +74,7 @@ def initialize
7474
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
7575
'Authorization' => 'YOUR_API_KEY',
7676
'Content-Type' => 'application/json',
77-
'Sn-Version' => '0.1.31',
77+
'Sn-Version' => '0.1.32',
7878
'User-Agent' => 'SecureNative-ruby'
7979
})
8080
.to_return(status: 500, body: '', headers: {})

spec/securenative/spec_http_client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
1616
'Authorization' => 'YOUR_API_KEY',
1717
'Content-Type' => 'application/json',
18-
'Sn-Version' => '0.1.31',
18+
'Sn-Version' => '0.1.32',
1919
'User-Agent' => 'SecureNative-ruby'
2020
}).to_return(status: 200, body: '', headers: {})
2121

0 commit comments

Comments
 (0)