Skip to content

findVersionByID (collection and global) never runs sanitizeWhereQuery on the merged access-control where, unlike every other read operation #17883

Closed

Description

@MILLERMARRU

Every other read operation sanitizes the merged where before handing it to the db layer: findByID.ts, findVersions.ts (line 110), countVersions.ts, find.ts, count.ts and findDistinct.ts all call sanitizeWhereQuery({ fields, payload, where }) on the combined access-control where so relationship-backed virtual fields referenced in an access function's returned where get rewritten to their real underlying path.

Both findVersionByID.ts (collections/operations/findVersionByID.ts) and its global counterpart (globals/operations/findVersionByID.ts) skip this step entirely, the merged where from combineQueries(where, accessResults) goes straight to payload.db.findVersions/findGlobalVersions.

Concretely: if a collection or global's access.readVersions returns a where constraint on a virtual field (e.g. a field defined as virtual: 'related.label'), every other read operation would resolve that to the real path first. findVersionByID doesn't, so the db layer gets an unresolvable virtual field path and the lookup silently returns nothing, the caller sees Forbidden/NotFound instead of the correct version.

I found PR #17804 which implements exactly this fix ("fix: sanitize where query on findVersionByID for inherited read access", explicitly noting "findByID, findVersions, and countVersions all sanitize the merged where in the same spot"), but it targets a feature branch (codex/pyld-3081-versions-access-control), not main, and I don't see any open or merged PR bringing it into main. Confirmed against the current main HEAD that both files still lack the sanitizeWhereQuery call.

Activity

  1. JarrodMFlesch commented on Aug 21, 2026

    @JarrodMFlesch
    Contributor

    The branch you mentioned is explicitly targeting the main branch? #17634

  2. wakqasahmed commented on Aug 23, 2026

    @wakqasahmed
    Contributor

    Confirmed: PR #17634 (open, targeting main, changes-requested) already includes this exact fix — sanitizeWhereQuery calls added to both collections/operations/findVersionByID.ts and globals/operations/findVersionByID.ts, as part of its broader read-access-inheritance work. #17804 (referenced above) was a branch off that same work targeting the now-superseded feature branch. Since #17634 already carries this change on main-targeted code, I won't open a duplicate PR here — this should close once #17634 merges (or a maintainer can cherry-pick just this piece out sooner if #17634 stalls).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions