Skip to content

Commit

Permalink
Add 'private' to Cache-Control, match Rails expectations (mastodon#20608
Browse files Browse the repository at this point in the history
)

Several controlers set quite intricate Cache-Control headers in order to
hopefully not be cached by any intermediate proxies or local caches. Unfortunately,
these headers are processed by ActionDispatch::HTTP::Cache in a way that squashes
and discards any values set alongside no-store other than private:
https://github.com/rails/rails/blob/8015c2c2cf5c8718449677570f372ceb01318a32/actionpack/lib/action_dispatch/http/cache.rb#L207-L209

We want to preserve no-store on these responses, but we might as well remove
parts that are going to be dropped anyway. As many of the endpoints in these
controllers are private to a particular user, we should also add "private",
which will be preserved alongside no-store.
  • Loading branch information
daxtens authored Nov 16, 2022
1 parent ac7a29f commit 4d85c27
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def authorize_if_got_token!(*scopes)
end

def set_cache_headers
response.headers['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
response.headers['Cache-Control'] = 'private, no-store'
end

def disallow_unauthenticated_api_access?
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/auth/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,6 @@ def require_rules_acceptance!
end

def set_cache_headers
response.headers['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
response.headers['Cache-Control'] = 'private, no-store'
end
end
2 changes: 1 addition & 1 deletion app/controllers/oauth/authorizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ def truthy_param?(key)
end

def set_cache_headers
response.headers['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
response.headers['Cache-Control'] = 'private, no-store'
end
end
2 changes: 1 addition & 1 deletion app/controllers/settings/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def set_body_classes
end

def set_cache_headers
response.headers['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
response.headers['Cache-Control'] = 'private, no-store'
end

def require_not_suspended!
Expand Down

0 comments on commit 4d85c27

Please sign in to comment.