From 1747bbbbcb0090523107836c6d879b4f37316926 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 19 Oct 2022 20:43:53 +0530 Subject: [PATCH] ssh kitten: Allow using absolute paths for the location of transferred data Fixes #5607 --- docs/changelog.rst | 2 ++ kittens/ssh/options/definition.py | 5 ++--- kittens/ssh/options/utils.py | 11 ----------- shell-integration/ssh/bootstrap.py | 5 ++++- shell-integration/ssh/bootstrap.sh | 5 ++++- 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 4998681ae..32eb1e828 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -38,6 +38,8 @@ Detailed list of changes 0.26.5 [future] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +- ssh kitten: Allow using absolute paths for the location of transferred data (:iss:`5607`) + - Fix a regression in the previous release that caused a :opt:`resize_draw_strategy` of ``static`` to not work (:iss:`5601`) - Wayland KDE: Fix abort when pasting into Firefox (:iss:`5603`) diff --git a/kittens/ssh/options/definition.py b/kittens/ssh/options/definition.py index 616924088..9310a5949 100644 --- a/kittens/ssh/options/definition.py +++ b/kittens/ssh/options/definition.py @@ -40,10 +40,9 @@ shell or a :program:`python` executable. If the default :program:`sh` is not available or broken, using an alternate interpreter can be useful. ''') -opt('remote_dir', '.local/share/kitty-ssh-kitten', option_type='relative_dir', long_text=''' +opt('remote_dir', '.local/share/kitty-ssh-kitten', long_text=''' The location on the remote host where the files needed for this kitten are -installed. The location is relative to the HOME directory. Absolute paths or -paths that resolve to a location outside the HOME are not allowed. +installed. Relative paths are resolved with respect to :code:`$HOME`. ''') opt('+copy', '', option_type='copy', add_to_default=False, long_text=f''' diff --git a/kittens/ssh/options/utils.py b/kittens/ssh/options/utils.py index cc90f4ef7..135bb2704 100644 --- a/kittens/ssh/options/utils.py +++ b/kittens/ssh/options/utils.py @@ -1,7 +1,6 @@ #!/usr/bin/env python # License: GPLv3 Copyright: 2022, Kovid Goyal -import posixpath from typing import Any, Dict, Iterable, Optional, Tuple from ..copy import CopyInstruction, parse_copy_instructions @@ -9,16 +8,6 @@ from ..copy import CopyInstruction, parse_copy_instructions DELETE_ENV_VAR = '_delete_this_env_var_' -def relative_dir(val: str) -> str: - if posixpath.isabs(val): - raise ValueError(f'Absolute paths not allowed. {val} is invalid.') - base = '/ffjdg' - q = posixpath.normpath(posixpath.join(base, val)) - if q == base or not q.startswith(base): - raise ValueError(f'Paths that escape their parent dir are not allowed. {val} is not valid') - return posixpath.normpath(val) - - def env(val: str, current_val: Dict[str, str]) -> Iterable[Tuple[str, str]]: val = val.strip() if val: diff --git a/shell-integration/ssh/bootstrap.py b/shell-integration/ssh/bootstrap.py index af68984c1..ac9c22b69 100644 --- a/shell-integration/ssh/bootstrap.py +++ b/shell-integration/ssh/bootstrap.py @@ -205,7 +205,10 @@ def get_data(): with open(tdir + '/data.sh') as f: env_vars = f.read() apply_env_vars(env_vars) - data_dir = os.path.join(HOME, os.environ.pop('KITTY_SSH_KITTEN_DATA_DIR')) + data_dir = os.environ.pop('KITTY_SSH_KITTEN_DATA_DIR') + if not os.path.isabs(data_dir): + data_dir = os.path.join(HOME, data_dir) + data_dir = os.path.abspath(data_dir) shell_integration_dir = os.path.join(data_dir, 'shell-integration') compile_terminfo(tdir + '/home') move(tdir + '/home', HOME) diff --git a/shell-integration/ssh/bootstrap.sh b/shell-integration/ssh/bootstrap.sh index abd72d66d..0ddf02513 100644 --- a/shell-integration/ssh/bootstrap.sh +++ b/shell-integration/ssh/bootstrap.sh @@ -103,7 +103,10 @@ untar_and_read_env() { . "$tdir/bootstrap-utils.sh" . "$tdir/data.sh" [ -z "$KITTY_SSH_KITTEN_DATA_DIR" ] && die "Failed to read SSH data from tty" - data_dir="$HOME/$KITTY_SSH_KITTEN_DATA_DIR" + case "$KITTY_SSH_KITTEN_DATA_DIR" in + /*) data_dir="$KITTY_SSH_KITTEN_DATA_DIR" ;; + *) data_dir="$HOME/$KITTY_SSH_KITTEN_DATA_DIR" + esac shell_integration_dir="$data_dir/shell-integration" unset KITTY_SSH_KITTEN_DATA_DIR login_shell="$KITTY_LOGIN_SHELL"