Skip to content

Don't load the native library from a directory another user controls - #98

Merged
eed3si9n merged 1 commit into
sbt:2.xfrom
lrytz:pr/native-loader-private-dir
Oct 30, 2026
Merged

eed3si9n merged 1 commit into
sbt:2.xfrom
lrytz:pr/native-loader-private-dir

Conversation

@lrytz

@lrytz lrytz commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

The native library is extracted to a temporary directory and loaded from there. Without XDG_RUNTIME_DIR (common in cron jobs, containers and CI), that directory is in /tmp, with a name derived from the home directory: predictable, in a directory every user can write to, and used without checking who created it. Another user on the same machine could create it first and replace the library before it is loaded, and so run their code in the victim's process.

Now the directory is only used if it belongs to the current user and no one else can write to it, and new directories are created private. Otherwise the library is extracted to a new private temporary directory. macOS and Windows are not affected, because their temporary directories are per user. A directory set with the sbt.ipcsocket.tmpdir property is used as given; whoever sets it is responsible for making it private.

@lrytz
lrytz force-pushed the pr/native-loader-private-dir branch from 8ac5f54 to 37223d8 Compare October 28, 2026 10:57
@lrytz lrytz mentioned this pull request Oct 28, 2026
Comment on lines +79 to +82
if ((isPrivateDirectory(parent) || isSharedStickyDirectory(parent))
&& isPrivateDirectory(dir)) {
return dir;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the concern, but given that sbt is actively setting the sbt.ipcsocket.tmpdir property, adding a new check here may make the future debugging more confusing. Since we have control of the both repos, I suggest fixing this in sbt and runtimeDir() by moving the isPrivateDirectory checks there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks. I dropped the second commit and moved the check into runtimeDir(), so it only covers the default directory. A directory set with sbt.ipcsocket.tmpdir is used as given.

The native library is extracted to a temporary directory and loaded from
there. Without XDG_RUNTIME_DIR (common in cron jobs, containers and CI),
that directory is in /tmp, with a name derived from the home directory:
predictable, in a directory every user can write to, and used without
checking who created it. Another user on the same machine could create
it first and replace the library before it is loaded, and so run their
code in the victim's process.

Now the directory is only used if it belongs to the current user and no
one else can write to it, and new directories are created private.
Otherwise the library is extracted to a new private temporary directory.
macOS and Windows are not affected, because their temporary directories
are per user. A directory set with the sbt.ipcsocket.tmpdir property is
used as given; whoever sets it is responsible for making it private.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@eed3si9n eed3si9n left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@eed3si9n
eed3si9n merged commit 38fa2b9 into sbt:2.x Oct 30, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants