-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Make sure that NSTemporaryDirectory() is included in the sandbox when writableTemporaryDirectory
is set
#3918
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 all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
See http://swift.org/CONTRIBUTORS.txt for Swift project authors | ||
*/ | ||
|
||
import Foundation | ||
import TSCBasic | ||
import TSCUtility | ||
|
||
|
@@ -73,8 +74,13 @@ fileprivate func macOSSandboxProfile( | |
} | ||
// Optionally allow writing to temporary directories (a lot of use of Foundation requires this). | ||
else if strictness == .writableTemporaryDirectory { | ||
writableDirectoriesExpression.append("(subpath \"/private/tmp\")") | ||
if let tmpDir = try? TSCBasic.determineTempDirectory() { | ||
// Add the standard and Foundation temporary directories, and the one determined by TSC (which also taked into account environment variables). | ||
var temporaryDirectories = Set([AbsolutePath("/tmp"), AbsolutePath(NSTemporaryDirectory())]) | ||
if let tscTmpDir = try? TSCBasic.determineTempDirectory() { | ||
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. It's not clear that we should still be doing this instead of just the standard paths. But it seems better to start more lenient and then tighten it over time. 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. Since the sandbox always applies to a subprocess, the most correct thing to do here is probably for the code in 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. Can the sandbox of a subprocess be more lenient than the one of the parent? 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. Nested sandboxing is actually completely unsupported right now (on Darwin). What I meant by lenient is to allow both the 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. Adjusted it here #3920 |
||
temporaryDirectories.insert(tscTmpDir) | ||
} | ||
// Add `subpath` expressions for all of them. | ||
for tmpDir in temporaryDirectories.sorted() { | ||
writableDirectoriesExpression += ["(subpath \(resolveSymlinks(tmpDir).quotedAsSubpathForSandboxProfile))"] | ||
} | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
Note that this will get resolved to
/private/tmp
since all the paths now go through theresolveSymlinks
below. So this is not a material change from before. But it is semantically more correct, since the fact that/tmp
is a symlink to/private/tmp
is an implementation detail.