Skip to content

create debugger tmp directory with 0o700 permissions - #1530

Merged
minrk merged 1 commit into
ipython:mainfrom
sahvx655-wq:debugger-tmp-dir-mode
Jun 18, 2026
Merged

minrk merged 1 commit into
ipython:mainfrom
sahvx655-wq:debugger-tmp-dir-mode

Conversation

@sahvx655-wq

Copy link
Copy Markdown
Contributor

While looking at where the debugger persists cell sources, I noticed Debugger.start creates the scratch directory with Path(tmp_dir).mkdir(parents=True) and no mode argument. get_tmp_directory() returns a predictable <tmpdir>/ipykernel_<pid>, so on a typical umask the directory lands at 0o755 and the cell files dumpCell writes into it come out 0o644. On a shared host any other local user can then read the source the user is debugging. Checking the mode locally confirmed 0o755 on the directory and 0o644 on the written .py files.

The connection directory in kernelapp.init_connection_file is already created with mode=0o700 for the same reason, so this brings the debugger scratch directory in line. Setting the mode at creation keeps the restriction next to the only place the directory is made, rather than relying on the ambient umask being tight.

@minrk
minrk merged commit 8816d02 into ipython:main Jun 18, 2026
42 of 43 checks passed
JohanMabille added a commit that referenced this pull request Oct 17, 2026
Debugger.start only creates its scratch directory when
Path(tmp_dir).exists() is false, and get_tmp_directory returns the
completely predictable <tempdir>/ipykernel_<pid>. Path.exists follows
symlinks, so on a host with a shared temp directory another local user
can reach that name first and point it at a directory they own; the
kernel then skips the mkdir, the 0o700 mode from #1530 never applies,
and dumpCell writes the cell source straight through the link. I went
back to start after that permissions change and noticed the mkdir is
reachable only when the path does not already exist, which is the one
case someone else gets to control. Planting the predictable name as a
symlink locally confirmed it: start carried on, dumpCell dropped the
cell text into the other directory, and a symlink planted under the
Murmur2 cell name turned the same write into an overwrite of a file
outside the temp tree. Creating the directory first and only accepting
an existing one when lstat says it is a real directory owned by this
user closes that, and opening the dumped cell with O_NOFOLLOW keeps the
file write itself from being redirected; the cell file now lands at
0o600 instead of whatever the umask gives, matching the directory around
it. Added two regressions beside the existing debugger tests, both
skipped when debugpy is absent and on Windows where symlinks need
privileges and O_NOFOLLOW does not exist.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants