Closed (fixed)
Project:
Twig Tweak
Version:
8.x-2.x-dev
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
27 Feb 2020 at 11:14 UTC
Updated:
13 Mar 2020 at 09:54 UTC
Jump to comment: Most recent
Comments
Comment #2
chi commentedThe issue can arise when implementing a custom access workflow based on something different from user permissions. For instance, the access control may be based on some field values in user profile and implemented via hook_node_access(). Anyway, I believe it's up for developers to ensure bubbling access cacheability metadata when implementing such workflow. Currently it can be done like follows.
Note that's not specific to Twig templates. Access cachebility metatdata needs to be respected in PHP code as well.
The following code has the same problem.
The correct approach would be like this.
I think Twig Tweak should merge those metadata itself to make the result more secure by default.
Comment #4
chi commentedComment #7
chi commentedThe fix was pushed in 3.x branch and backported to 2.x and 1.x branches.
In 2.x and 1.x branches Twig Tweak functions does not return cache metadata when access is not allowed. That was done to preserve backward compatibility. Returning not NULL value in this case would break conditions in Twig templates like this one.
That's not perfect but it fixes the security problems with access control. 3.x branch of the module uses more correct approach.
Comment #8
chi commented