This module has an Information Disclosure vulnerability, but it was decided that this falls under https://www.drupal.org/psa-2023-07-12 and can be solved in public.
The flag_relationship Views relationship plugin (FlagViewsRelationship) supports per-user ("current user") scopes. For anonymous users it filters flaggings by the Flag session ID through the ***FLAG_CURRENT_USER_SID*** query substitution. But the plugin declares only the user cache context, and user resolves to the same value (uid 0) for every anonymous visitor.
As a result, the rendered output of a view such as "My bookmarks" is cached once for all anonymous users. Every other anonymous visitor then sees the flagged content of whoever first filled the cache.
The page-cache kill switch in query() does not prevent this. It only disables the Internal Page Cache, not the Views render/output cache or the Dynamic Page Cache. On a render-cache hit, query() doesn't run at all.
Affected code
src/Plugin/views/relationship/FlagViewsRelationship.php:
<span class="hljs-comment">// query(): anonymous users are separated by session ID ...</span> <span class="hljs-keyword">if</span> (<span class="hljs-keyword">isset</span>($flag_roles[RoleInterface::ANONYMOUS_ID]) && <span class="hljs-keyword">$this</span>->currentUser->isAnonymous() && <span class="hljs-keyword">$this</span>->options[<span class="hljs-string">'user_scope'</span>] !== <span class="hljs-string">'context'</span>) { <span class="hljs-keyword">$this</span>->pageCacheKillSwitch->trigger(); <span class="hljs-comment">// only affects page_cache</span> <span class="hljs-keyword">$this</span>->definition[<span class="hljs-string">'extra'</span>][] = [ <span class="hljs-string">'field'</span> => <span class="hljs-string">'session_id'</span>, <span class="hljs-string">'value'</span> => <span class="hljs-string">'***FLAG_CURRENT_USER_SID***'</span>, ]; } <span class="hljs-comment">// ... but the cacheability metadata does not vary by session:</span> <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getCacheContexts</span><span class="hljs-params">()</span>: <span class="hljs-title">array</span> </span>{ ... <span class="hljs-keyword">return</span> in_array(<span class="hljs-keyword">$this</span>->options[<span class="hljs-string">'user_scope'</span>], [<span class="hljs-string">'context'</span>, <span class="hljs-string">'current'</span>]) && !$flag->isGlobal() ? [<span class="hljs-string">'user'</span>] : []; }
Preconditions
- A non-global flag, and the anonymous role has
flag <flag_id>permission. - A view with a
flag_relationshipusinguser_scope: current. This is the standard "My bookmarks" setup. - The view uses Views caching other than "None", i.e. Tag-based (the default for new views) or Time-based. The
flag_bookmarksubmodule's shipped view usescache: noneand is not affected, but copies or custom views with default settings are. - Render caching is active, as on any production site.
Steps to reproduce
- Enable Flag and create a non-global node flag
test_bookmarkwith the "Reload" link type. - Grant the anonymous role
flag test_bookmarkandunflag test_bookmark. - Create two published nodes, A and B.
- Create a view of content with:
- Relationship "Flags" (
flag_relationship), flagtest_bookmark, "By: Current user", required. - Field: Title.
- Caching: Tag based (default).
- A page display at
/test-bookmarksand/or a block display placed on node pages. - Access: permission
flag test_bookmark.
- Relationship "Flags" (
-
Visitor 1 (anonymous, own cookie jar) flags node A, which starts a session, and opens the view:
<span class="hljs-symbol">curl</span> -c <span class="hljs-built_in">v1</span> -<span class="hljs-keyword">b </span><span class="hljs-built_in">v1</span> http://example.com/flag/flag/test_bookmark/<A>/full <span class="hljs-symbol">curl</span> -c <span class="hljs-built_in">v1</span> -<span class="hljs-keyword">b </span><span class="hljs-built_in">v1</span> http://example.com/test-<span class="hljs-keyword">bookmarks </span> # shows <span class="hljs-string">"A"</span> -
Visitor 2 (anonymous, separate cookie jar) flags node B and opens the view:
<span class="hljs-symbol">curl</span> -c <span class="hljs-built_in">v2</span> -<span class="hljs-keyword">b </span><span class="hljs-built_in">v2</span> http://example.com/flag/flag/test_bookmark/<<span class="hljs-keyword">B>/full </span><span class="hljs-symbol">curl</span> -c <span class="hljs-built_in">v2</span> -<span class="hljs-keyword">b </span><span class="hljs-built_in">v2</span> http://example.com/test-<span class="hljs-keyword">bookmarks</span> - Expected: Visitor 2 sees only "B". Actual: Visitor 2 sees "A", Visitor 1's bookmark.
Observed result on the test site, with three independent anonymous sessions (the database confirmed each flagging belonged to a different session_id):
| Visitor | Flagged | Page display shows | Block display shows |
|---|---|---|---|
| 1 | A | A | A |
| 2 | B | A | A |
| 3 | B | A | A |
The page display responded with X-Drupal-Dynamic-Cache: UNCACHEABLE and still leaked, so the leak comes from the Views output cache itself. Requests for the block display were served with X-Drupal-Dynamic-Cache: HIT.
The leak does not reproduce with $settings['cache']['bins']['render'] = 'cache.backend.null', which is a typical local development setting. That may be why it has gone unnoticed.
AI Disclaimer:
I used AI (Claude Opus 5.5) to document and verify the issue.
| Comment | File | Size | Author |
|---|
Issue fork flag-3638524
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
anybodyComment #4
anybodyHere we go, see MR.
Comment #5
anybodyComment #6
anybody