From 45cd5201e964fdb93eac04d647e828e66fa32af1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 10 Nov 2026 08:15:26 +0530 Subject: [PATCH] ssh kitten: Fix remote directories being created world writable The bootstrap script extracted the tarball with umask 000, so tar created any directories not present in the tarball, such as ~/.terminfo and the ssh kitten data directory, with mode 0777. Since tar is run with -p, the permissions of entries in the tarball are already restored exactly, so the umask override is unnecessary. Remove it so that directories not in the tarball respect the user's umask, matching the behavior of bootstrap.py. Fixes #10834 Closes #10835 --- docs/changelog.rst | 3 +++ kitty_tests/ssh.py | 4 ++++ shell-integration/ssh/bootstrap.sh | 5 ++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 623144769..95cc3b928 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -169,6 +169,9 @@ Detailed list of changes selection destroys its window before kitty can reply. X errors no longer cause kitty to exit, they are reported instead (:iss:`9248`) +- ssh kitten: Fix directories such as :file:`~/.terminfo` being created world + writable on the remote host on first connect (:iss:`10834`) + 0.50.0 [2026-11-03] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty_tests/ssh.py b/kitty_tests/ssh.py index 8c6880a99..4cbd095f3 100644 --- a/kitty_tests/ssh.py +++ b/kitty_tests/ssh.py @@ -303,6 +303,10 @@ copy --exclude **/w.* --exclude **/r d1 self.ae(os.readlink(os.path.join(dest, 'link')), 'private/nested') self.ae(os.readlink(os.path.join(dest, 'broken')), 'missing') self.ae(glob.glob(os.path.join(remote_home, '.kitty-ssh-kitten-untar-*')), []) + # directories not present in the tarball must be created respecting the umask + # https://github.com/kovidgoyal/kitty/issues/10834 + for name in ('.terminfo', '.terminfo/x'): + self.ae(stat.S_IMODE(os.lstat(os.path.join(remote_home, name)).st_mode), 0o777 & ~int(umask, 8), (sh, umask, name)) @retry_on_failure() def test_ssh_env_vars(self): diff --git a/shell-integration/ssh/bootstrap.sh b/shell-integration/ssh/bootstrap.sh index 25418b29c..7e170f891 100644 --- a/shell-integration/ssh/bootstrap.sh +++ b/shell-integration/ssh/bootstrap.sh @@ -114,10 +114,9 @@ untar_and_read_env() { tdir=$(command mktemp -d "$HOME/.kitty-ssh-kitten-untar-XXXXXXXXXXXX") [ $? = 0 ] || die "Creating temp directory failed" # suppress STDERR for tar as tar prints various warnings if for instance, timestamps are in the future - old_umask=$(umask) - umask 000 + # -p makes tar restore the exact permissions of the entries in the tarball, + # directories not in the tarball are created respecting the user's umask read_base64_from_tty | base64_decode | command tar "xpzf" "-" "-C" "$tdir" 2> /dev/null - umask "$old_umask" . "$tdir/bootstrap-utils.sh" . "$tdir/data.sh" [ -z "$KITTY_SSH_KITTEN_DATA_DIR" ] && die "Failed to read SSH data from tty"