diff options
author | Claire <claire.github-309c@sitedethib.com> | 2022-01-16 18:11:20 +0100 |
---|---|---|
committer | Claire <claire.github-309c@sitedethib.com> | 2022-01-16 18:11:20 +0100 |
commit | b61c3ddff8338432fdc287f6bebbf76a12859c17 (patch) | |
tree | 702e67a92f3a6e84feed3c06126b14a7e4ecab35 /config/initializers | |
parent | 07cb948f39464b11959fc506b673a90d9524e519 (diff) | |
parent | 462bc65112276f4cbfbeb1efd8cd452fda7d0f23 (diff) |
Merge branch 'main' into glitch-soc/merge-upstream
Conflicts: - `README.md`: Upstream added some text, but our README is completely different. Kept our README unchanged.
Diffstat (limited to 'config/initializers')
-rw-r--r-- | config/initializers/devise.rb | 15 | ||||
-rw-r--r-- | config/initializers/rack_attack.rb | 2 |
2 files changed, 9 insertions, 8 deletions
diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 5232e6cfd..b434c68fa 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -1,11 +1,8 @@ require 'devise/strategies/authenticatable' Warden::Manager.after_set_user except: :fetch do |user, warden| - if user.session_active?(warden.cookies.signed['_session_id'] || warden.raw_session['auth_id']) - session_id = warden.cookies.signed['_session_id'] || warden.raw_session['auth_id'] - else - session_id = user.activate_session(warden.request) - end + session_id = warden.cookies.signed['_session_id'] || warden.raw_session['auth_id'] + session_id = user.activate_session(warden.request) unless user.session_activations.active?(session_id) warden.cookies.signed['_session_id'] = { value: session_id, @@ -17,9 +14,13 @@ Warden::Manager.after_set_user except: :fetch do |user, warden| end Warden::Manager.after_fetch do |user, warden| - if user.session_active?(warden.cookies.signed['_session_id'] || warden.raw_session['auth_id']) + session_id = warden.cookies.signed['_session_id'] || warden.raw_session['auth_id'] + + if session_id && (session = user.session_activations.find_by(session_id: session_id)) + session.update(ip: warden.request.remote_ip) if session.ip != warden.request.remote_ip + warden.cookies.signed['_session_id'] = { - value: warden.cookies.signed['_session_id'] || warden.raw_session['auth_id'], + value: session_id, expires: 1.year.from_now, httponly: true, secure: (Rails.env.production? || ENV['LOCAL_HTTPS'] == 'true'), diff --git a/config/initializers/rack_attack.rb b/config/initializers/rack_attack.rb index 2a6cca7dc..964d4266d 100644 --- a/config/initializers/rack_attack.rb +++ b/config/initializers/rack_attack.rb @@ -55,7 +55,7 @@ class Rack::Attack end throttle('throttle_api_media', limit: 30, period: 30.minutes) do |req| - req.authenticated_user_id if req.post? && req.path.start_with?('/api/v1/media') + req.authenticated_user_id if req.post? && req.path.match?('^/api/v\d+/media') end throttle('throttle_media_proxy', limit: 30, period: 10.minutes) do |req| |