I am looking for a secure place to put Unix domain sockets that will be used to control a REPL.
On Linux, I would use
/run/user/$UID, which meets all requirements except for portability. I need the program that handles them to be portable.
One option is to use a directory under
~ but that runs into a different problem: the user's home directory might be in a directory too deep to be able to bind a Unix domain socket to, due to the limit in the path length.
Placing the socket in a directory under
/tmp is portable, but I am worried about race conditions upon removing the directory. I am also worried about whether
/tmp can be relied on to have the sticky bit set on all platforms (that is, for users to not be able to delete or rename other user's temporary files). I am assuming that
/tmp IS sticky, however, as otherwise many, many applications (every script that uses
mkstemp) is insecure.
My current plan is for the server to create a temporary directory in
/tmp, and for the clients to check the ownership of the containing directory before using the socket. Is this adequate for security?