diff options
author | Rémy Coutable <remy@rymai.me> | 2016-04-28 13:09:44 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-04-28 13:09:44 +0000 |
commit | 5addff7e6c89f2cad6f1af814e02ceecd2aed55b (patch) | |
tree | f861e07e9a634d7f761ee7189d0f4a9d78e345ad /lib | |
parent | d4668825e4cb9c6c34b6f6530a4cb64d045b96d4 (diff) | |
parent | e99cf05875af4627e532fee77bd22574dde240d7 (diff) | |
download | gitlab-ce-5addff7e6c89f2cad6f1af814e02ceecd2aed55b.tar.gz |
Merge branch 'use-remote-ip-for-akismet' into 'master'
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
See merge request !3961
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/issues.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/akismet_helper.rb | 12 |
2 files changed, 12 insertions, 4 deletions
diff --git a/lib/api/issues.rb b/lib/api/issues.rb index 8aa08fd5acc..40928749481 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -24,8 +24,8 @@ module API def create_spam_log(project, current_user, attrs) params = attrs.merge({ - source_ip: env['REMOTE_ADDR'], - user_agent: env['HTTP_USER_AGENT'], + source_ip: client_ip(env), + user_agent: user_agent(env), noteable_type: 'Issue', via_api: true }) 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', |