Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

fix: prevent unlimited loop due to invalid filename in path #2155

Merged
merged 1 commit into from
Mar 21, 2025

Conversation

qnixsynapse
Copy link
Contributor

Describe Your Changes

  • This PR addresses an infinite loop issue in the SanitizePath function. The bug occurs when the user-supplied filename (e.g., ../hi) results in a resolved path that is outside of the base directory. When the resolved path reaches the root directory, the loop fails to exit because the root is its own parent, causing the loop to iterate indefinitely.

Fixes Issues

Self Checklist

  • Added relevant comments, esp in complex areas
  • Updated docs (for bug fixes / features)
  • Created issues for follow-up changes or refactoring needed

Copy link
Contributor

@gau-nernst gau-nernst left a comment

Choose a reason for hiding this comment

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

No more hang, though I still think it's better to sanitize the filename string itself (checks including, but not limited to, no /), instead of trying to parse it as path and make sure it falls under cortex directory.

Approve to unblock. You can add test if you have time. Thank you!

@qnixsynapse qnixsynapse merged commit 6bb4656 into dev Mar 21, 2025
8 checks passed
@qnixsynapse qnixsynapse deleted the fix_hang branch March 21, 2025 00:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: /v1/files/ invalid filename will hang the server
2 participants