-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mktemp templates & security #3
Comments
Hey, good question, thanks for asking, I created this quickly because I needed something easy to create, and then clean up temporary files and directories, and wanted to use Rust's lifetimes to manage the lifetime of the fs entity. This isn't quite like libc's The file is opened upon creation by the library, and upon opening, is truncated if it already exists (std::fs::File::create). Directories are also created. This definitely isn't perfect, and still suffers from a couple of potential things, plus there are a couple things I need to check with regard to the Of course, you/we can still use Templating is a nice idea - will also add it to the agenda. |
Whether you allow file-names to be specified via a template is really up to you. As the CWE I linked points out, there is good reason for creating exclusively (failing if the file already exists). If the process is unprivileged this is less important, but best to get it right once than expect all users to check whether this is something that might concern them, in my opinion. So I recommend:
I don't personally see an issue linking to libc functions since libc is linked anyway and very well tested, but if you prefer not to it's not a big deal. |
I'd also recommend to set the proper permissions, the files are currently readable by anyone. Something like this should do the trick: |
Bear in mind: Also exec should not be set on something other than very deliberately—a mode of 600 is preferable to 700. |
Hiya, this isn't an 'issue' but I wanted to ask about the design / what use cases you aim to cover.
First, some "mktemp" functions allow a template filename to be passed, e.g. C's
mkstemp
and the shell command. Allowing this would be nice.Second, there are several security issues to consider.
It may turn out better just to wrap C's
mkstemp
ormkstemps
?The text was updated successfully, but these errors were encountered: