Package names from repositories are not validated (.., ., ../x, C:\x resolve outside Packages)
Repository package names aren't validated; names like .., ., ../evil, a/b or C:\Temp\x are accepted and resolve to paths outside Packages/.
JsonRepositoryProvider (4.2.8) yields any string name, and package_io.get_package_dir() / get_installed_package_path() / get_package_cache_dir() just join it onto the data paths. Verified live in Sublime Text 4 on Windows (Data path C:\Users\<me>\AppData\Roaming\Sublime Text):
name in repository |
get_package_dir(name) |
get_installed_package_path(name) |
|---|---|---|
.. |
...\Sublime Text (the whole data directory) |
...\Installed Packages\...sublime-package |
. |
...\Sublime Text\Packages (the Packages folder itself) |
...\Installed Packages\..sublime-package |
../evil or ..\evil |
...\Sublime Text\evil |
...\Sublime Text\evil.sublime-package |
a/b |
...\Packages\a\b |
...\Installed Packages\a\b.sublime-package |
C:\Temp\x |
C:\Temp\x |
C:\Temp\x.sublime-package |
/abs |
C:\abs |
C:\abs.sublime-package |
The provider accepted all of these (plus User, Default, Package Control, CON, nul, names with a NUL character, trailing dot/space, */?/<). Only the literal name user is special-cased, in delete_package. So remove_package('..') or ('.') for a package that got installed under such a name resolves to delete_directory()/move_package_dir_to_backup() on the Sublime data directory or the Packages folder, and install/upgrade would extract into evil/, C:\Temp\x, etc.
To keep the threat model honest: someone has to add or trust that repository, and an installed package already runs arbitrary code, so this is defence in depth against a hostile or simply mistyped repository/channel entry ("name": "." is a plausible typo), not a new privilege. I did not attempt an install/remove with such names; I only exercised path resolution.
Suggested fix: reject in the provider (InvalidPackageKeyError) and again in package_io any name that is empty, is ./.., contains /, \, : , NUL or other control characters, ends in space/dot, or is a Windows reserved device name; compare case-insensitively against User/Default/Package Control; and assert the resolved path stays inside Packages/Installed Packages.
The same names are also accepted through ChannelProvider (schema 4.0.0 packages_cache / libraries_cache, which does no validation of entries): .., ., ../evil, a/b, C:\x, User, "" for packages, and ../x for a library, so validating in only one provider wouldn't be enough; the check would belong where names enter the manager (or in package_io path helpers) as well.