-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Add doc on Unix temporary file security practice #70585
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
Changes from 1 commit
ef07497
ef25c1a
d8555f2
5ff7105
045841b
b2a9a8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,10 +8,10 @@ Most notably, the Windows model for temporary files is that the operating system | |
| Moreover, all Windows users, including the service and system users, have designated user folders, including temporary folders. | ||
|
|
||
| The Unix model is very different. The temp directory, assuming there is one, is often a global folder (except on MacOS). | ||
| If possible, prefer a library function like `GetTempPath()` to find the folder. Othewrise, | ||
| If possible, prefer a library function like `GetTempPath()` to find the folder. Otherwise, | ||
| the `TMPDIR` environment variable is used to store the location of this folder. This variable is | ||
| widely used and supported, but it is not mandatory for all Unix implementations. It should be the preferred | ||
| mechanism for finding the Unix temporary folder, if a library method is not available. It will commonly | ||
| mechanism for finding the Unix temporary folder if a library method is not available. It will commonly | ||
| point to either the `/tmp` or `/var/tmp` folder. These folders are not used for MacOS, so it is not recommended | ||
| to use them directly. | ||
|
|
||
|
|
@@ -24,8 +24,8 @@ considered. In general, the best use of the temp directory is for programs which | |
|
|
||
| In these cases, the process can create a file or files with | ||
| 1. A pseudorandom name, unlikely to cause collisions | ||
| 1. Permissions which restrict all access to owner-only | ||
| 1. Permissions which restrict all access to owner-only, i.e. 700 | ||
|
|
||
| Any other use needs to be carefully audited, particularly if the temporary file is intended for use across | ||
| multiple processes. Some considerations: | ||
|
|
||
|
|
@@ -36,10 +36,10 @@ multiple processes. Some considerations: | |
| creating a denial of service. | ||
| - When creating files, consider likelihood of file name collision and performance impact of attempting | ||
| to create new names, if supported. | ||
|
|
||
| If any of the above conflict with the feature requirements, consider instead writing temporary files to a | ||
| location in the user home folder. Some considerations for this model: | ||
|
|
||
| - There is no automatic cleanup in user folders. Files will remain permanently or require cleanup by the app | ||
| - Some environments do not have user home folders (e.g., systemd). Consider providing an environment variable | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. systemd has a
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe also worth mentioning:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some interesting requirements there, including that files not survive reboot. It might be worth specifying here that we should not expect our temp files to survive reboot, but we should not expect them to be cleaned up by reboot either. |
||
| to override the location of the temporary folder, and provide user documentation for this variable. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be simplest to create a single folder and do everything else below that.
That folder could even become
Path.GetTempPath.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any value in using a cryptographically secure name here? Guid is not (or at least not enough). It can use GetRandomFileName()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would only make a difference if the attacker has permission to open files in the temp directory but not to enumerate them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a question of the app's threat model and can't be answered generally.