Skip to content

Compare paths on segment boundaries in isSubPath() - #493

Merged
kingjia90 merged 1 commit into
pimcore:2026.2from
timwiechers:fix/subpath-segment-boundary
Aug 20, 2026
Merged

Compare paths on segment boundaries in isSubPath()#493
kingjia90 merged 1 commit into
pimcore:2026.2from
timwiechers:fix/subpath-segment-boundary

Conversation

@timwiechers

Copy link
Copy Markdown
Contributor

Fixes pimcore/platform-version#314

Problem

PathService::isSubPath() compares with a plain str_starts_with():

return $path !== $parentPath && str_starts_with($path, $parentPath);

There is no / boundary, so a sibling whose name merely starts with another path counts as its child — /Catalog_Archive is treated as a child of /Catalog.

QueryService::addQueryByMainPath() runs the allowed workspace paths through removeSubPaths(), which therefore drops /Catalog_Archive from $allowedMainPaths. The resulting terms filter on system_fields.fullPath covers a path and its descendants (path_hierarchy tokenizer, splitting on /), and /Catalog does not match /Catalog_Archive — it is a sibling, not a descendant.

Effect for the user: a folder with list granted on exactly its own path is missing from the element tree, while sibling folders without a prefix neighbour show up normally. Only the tree is affected, since it reads from the index; the SQL-level permission check reports the same folder as visible.

isSubPath() also backs containsSubPath(), getContainedSubPaths() and keepDeclinedPathsWithinAllowed(), which all want real hierarchy as well.

This is the index-side counterpart of pimcore/platform-version#214, where the same missing boundary was fixed for the SQL permission conditions in the core.

Fix

Compare against the parent path plus its separator:

return $path !== $parentPath
    && str_starts_with($path, rtrim($parentPath, '/') . '/');

Strictly narrowing — only the previous false positives disappear. The root path stays intact: rtrim('/', '/') . '/' is /, which every absolute path starts with.

Tests

Extended tests/Unit/Service/PathServiceTest.php:

  • testIsSubPath() — prefix siblings are not sub paths (/foobar and /foo_bar under /foo, /foo/barbaz under /foo/bar), and /foobar is still a sub path of /.
  • testRemoveSubPaths()['/foo', '/foo_bar'] is kept as-is instead of collapsing to ['/foo'].

All pre-existing assertions in that file stay unchanged and green.

isSubPath() used a plain str_starts_with(), so a sibling whose name merely
starts with another path counted as its child - "/Catalog_Archive" was treated
as a child of "/Catalog".

removeSubPaths() therefore dropped such a sibling from the allowed main paths
in the workspace query, and since the resulting terms filter on fullPath only
covers a path and its descendants, the folder never matched: it stayed
invisible in the element tree although the workspace granted list permission
on exactly that path.

The change is strictly narrowing, only the previous false positives disappear.
For the root path the rtrim leaves "/", which every absolute path starts with,
so "/" keeps matching everything below it.
@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@timwiechers
timwiechers marked this pull request as ready for review August 10, 2026 12:55
Copilot AI balanced review requested due to automatic review settings August 10, 2026 12:55
@pimcore-deployments
pimcore-deployments marked this pull request as draft August 10, 2026 12:55
@sonarqubecloud

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes hierarchy checks so similarly prefixed sibling paths remain distinct.

Changes:

  • Compares paths at / segment boundaries.
  • Adds regression tests for prefix siblings and root paths.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Service/PathService.php Corrects subpath detection.
tests/Unit/Service/PathServiceTest.php Adds regression coverage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@timwiechers
timwiechers marked this pull request as ready for review August 10, 2026 12:57
@pimcore-deployments
pimcore-deployments marked this pull request as draft August 10, 2026 12:58
@timwiechers

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@astapc
astapc marked this pull request as ready for review August 11, 2026 05:23
@kingjia90 kingjia90 added this to the 2026.2.6 milestone Aug 20, 2026
@kingjia90 kingjia90 self-assigned this Aug 20, 2026
@kingjia90
kingjia90 merged commit f33bc07 into pimcore:2026.2 Aug 20, 2026
34 of 37 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants