pcap: preserve capture and protocol source history

Port relevant PCAP implementation and regression snapshots from Craft Anything d67583b183e42bdb69a5ab440d2403eea58c7b0d.
This commit is contained in:
RRFZ authored and Dylan M. Taylor committed 2026-11-17 08:37:53 -05:00
1 parent 747080c659
commit a9acede958
2 files changed
+37 -2

No files matched your search

+5 -2
View File
@@ -1176,7 +1176,10 @@ fn dns(msg: &[u8], d: &mut Decoded, label: &'static str, mdns_wire_format: bool)
d.dns = Some(out);
}
const METHODS: &[&str] = &["GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS", "PATCH", "CONNECT", "TRACE"];
/// HTTP method names are case-sensitive tokens, including extension methods.
fn http_method(method: &str) -> bool {
!method.is_empty() && method.bytes().all(|b| b.is_ascii_alphanumeric() || b"!#$%&'*+-.^_`|~".contains(&b))
}
/// Remove `user:password@` from an absolute request target.
pub fn strip_userinfo(target: &str) -> String {
@@ -1209,7 +1212,7 @@ fn tcp_app(p: &[u8], d: &mut Decoded) {
return;
}
if let (Some(m), Some(t), Some(v)) = fields
&& METHODS.contains(&m)
&& http_method(m)
&& !t.is_empty()
&& !t.bytes().any(|b| b.is_ascii_control())
&& version(v)
+32
View File
@@ -0,0 +1,32 @@
use craft_anything_formats::pcap::decode;
use craft_anything_testkit::pcap::{ipv4_pkt, tcp};
/// WebDAV and extension methods retain the same HTTP evidence as core methods.
#[test]
fn extension_methods_are_http_requests() {
for method in ["PROPFIND", "MKCOL", "LOCK", "REPORT", "M-SEARCH", "custom", "X!#$%&'*+-.^_`|~012"] {
let request = format!("{method} /collection/ HTTP/1.1\r\nHost: dav.example\r\n\r\n");
let decoded = decode(101, &ipv4_pkt(6, [1; 4], [2; 4], &tcp(100, 80, 0x18, request.as_bytes())));
let http = decoded.http.unwrap_or_else(|| panic!("missing HTTP: {method}"));
assert_eq!(http.method.as_deref(), Some(method));
assert_eq!(http.target.as_deref(), Some("/collection/"));
assert_eq!(http.host.as_deref(), Some("dav.example"));
}
}
/// A method still needs a nonempty ASCII token and a complete valid start line.
#[test]
fn invalid_extension_method_lines_are_not_http() {
for request in [
" / HTTP/1.1\r\n",
"BAD:METHOD / HTTP/1.1\r\n",
"BAD/METHOD / HTTP/1.1\r\n",
"MÉTHOD / HTTP/1.1\r\n",
"BAD\tMETHOD / HTTP/1.1\r\n",
"PROPFIND / HTTP/1.1",
"PROPFIND / HTTP/no\r\n",
] {
let decoded = decode(101, &ipv4_pkt(6, [1; 4], [2; 4], &tcp(100, 80, 0x18, request.as_bytes())));
assert!(decoded.http.is_none(), "{request:?}");
}
}