SFTP path confinement and status-reply refactor#1000
Open
yosuke-wolfssl wants to merge 1 commit into
Open
Conversation
09d049a to
0659275
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1000
Scan targets checked: wolfssh-bugs, wolfssh-src
Findings: 3
3 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Findings are non-blocking.
yosuke-wolfssl
commented
Jun 5, 2026
yosuke-wolfssl
commented
Jun 5, 2026
yosuke-wolfssl
commented
Jun 5, 2026
73125b2 to
1b36c5b
Compare
aa9c5c6 to
cd7d26b
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1000
Scan targets checked: wolfssh-bugs, wolfssh-src
Findings: 3
3 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Findings are non-blocking.
yosuke-wolfssl
commented
Jun 5, 2026
yosuke-wolfssl
commented
Jun 5, 2026
yosuke-wolfssl
commented
Jun 5, 2026
bf885ae to
9c69bcc
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1000
Scan targets checked: wolfssh-bugs, wolfssh-src
Findings: 3
3 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Findings are non-blocking.
9c69bcc to
16dbbc3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
The SFTP server resolved client request paths but did not verify the result stayed inside the configured default/home directory, so a client could reach absolute or ..-laden paths outside its intended jail.
This adds a confinement check that rejects any resolved path outside the canonical default path, and hardens the surrounding status-reply handling.
Changes
Confinement check in GetAndCleanPath — after wolfSSH_RealPath resolves a request, the canonical result is prefix-compared against the stored canonical default path (with a /-boundary check so /jaildir can't match /jaildirX). Out-of-jail requests return WS_PERMISSIONS. The "/" default (no confinement) and trailing-separator cases are handled explicitly. On Windows (USE_WINDOWS_API) the compare is case-insensitive to match the case-insensitive filesystem.
wolfSSH_SFTP_SetDefaultPath rewritten — stores the default path in canonical form (resolving relative paths against the cwd) so the per-request confinement compare is a cheap prefix match with no re-canonicalization. Also frees any previously-stored default path to avoid a leak on reassignment (reachable from wolfsshd's chroot setup).
New SFTP_SendStatus helper — consolidates the build-status-packet-and-queue boilerplate; 14 call sites across the Recv* handlers (RMDIR/MKDIR/Open/OpenDir/Write/Close/Remove/Rename/STAT/LSTAT/SetSTAT/FSetSTAT) refactored to use it, replacing repeated inline blocks.
New tests to exercise new code path
Updated the SFTP CI tests to read/write within the echoserver's working directory (its jail) rather than /tmp, since out-of-jail absolute paths are now correctly rejected.
Addressed by f_4720, f_4791, f_4796, f_4942, f_5111, f_5134, f_5725, f_5828.