Skip to content

A platform for community discussion. Free, open, simple.

FIX: Strip `discourse-logged-in` header during `force_anonymous!` (#14533)

David Taylor7a52ce0d6dc6
diff --git a/lib/middleware/anonymous_cache.rb b/lib/middleware/anonymous_cache.rb
index 9fe8c8cd5b4..a62fb01836c 100644
--- a/lib/middleware/anonymous_cache.rb
+++ b/lib/middleware/anonymous_cache.rb
@@ -171,6 +171,7 @@ module Middleware
def force_anonymous!
@env[Auth::DefaultCurrentUserProvider::USER_API_KEY] = nil
@env['HTTP_COOKIE'] = nil
+ @env['HTTP_DISCOURSE_LOGGED_IN'] = nil
@env['rack.request.cookie.hash'] = {}
@env['rack.request.cookie.string'] = ''
@env['_bypass_cache'] = nil
diff --git a/spec/components/middleware/anonymous_cache_spec.rb b/spec/components/middleware/anonymous_cache_spec.rb
index c9ad5b558ad..e0b23c8a54f 100644
--- a/spec/components/middleware/anonymous_cache_spec.rb
+++ b/spec/components/middleware/anonymous_cache_spec.rb
@@ -186,7 +186,7 @@ describe Middleware::AnonymousCache do
app = Middleware::AnonymousCache.new(
lambda do |env|
- is_anon = env["HTTP_COOKIE"].nil?
+ is_anon = env["HTTP_COOKIE"].nil? && env["HTTP_DISCOURSE_LOGGED_IN"].nil?
[200, {}, ["ok"]]
end
)
@@ -196,6 +196,7 @@ describe Middleware::AnonymousCache do
env = {
"HTTP_COOKIE" => "_t=#{SecureRandom.hex}",
+ "HTTP_DISCOURSE_LOGGED_IN" => "true",
"HOST" => "site.com",
"REQUEST_METHOD" => "GET",
"REQUEST_URI" => "/somewhere/rainbow",