Skip to content

Harden RemoteFileSystem path resolution containment and rebuild absolute URLs#22476

Merged
desertaxle merged 3 commits into
mainfrom
devin/remote-filesystem-resolve-path
Jul 12, 2026
Merged

Harden RemoteFileSystem path resolution containment and rebuild absolute URLs#22476
desertaxle merged 3 commits into
mainfrom
devin/remote-filesystem-resolve-path

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Hardens RemoteFileSystem._resolve_path so it no longer returns raw user input that downstream fsspec backends may interpret differently.

Changes

  • Absolute URLs with a netloc are rebuilt from the configured scheme/netloc and a normalized path.
  • Dot-segment traversal is rejected, including literal .. and encoded variants (%2e%2e, .%2e, %2e.).
  • SMB-style backslash separators are treated as path separators.
  • Control characters stripped by urlsplit (e.g. \r, \n, \t) are not passed through.
  • Percent-encoded object keys are not decoded in the returned URL.

Tests

  • Added regression tests covering traversal variants, control-character inputs, mixed-case scheme write/read round trips, and the existing nested/sibling cases.

Validation

  • uv run pytest tests/test_filesystems.py -q — 73 passed, 1 skipped
  • uv run ruff check src/prefect/filesystems.py tests/test_filesystems.py — passed
  • uv run ruff format --check src/prefect/filesystems.py tests/test_filesystems.py — formatted
  • git diff --check — clean
  • SKIP=check-ui-v2 uv run pre-commit run --all-files — passed
  • CI — 84 passed, 0 failed

Link to Devin session: https://app.devin.ai/sessions/feb3ed2e92b14cfda4a3ad17019bd4a8
Requested by: @desertaxle

@desertaxle desertaxle self-assigned this Jul 10, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@codspeed-hq

codspeed-hq Bot commented Jul 10, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 8 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing devin/remote-filesystem-resolve-path (b2264a5) with main (c7f899b)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

…ainment

Co-authored-by: Alex S. <alex.s@prefect.io>
Co-Authored-By: alex.s <ajstreed1@gmail.com>
@devin-ai-integration devin-ai-integration Bot force-pushed the devin/remote-filesystem-resolve-path branch from 3178d9d to 8f27321 Compare July 10, 2026 14:07
@desertaxle desertaxle marked this pull request as ready for review July 10, 2026 14:18

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8f27321c81

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/prefect/filesystems.py Outdated
…tests

- Reject absolute paths with dot-segment traversal (literal or encoded %2e variants)
- Treat backslashes as separators for SMB traversal detection
- Strip control characters that urlsplit removes
- Rebuild accepted absolute URLs from the configured scheme/netloc
- Preserve percent-encoded object keys in returned URLs

Co-authored-by: Alex S. <alex.s@prefect.io>
Co-Authored-By: alex.s <ajstreed1@gmail.com>
@devin-ai-integration devin-ai-integration Bot changed the title Fix RemoteFileSystem absolute path resolution and sibling prefix containment Harden RemoteFileSystem path resolution containment and rebuild absolute URLs Jul 10, 2026
Use the decoded path only for traversal detection. Require the raw

candidate URL path to be contained under the raw configured base path

before accepting it. This rejects prefix spoofs such as pre%66ix and

prefix%2Fchild while preserving safe percent encodings, literal //, /./,

and backslashes as object keys.

Co-authored-by: Alex S. <alex.s@prefect.io>
Co-Authored-By: alex.s <ajstreed1@gmail.com>
@desertaxle desertaxle merged commit 0e74350 into main Jul 12, 2026
91 checks passed
@desertaxle desertaxle deleted the devin/remote-filesystem-resolve-path branch July 12, 2026 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant