Skip to content

Commit

Permalink
transfers: Don't allow a received file to be saved outside of the
Browse files Browse the repository at this point in the history
transfer folder.

Since relative paths are valid for GFiles, we need to make sure
they resolve as descendants of the incoming transfer folder.
  • Loading branch information
mtwebster committed Sep 20, 2022
1 parent c28609c commit 5244c33
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/transfers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import stat
import shutil
import gettext

from gi.repository import GLib, Gio, GObject

Expand All @@ -12,6 +13,8 @@
import prefs
import warp_pb2

_ = gettext.gettext

FILE_INFOS = ",".join([
"standard::size",
"standard::allocated-size",
Expand Down Expand Up @@ -164,6 +167,7 @@ class FileReceiver(GObject.Object):
def __init__(self, op):
super(FileReceiver, self).__init__()
self.save_path = prefs.get_save_path()
self.save_path_file = Gio.File.new_for_path(self.save_path)
self.op = op
self.preserve_perms = prefs.preserve_permissions() and util.save_folder_is_native_fs()
self.preserve_timestamp = prefs.preserve_timestamp() and util.save_folder_is_native_fs()
Expand Down Expand Up @@ -208,6 +212,9 @@ def receive_data(self, s):

if not self.current_gfile:
self.current_gfile = Gio.File.new_for_path(path)
# Check for valid path (GFile resolves paths upon creation).
if self.save_path_file.get_relative_path(self.current_gfile) is None:
raise Exception(_("Resolved path is not valid: %s -> %s") % (path, self.current_gfile.get_path()))

if s.file_type == FileType.DIRECTORY:
os.makedirs(path, exist_ok=True)
Expand Down

0 comments on commit 5244c33

Please sign in to comment.