Skip to content

refactor(filesystem): clean up isValidPath() logic and update docs - #57325

Open
joshtrichards wants to merge 2 commits into
masterfrom
jtr/refactor-Files-FIlesystem-isValidPath
Open

refactor(filesystem): clean up isValidPath() logic and update docs#57325
joshtrichards wants to merge 2 commits into
masterfrom
jtr/refactor-Files-FIlesystem-isValidPath

Conversation

@joshtrichards

Copy link
Copy Markdown
Member

Summary

  • Optimizations/code cleanup:
    • Removes redundant checks; normalization already guarantees path is absolute
    • Replaces strrchr with str_ends_with
    • Adds parameter and return type hints (were already enforced via static analysis; should be safe)
  • Docs:
    • Note it's primary role as a security boundary for path validation and what specifically it handles

No functional change in logic: the production code path is just simpler and optimized.

TODO

  • ...

Checklist

…y docs

Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
@joshtrichards
joshtrichards marked this pull request as ready for review January 4, 2026 01:56
@joshtrichards
joshtrichards requested a review from a team as a code owner January 4, 2026 01:56
@joshtrichards
joshtrichards requested review from Altahrim, leftybournes, salmart-dev and yemkareems and removed request for a team January 4, 2026 01:56
@joshtrichards joshtrichards added 3. to review Waiting for reviews feature: filesystem ♻️ refactor Refactor code (not a bug fix, not a feature just refactoring) technical debt 🧱 🤔🚀 labels Jan 4, 2026
Comment on lines +395 to +403
* This method is the primary defense against directory traversal and
* path manipulation attacks. It ALWAYS normalizes the input (see {@see normalizePath}),
* converting slash and unicode variants to a canonical absolute path.
*
* After normalization, any path containing '/..' segments (traversal attempts) is rejected.
* Normalized paths like '//foo//bar' are allowed and become '/foo/bar'.
*
* @param string $path Untrusted or user-supplied path to check.
* @return bool True if the path is safe, false otherwise.

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.

The doc string is longer than the implementation of the the function, it literally describes the implementation.
IMHO this is not a good thing because docs are not always kept up to date and will differ from implementation and then it just confuses at some point.
Better to just state the intent of the method and make the code itself self explaining.

@susnux susnux added the community pull requests from community label Jun 9, 2026
@susnux susnux added this to the Nextcloud 35 milestone Jun 9, 2026
@nextcloud-bot nextcloud-bot mentioned this pull request Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews community pull requests from community feature: filesystem ♻️ refactor Refactor code (not a bug fix, not a feature just refactoring) technical debt 🧱 🤔🚀

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants