Skip to content

SFTP path confinement and status-reply refactor#1000

Open
yosuke-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
yosuke-wolfssl:fix/f_4720
Open

SFTP path confinement and status-reply refactor#1000
yosuke-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
yosuke-wolfssl:fix/f_4720

Conversation

@yosuke-wolfssl
Copy link
Copy Markdown
Contributor

@yosuke-wolfssl yosuke-wolfssl commented Jun 3, 2026

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.

@yosuke-wolfssl yosuke-wolfssl self-assigned this Jun 3, 2026
Copilot AI review requested due to automatic review settings June 3, 2026 23:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@yosuke-wolfssl yosuke-wolfssl marked this pull request as draft June 4, 2026 00:57
@yosuke-wolfssl yosuke-wolfssl force-pushed the fix/f_4720 branch 3 times, most recently from 09d049a to 0659275 Compare June 5, 2026 00:41
@yosuke-wolfssl yosuke-wolfssl marked this pull request as ready for review June 5, 2026 00:41
Copy link
Copy Markdown

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Choose a reason for hiding this comment

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

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.

Comment thread src/wolfsftp.c Outdated
Comment thread tests/api.c Outdated
Comment thread src/wolfsftp.c
Comment thread src/wolfsftp.c Outdated
Comment thread tests/api.c Outdated
Comment thread src/wolfsftp.c
@yosuke-wolfssl yosuke-wolfssl changed the title Add a confinement check of the resolved path into GetAndCleanPath, and Add a SFTP_SendStatus helper SFTP path confinement and status-reply refactor Jun 5, 2026
Copy link
Copy Markdown

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Choose a reason for hiding this comment

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

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.

Comment thread tests/api.c
Comment thread src/wolfsftp.c Outdated
Comment thread src/wolfsftp.c
Comment thread tests/api.c
Comment thread src/wolfsftp.c Outdated
Comment thread src/wolfsftp.c
Copy link
Copy Markdown

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Choose a reason for hiding this comment

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

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.

Comment thread tests/api.c Outdated
Comment thread src/wolfsftp.c Outdated
Comment thread src/wolfsftp.c
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.

4 participants