Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not write or update sessions or their cookies for API access #14826

Merged
merged 2 commits into from
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/api/root_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ def allowed_content_types
%w(application/json application/hal+json)
end

# Prevent committing the session
# This prevents an unnecessary write when accessing the API
def skip_session_write
request.session_options[:skip] = true
end

def enforce_content_type
# Content-Type is not present in GET or DELETE requests
return if request.get? || request.delete?
Expand Down Expand Up @@ -325,6 +331,7 @@ def self.authentication_scope(sym)

# run authentication before each request
after_validation do
skip_session_write
authenticate
set_localization
enforce_content_type
Expand Down
Loading