mirror of
https://github.com/usestrix/firewall.git
synced 2026-11-11 05:01:25 -10:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8bb60c1214 |
No files matched your search
+7
-1
@@ -25,6 +25,10 @@ pub struct BlockedPackage {
|
||||
pub version: Option<String>,
|
||||
pub filter: &'static str,
|
||||
pub reason: String,
|
||||
/// Flagged as malware, not just held back for being new.
|
||||
pub malicious: bool,
|
||||
/// Malware is never allowed, and a new package only by version. Saves each app the rule.
|
||||
pub trustable: bool,
|
||||
}
|
||||
|
||||
struct Blocks {
|
||||
@@ -96,9 +100,11 @@ fn record(
|
||||
version: pkg.version.clone(),
|
||||
filter,
|
||||
reason: reason.to_owned(),
|
||||
malicious: filter != "age",
|
||||
trustable: filter == "age" && pkg.version.is_some(),
|
||||
};
|
||||
push(&mut blocks.unsent, block.clone());
|
||||
if filter != "age" {
|
||||
if block.malicious {
|
||||
return None;
|
||||
}
|
||||
let (wake, allowed) = watch::channel(false);
|
||||
|
||||
@@ -16,6 +16,8 @@ async fn allowing_once_releases_the_held_download() {
|
||||
let id = loop {
|
||||
let blocks: serde_json::Value = serde_json::from_str(&answer(&firewall, config, "blocks")).unwrap();
|
||||
if let Some(id) = blocks[0]["id"].as_u64() {
|
||||
assert_eq!(blocks[0]["malicious"], false);
|
||||
assert_eq!(blocks[0]["trustable"], true);
|
||||
break id;
|
||||
}
|
||||
tokio::time::sleep(Duration::from_millis(10)).await;
|
||||
|
||||
@@ -30,12 +30,12 @@ enum BlockAlert {
|
||||
if package.malicious {
|
||||
alert.alertStyle = .critical
|
||||
alert.messageText = "Blocked malware: \(package.label) (\(package.eco))"
|
||||
setText(alert, "\(package.label) \(package.reason).\n\n"
|
||||
alert.informativeText = "\(package.label) \(package.reason).\n\n"
|
||||
+ "It was not installed. Don't install it from another source. "
|
||||
+ "If you didn't expect this package, a dependency may be compromised; tell your security team.")
|
||||
+ "If you didn't expect this package, a dependency may be compromised; tell your security team."
|
||||
} else {
|
||||
alert.messageText = "Held back a new package"
|
||||
setText(alert, "\(package.label) (\(package.eco)) \(package.reason).")
|
||||
alert.informativeText = "\(package.label) (\(package.eco)) \(package.reason)."
|
||||
if package.trustable {
|
||||
alert.addButton(withTitle: "Allow Once")
|
||||
alert.addButton(withTitle: "Trust this version")
|
||||
@@ -56,22 +56,6 @@ enum BlockAlert {
|
||||
NSApp.activate(ignoringOtherApps: true)
|
||||
alert.runModal()
|
||||
}
|
||||
|
||||
/// An alert's own text is plain, so this text goes in a selectable field, where its links open on click.
|
||||
private static func setText(_ alert: NSAlert, _ text: String) {
|
||||
let linked = NSMutableAttributedString(string: text, attributes: [.font: NSFont.systemFont(ofSize: NSFont.smallSystemFontSize)])
|
||||
let detector = try! NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
|
||||
for match in detector.matches(in: text, range: NSRange(text.startIndex..., in: text)) {
|
||||
if let url = match.url { linked.addAttribute(.link, value: url, range: match.range) }
|
||||
}
|
||||
let field = NSTextField(wrappingLabelWithString: "")
|
||||
field.allowsEditingTextAttributes = true
|
||||
field.isSelectable = true
|
||||
field.attributedStringValue = linked
|
||||
field.preferredMaxLayoutWidth = 300
|
||||
field.frame.size = field.fittingSize
|
||||
alert.accessoryView = field
|
||||
}
|
||||
}
|
||||
|
||||
enum AdminAuthorization {
|
||||
|
||||
Reference in new issue
Block a user