py-winrm-plugin icon indicating copy to clipboard operation
py-winrm-plugin copied to clipboard

File copier writes to the wrong folder when the filename also appears earlier in the destination path

Open skywalkw3r opened this issue 1 month ago • 0 comments

winrm-filecopier.py splits the destination into directory and filename like this:

filename = ntpath.basename(args.destination)
if filename is None:
    filename = os.path.basename(args.source)

if filename in args.destination:
    destination = destination.replace(filename, '')

str.replace removes every occurrence of the filename, not only the last path component, so the remote directory gets mangled whenever the filename string also appears in a parent directory.

Repro

  1. Job with a "Copy File" step targeting a node using the WinRM file copier.
  2. Set the destination to C:\Users\admin\Desktop\a.
  3. Run the job.

Actual: the plugin creates C:\Users\dmin\Desktop\ and writes the file there as a.

Expected: the file is written to C:\Users\admin\Desktop\a.

Other cases:

Destination Remote directory used Expected
C:\Users\admin\Desktop\a C:\Users\dmin\Desktop\ C:\Users\admin\Desktop\
C:\deploy\app\app C:\deploy\\ C:\deploy\app\
C:\Users\admin\Desktop\ (directory) filename is empty, upload targets the directory path itself and fails file is written into that directory using the source file's name

Also, ntpath.basename returns '' rather than None, and its result is always a substring of the destination, so the None check and the else branch (check_is_file / get_file) never run.

Normal Rundeck script dispatch paths (e.g. C:\Windows\TEMP\123-dispatch.ps1) are not affected, since the filename doesn't appear elsewhere in the path.

skywalkw3r avatar Oct 18 '26 20:10 skywalkw3r