Skip to content

Commit 401eda6

Browse files
Ilan HarelIlan Harel
authored andcommitted
fix(diff-logs): ignore OCSF network Refuse (policy DNS) records
OpenShell logs a class 4001 / activity 5 "Refuse" record (status_detail policy_dns_ineligible) when policy DNS refuses a name. It has no port or actor, and the connection attempt that follows is logged separately as a denied Open. parse_json_line counted it as a second denial and produced a bogus "manual review: host:?" item. Skip it, matching the shorthand parser, which ignores NET:REFUSE. Closes #69 Signed-off-by: Ilan Harel <[email protected]>
1 parent 0f413a1 commit 401eda6

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ version section and adds the squash-merged PR titles since the previous tag. Ver
66
## [Unreleased]
77

88
- chore(deps): build against OpenShell v0.1.7 (`openshell-policy-schema`, `openshell-policy`); docs and generated policy headers now name v0.1.7
9+
- fix(diff-logs): ignore OCSF Network Activity Refuse records (policy DNS `policy_dns_ineligible`) that have no port, so OCSF JSON and shorthand logs report the same denials
910

1011
## [0.1.0-rc.3] - 2026-11-09
1112

‎src/diff_logs.rs‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,21 @@ fn strip_query(p: &str) -> String {
100100
/// Only network activity (class 4001; activity 4 is a failure) and HTTP activity (class 4002) are used. Returns `None`
101101
/// for other classes, records without a destination host or an action, and the binary is dropped unless it is an
102102
/// absolute path.
103+
///
104+
/// Network "Refuse" records (activity 5, e.g. `status_detail: policy_dns_ineligible` when policy DNS refuses a name the
105+
/// policy does not allow) are skipped as well: they carry no port or process, and the connection attempt that follows
106+
/// is logged separately as a denied Open with host, port and binary. The shorthand parser ignores `NET:REFUSE` too.
103107
fn parse_json_line(v: &serde_json::Value, source: &str, line: usize) -> Option<Event> {
104108
let class_uid = v.get("class_uid")?.as_u64()?;
105109
if class_uid != 4001 && class_uid != 4002 {
106110
return None;
107111
}
112+
if class_uid == 4001
113+
&& (v.get("activity_id").and_then(|a| a.as_u64()) == Some(5)
114+
|| v.get("status_detail").and_then(|d| d.as_str()) == Some("policy_dns_ineligible"))
115+
{
116+
return None;
117+
}
108118
let failed = class_uid == 4001 && v.get("activity_id").and_then(|a| a.as_u64()) == Some(4);
109119
let action = match v.get("action").and_then(|a| a.as_str()) {
110120
_ if failed => Action::Failed,
@@ -949,6 +959,35 @@ garbage line\n";
949959
);
950960
}
951961

962+
#[test]
963+
fn skips_ocsf_network_refuse_records() {
964+
// Real OpenShell v0.1.7 (OCSF 1.8.0) policy-DNS refusal followed by the denied connection it precedes.
965+
let t = concat!(
966+
"{\"class_uid\":4001,\"activity_id\":5,\"activity_name\":\"Refuse\",\"status_detail\":\"policy_dns_ineligible\",",
967+
"\"dst_endpoint\":{\"domain\":\"example.com\"},\"action_id\":2,\"action\":\"Denied\",\"metadata\":{\"version\":\"1.8.0\"}}\n",
968+
"{\"class_uid\":4001,\"activity_id\":1,\"status_detail\":\"policy_dns_ineligible\",\"dst_endpoint\":{\"domain\":\"b.example\"},\"action\":\"Denied\"}\n",
969+
"{\"class_uid\":4001,\"activity_id\":1,\"status_detail\":\"transparent_tcp_policy_denied\",",
970+
"\"dst_endpoint\":{\"domain\":\"example.com\",\"ip\":\"198.18.0.3\",\"port\":443},",
971+
"\"actor\":{\"process\":{\"name\":\"/usr/bin/curl\",\"pid\":0}},\"action_id\":2,\"action\":\"Denied\",\"metadata\":{\"version\":\"1.8.0\"}}\n",
972+
);
973+
let e = parse_logs(t, "x");
974+
assert_eq!(e.len(), 1);
975+
assert_eq!(
976+
(
977+
e[0].action,
978+
e[0].host.as_str(),
979+
e[0].port,
980+
e[0].binary.as_deref()
981+
),
982+
(
983+
Action::Denied,
984+
"example.com",
985+
Some(443),
986+
Some("/usr/bin/curl")
987+
)
988+
);
989+
}
990+
952991
#[test]
953992
fn git_helpers_match_their_parent_binary() {
954993
assert!(bin_matches(

0 commit comments

Comments
 (0)