Install
Works with Drupal: ^10.3 || ^11 || ^12Using Composer to manage Drupal site dependencies
Alternative installation files
Release notes
Flag action routes now require view access to the flagged entity
What was wrong
The route access checks for Flag's action routes (_flag_access / _unflag_access) only called FlagInterface::actionAccess(). That method checks Flag's own permissions — flag <id> / unflag <id>, the "own / other users' items" configuration and hook_flag_action_access() — but never checked whether the user may view the entity being flagged.
As a result, any user with permission to use a flag could flag or unflag any entity of the flag's entity type by guessing or enumerating IDs: unpublished nodes, other users' private content, and content hidden by node access grants or modules such as Group. Differing responses for existing and missing IDs additionally allowed entity ID enumeration.
What changed
FlagAccessCheck and UnFlagAccessCheck now combine the flag's own action access with the flaggable entity's view access: a user may only flag or unflag an entity they are allowed to view. The check applies to all action routes at once — action links (AJAX/POST and no-JS/GET), the confirm forms and the field entry forms. Requests for non-existent entities still return 404, exactly as before.
Flag's programmatic API (FlagService::flag() / FlagService::unflag()) is unchanged; only route access is affected.
Impact on existing sites
For the vast majority of sites nothing changes: flag links are only rendered where the entity is already viewable, and standard entity types (nodes, users, taxonomy terms, comments, media) return a definitive view access result.
Be aware of the following behavior changes:
- Entity types with "neutral" view access: if you flag a custom entity type that has no access control handler, no admin permission and no
hook_entity_access()implementations, itsviewaccess is neutral by default — and neutral combined with an allowed flag permission is no longer sufficient. Such entity types can no longer be flagged through the routes. If this affects you, implement an access handler or ahook_ENTITY_TYPE_access()that returns "allowed" for users who should see the entity. (Allowing neutral results would have kept the vulnerability open for those entity types, so the strict behavior is intentional.) - Flags on user accounts now additionally require the
access user profilespermission. - Unflagging content that became unviewable: users can no longer unflag an entity they are no longer allowed to view (for example, a bookmarked node that was later unpublished). Such flaggings remain in place until the entity becomes viewable again or an administrator resets the flag.
hook_flag_action_access()implementations can no longer grant flag access to entities the user cannot view — the view access check always applies.
Contributors (5)
Anybody, anybody, csakiistvan, grevil, ivnish
Changelog
Issues: 3 issues resolved.
Changes since 5.2.1 (compare):