summaryrefslogtreecommitdiff
path: root/lib/gitlab/akismet_helper.rb
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2016-04-27 22:04:40 -0700
committerStan Hu <stanhu@gmail.com>2016-04-27 22:12:55 -0700
commite99cf05875af4627e532fee77bd22574dde240d7 (patch)
treefff4014cf37f8817eac67d039a0ee35701338ac8 /lib/gitlab/akismet_helper.rb
parentc01ff1f54b55a60f7c7473d0d8a429d5cf9c1609 (diff)
downloadgitlab-ce-e99cf05875af4627e532fee77bd22574dde240d7.tar.gz
Use ActionDispatch Remote IP for Akismet checking
Previously all remote IPs appeared at 127.0.0.1, which made Akismet not very useful. Using the ActionDispatch Remote IP (http://api.rubyonrails.org/classes/ActionDispatch/RemoteIp.html) should provide more reliable results. Closes #16629
Diffstat (limited to 'lib/gitlab/akismet_helper.rb')
-rw-r--r--lib/gitlab/akismet_helper.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/gitlab/akismet_helper.rb b/lib/gitlab/akismet_helper.rb
index b366c89889e..04676fdb748 100644
--- a/lib/gitlab/akismet_helper.rb
+++ b/lib/gitlab/akismet_helper.rb
@@ -9,14 +9,22 @@ module Gitlab
Gitlab.config.gitlab.url)
end
+ def client_ip(env)
+ env['action_dispatch.remote_ip'].to_s
+ end
+
+ def user_agent(env)
+ env['HTTP_USER_AGENT']
+ end
+
def check_for_spam?(project, user)
akismet_enabled? && !project.team.member?(user)
end
def is_spam?(environment, user, text)
client = akismet_client
- ip_address = environment['REMOTE_ADDR']
- user_agent = environment['HTTP_USER_AGENT']
+ ip_address = client_ip(environment)
+ user_agent = user_agent(environment)
params = {
type: 'comment',