Skip to content

Request attributes are not being propagated for SSH_FXP_OPEN operation #557

Closed

Description

@pavan-aeturi

Hi Team, I'm facing the below issue where I'm looking for ways to block interrupted uploads (similar issue). So I want to access request attributes such as file-size during a put command. Even though the client sends the attributes during a put command, sftp-go server library doesn't seem to propagate it to handler

The restriction might be intentional and have a good reason behind it, in which case may I know the details of the reasoning? The library specification document too, doesn't talk about having this restriction. Please correct me if I'm wrong. Thanks in the advance.

Screenshot 2023-09-08 at 2 03 28 PM

`// New Request initialized based on packet data
func requestFromPacket(ctx context.Context, pkt hasPath, baseDir string) *Request {
request := &Request{
Method: requestMethod(pkt),
Filepath: cleanPathWithBase(baseDir, pkt.getPath()),
}
request.ctx, request.cancelCtx = context.WithCancel(ctx)

switch p := pkt.(type) {
case *sshFxpOpenPacket:
	request.Flags = p.Pflags
case *sshFxpSetstatPacket:
	request.Flags = p.Flags
	request.Attrs = p.Attrs.([]byte)
case *sshFxpRenamePacket:
	request.Target = cleanPathWithBase(baseDir, p.Newpath)
case *sshFxpSymlinkPacket:
	// NOTE: given a POSIX compliant signature: symlink(target, linkpath string)
	// this makes Request.Target the linkpath, and Request.Filepath the target.
	request.Target = cleanPathWithBase(baseDir, p.Linkpath)
	request.Filepath = p.Targetpath
case *sshFxpExtendedPacketHardlink:
	request.Target = cleanPathWithBase(baseDir, p.Newpath)
}
return request

} `

Activity

  1. puellanivis commented on Sep 8, 2023

    @puellanivis
    Collaborator

    There are unfortunately known issues with the opening of files and handling of attributes. I’ve done a complete rewrite of the client before, but due to early design decisions some of these just aren’t possible to address.

    Though… in this case, :squint: it might be possible to bodge in request.Attrs if we make sure the sshFxpOpenPacket contains them at least.

  2. drakkan commented on Sep 8, 2023

    @drakkan
    Collaborator

    If a client sends size 0 because it does not support this optional attribute it will be difficult to distinguish it from clients that support the attribute if they upload a 0 byte file

  3. puellanivis commented on Sep 11, 2023

    @puellanivis
    Collaborator

    Wouldn’t a client that does not support the optional attribute just not even set SSH_FILEXFER_ATTR_SIZE and thus be distinct from those that do support the attribute?

  4. pavan-aeturi commented on Sep 11, 2023

    @pavan-aeturi
    Author

    yes @puellanivis, that makes sense, SSH_FILEXFER_ATTR_SIZE check should help figure out if it is actually set and something like the below should help resolve file-size on server side

    // r *sftp.Request
    if r.AttrFlags().Size && r.Attributes() != nil && r.Attributes().Size > 0 {
      h.logger.Info("File size of upload file_length: %d", r.Attributes().Size)
    }
    
  5. mafredri commented on Dec 12, 2023

    @mafredri
    Contributor

    I ended up implementing attrs for the old Server in #567, should be possible to use in the request server as well, I think. There are probably edge cases I haven't considered, though.

  6. added a commit that references this issue on Nov 5, 2026
    60a3491
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions