Skip to content

sftp: confine REALPATH, refuse unsafe roots - #1387

Open
ejohnstown wants to merge 2 commits into
wolfSSL:masterfrom
ejohnstown:sftp-confinement
Open

ejohnstown wants to merge 2 commits into
wolfSSL:masterfrom
ejohnstown:sftp-confinement

Conversation

@ejohnstown

@ejohnstown ejohnstown commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

REALPATH answers PERMISSION_DENIED outside the confinement root, and the
root compare runs in fixed time. Builds that cannot refuse a link below
the root now refuse confinement itself.

  • REALPATH goes through SFTP_CheckConfined(); Windows folds ASCII case;
    a start path outside the root resolves as the root
  • SetConfinePath returns WS_NOT_COMPILED without O_NOFOLLOW, with a
    user filesystem or the symlink check off, but still stores the root;
    OPEN and OPENDIR walk from the root with O_NOFOLLOW

Issue: F-8860, F-10599, F-11669, F-15661

@ejohnstown

Copy link
Copy Markdown
Contributor Author

@claude review

Comment thread src/wolfsftp.c Resolved
Comment thread src/wolfsftp.c Resolved

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-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.

Fenrir Automated Review — PR #1387

Scan targets checked: wolfssh-src, wolfssh-bugs
Coverage: 5 of 6 in-scope changed file(s) opened by the reviewer; not opened: wolfssh/internal.h

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Max

REALPATH now runs its answer through the same confinement check as the
other path requests and answers PERMISSION_DENIED for a name outside
the root. The check, split out of GetAndCleanPath as SFTP_CheckConfined,
compares every byte of the root before testing the boundary.

- a start path outside the root, or through a link below it, resolves
  as the root, so a confined session still opens
- prefix compare uses wolfSSH_ConstantCompare; Windows folds ASCII
  case in a fixed loop
- api.c: REALPATH of an escaping path and through an in-jail link

Issue: F-10599, F-11669
wolfSSH_SFTP_SetConfinePath returns WS_NOT_COMPILED for any root but
"/" where a link below the root cannot be refused:
WOLFSSH_NO_SYMLINK_CHECK, WOLFSSH_USER_FILESYSTEM, or POSIX without
O_NOFOLLOW. The root is still stored, so a caller that ignores the
error keeps the lexical jail.

- port.h defines WOLFSSH_NO_SFTP_CONFINE for those builds
- OPEN and OPENDIR walk down from the root with O_NOFOLLOW where
  openat() and O_PATH or O_SEARCH exist; _GNU_SOURCE on Linux for O_PATH
- wolfsftp.h states what still acts by name after the check
- tests expect the refusal under WOLFSSH_NO_SFTP_CONFINE, swap in a
  link between check and open, and start a session outside the root

Issue: F-8860, F-15661
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.

3 participants