8000 fix ReDoS · sinatra/sinatra@580b271 · GitHub
[go: up one dir, main page]

Skip to content

Commit 580b271

Browse files
ooooooo-qjkowens
authored andcommitted
fix ReDoS
1 parent 9031a44 commit 580b271

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

rack-protection/lib/rack/protection/ip_spoofing.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ class IPSpoofing < Base
1313

1414
def accepts?(env)
1515
return true unless env.include? 'HTTP_X_FORWARDED_FOR'
16-
ips = env['HTTP_X_FORWARDED_FOR'].split(/\s*,\s*/)
17-
return false if env.include? 'HTTP_CLIENT_IP' and not ips.include? env['HTTP_CLIENT_IP']
18-
return false if env.include? 'HTTP_X_REAL_IP' and not ips.include? env['HTTP_X_REAL_IP']
16+
17+
ips = env['HTTP_X_FORWARDED_FOR'].split(',').map(&:strip)
18+
return false if env.include?('HTTP_CLIENT_IP') && (!ips.include? env['HTTP_CLIENT_IP'])
19+
return false if env.include?('HTTP_X_REAL_IP') && (!ips.include? env['HTTP_X_REAL_IP'])
20+
1921
true
2022
end
2123
end

0 commit comments

Comments
 (0)
0