-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix modifying exceptions on macOS (#61)
The macOS sandbox is whitelist-based, denying everything and then step by step removing restrictions with every exception added. As a result, it wasn't possible to impose additional restrictions after a resource was made available. To allow restricting a specific resource even if a parent resource was already granted full access, we now deny all path access for every resource individually before granting new exceptions. As a result each new access always starts out with a clean fully denied slate.
- Loading branch information
Showing
5 changed files
with
177 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use std::fs; | ||
|
||
use birdcage::{Birdcage, Exception, Sandbox}; | ||
|
||
fn main() { | ||
const FILE_CONTENT: &str = "expected content"; | ||
|
||
// Setup our test tree. | ||
let tempdir = tempfile::tempdir().unwrap().into_path(); | ||
let tempfile = tempdir.join("target-file"); | ||
fs::write(&tempfile, FILE_CONTENT.as_bytes()).unwrap(); | ||
|
||
// Setup sandbox, allowing read/write to dir, but only read for the file. | ||
let mut birdcage = Birdcage::new(); | ||
birdcage.add_exception(Exception::WriteAndRead(tempdir.clone())).unwrap(); | ||
birdcage.add_exception(Exception::Read(tempfile.clone())).unwrap(); | ||
birdcage.lock().unwrap(); | ||
|
||
// Write access to directory works. | ||
fs::create_dir(tempdir.join("boop")).unwrap(); | ||
|
||
// Read access to file works. | ||
let content = fs::read_to_string(&tempfile).unwrap(); | ||
assert_eq!(content, FILE_CONTENT); | ||
|
||
// Write access to file is denied. | ||
let result = fs::write(&tempfile, "no"); | ||
assert!(result.is_err()); | ||
} |