fix: respect exclusive SFTP create requests#322
Open
metabrixkt wants to merge 2 commits into
Open
Conversation
3 tasks
85d0b56 to
ac2f4e1
Compare
Author
|
Rebased following the release of v1.12.3 |
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.
Fixes pterodactyl/panel#4739
What was wrong?
SFTP request flags
SSH_FXF_CREAT | SSH_FXF_EXCLmean "create this file, but fail if it already exists", semantically identical to a POSIXopenwith flagsO_CREAT | O_EXCL.Wings was ignoring the exclusive-create part of the request. Even when a client opened a file with
SSH_FXF_CREAT | SSH_FXF_EXCL, Wings would callTouchwith truncation behavior, allowing an existing file to be opened and replaced.What's the impact?
Mechanically, this violates the expected SFTPv3 open semantics for exclusive create requests.
Practically:
The change
This change makes Wings respect exclusive create requests:
os.ErrExist, whichpkg/sftpmaps to anSSH_FXP_STATUSfailure response (SSH_FX_FAILUREerror code), which matches OpenSSH SFTP behavior for SFTPv3os.O_CREATE | os.O_EXCL, so the exclusive create is enforced atomically by the filesystemos.ErrExistbehaviorVerification
Locally verified that
SSH_FXF_CREAT | SSH_FXF_EXCLnow fails for an existing file instead of truncating it, matching OpenSSH SFTP behavior and the spec. Also verified that GVFS/GIO now shows the overwrite prompt instead of silently replacing the remote file.