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]) &amp;&amp; <span class="hljs-keyword">$this</span>-&gt;currentUser-&gt;isAnonymous() &amp;&amp; <span class="hljs-keyword">$this</span>-&gt;options[<span class="hljs-string">'user_scope'</span>] !== <span class="hljs-string">'context'</span>) {
  <span class="hljs-keyword">$this</span>-&gt;pageCacheKillSwitch-&gt;trigger();   <span class="hljs-comment">// only affects page_cache</span>
  <span class="hljs-keyword">$this</span>-&gt;definition[<span class="hljs-string">'extra'</span>][] = [
    <span class="hljs-string">'field'</span> =&gt; <span class="hljs-string">'session_id'</span>,
    <span class="hljs-string">'value'</span> =&gt; <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>-&gt;options[<span class="hljs-string">'user_scope'</span>], [<span class="hljs-string">'context'</span>, <span class="hljs-string">'current'</span>]) &amp;&amp; !$flag-&gt;isGlobal()
    ? [<span class="hljs-string">'user'</span>]
    : [];
}

Preconditions

  • A non-global flag, and the anonymous role has flag &lt;flag_id&gt; permission.
  • A view with a flag_relationship using user_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_bookmark submodule's shipped view uses cache: none and is not affected, but copies or custom views with default settings are.
  • Render caching is active, as on any production site.

Steps to reproduce

  1. Enable Flag and create a non-global node flag test_bookmark with the "Reload" link type.
  2. Grant the anonymous role flag test_bookmark and unflag test_bookmark.
  3. Create two published nodes, A and B.
  4. Create a view of content with:
    • Relationship "Flags" (flag_relationship), flag test_bookmark, "By: Current user", required.
    • Field: Title.
    • Caching: Tag based (default).
    • A page display at /test-bookmarks and/or a block display placed on node pages.
    • Access: permission flag test_bookmark.
  5. 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/&lt;A&gt;/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>
    
  6. 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/&lt;<span class="hljs-keyword">B&gt;/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>
    
  7. 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[&#39;cache&#39;][&#39;bins&#39;][&#39;render&#39;] = &#39;cache.backend.null&#39;, 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.

CommentFileSizeAuthor
#2 3638524.patch11.96 KBanybody

Issue fork flag-3638524

Command icon 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

anybody created an issue. See original summary.

anybody’s picture

StatusFileSize
new11.96 KB

anybody’s picture

Status: Active » Needs review

Here we go, see MR.

anybody’s picture

Issue summary: View changes
anybody’s picture

Issue summary: View changes