Skip to content

Commit 695fc03

Browse files
fastrevmd-labBors (Rust Engineer)claude
authored
ingest: bound normalizer-derived fields (#65)
Several Vector transforms derive classification columns partly from upstream-controlled log content without bounding the result before it reaches storage. Clamp each derivation to a fixed charset/length pattern at the point of assignment, falling back to the sentinel already used elsewhere in the file when a value doesn't match. Co-authored-by: Bors (Rust Engineer) <bors@mechub.dev> Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 25b668b commit 695fc03

1 file changed

Lines changed: 183 additions & 0 deletions

File tree

‎infra/vector/vector.toml‎

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ if err != null {
156156
event_outcome = "unknown"
157157
}
158158
159+
# Bound event_action to a fixed vocabulary before it reaches storage/query
160+
# layers that treat this column as normalizer-controlled. Reject rather
161+
# than truncate/sanitize: an out-of-vocabulary value is a signal, not a
162+
# formatting problem.
163+
if !match(event_action, r'^[a-z0-9_-]{1,64}$') { event_action = "unknown" }
164+
159165
proto_id = to_int(fields."protocol-id")
160166
transport = "unknown"
161167
if proto_id == 6 {
@@ -324,6 +330,9 @@ if action == "allow" {
324330
# network_transport
325331
transport = downcase(protocol)
326332
if transport == "" { transport = "unknown" }
333+
# Bound to a fixed vocabulary before it reaches storage/query layers that
334+
# treat this column as normalizer-controlled.
335+
if !match(transport, r'^[a-z0-9_-]{1,64}$') { transport = "unknown" }
327336
328337
# --- base event; only safe defaults, branch fills the rest ---
329338
ev = {}
@@ -362,6 +371,7 @@ if nat_dst_ip != "" && nat_dst_ip != "0.0.0.0" { ext = set!(ext, ["panw.panos.na
362371
if log_type == "TRAFFIC" {
363372
ev.event_category = ["network"]
364373
ev.event_action = "flow_" + downcase(subtype)
374+
if !match(ev.event_action, r'^[a-z0-9_-]{1,64}$') { ev.event_action = "unknown" }
365375
ev.event_outcome = outcome
366376
ev.network_transport = transport
367377
ev.rule_name = rule_name
@@ -391,6 +401,7 @@ if log_type == "TRAFFIC" {
391401
} else if log_type == "THREAT" {
392402
ev.event_category = ["network", "intrusion_detection"]
393403
ev.event_action = "threat_" + downcase(subtype)
404+
if !match(ev.event_action, r'^[a-z0-9_-]{1,64}$') { ev.event_action = "unknown" }
394405
ev.event_outcome = outcome
395406
ev.network_transport = transport
396407
ev.rule_name = rule_name
@@ -427,6 +438,7 @@ if log_type == "TRAFFIC" {
427438
# SYSTEM (short): 9 EventID, 13 Module, 14 Severity, 15 Description
428439
ev.event_category = ["host"]
429440
ev.event_action = "system_" + downcase(subtype)
441+
if !match(ev.event_action, r'^[a-z0-9_-]{1,64}$') { ev.event_action = "unknown" }
430442
if length(f) > 8 {
431443
sysev = string(f[8]) ?? ""
432444
if sysev != "" { ext = set!(ext, ["panw.panos.event_id_str"], sysev) }
@@ -443,6 +455,7 @@ if log_type == "TRAFFIC" {
443455
# CONFIG (short): 10 Command, 11 Admin, 12 Client, 13 Result
444456
ev.event_category = ["configuration"]
445457
ev.event_action = "config_" + downcase(subtype)
458+
if !match(ev.event_action, r'^[a-z0-9_-]{1,64}$') { ev.event_action = "unknown" }
446459
if length(f) > 10 {
447460
adminv = string(f[10]) ?? ""
448461
if adminv != "N/A" { ev.user_name = adminv }
@@ -468,6 +481,7 @@ if log_type == "TRAFFIC" {
468481
} else {
469482
ev.event_action = downcase(log_type)
470483
}
484+
if !match(ev.event_action, r'^[a-z0-9_-]{1,64}$') { ev.event_action = "unknown" }
471485
} else {
472486
# Malformed / short: no log_type at all
473487
ev.event_action = "unknown"
@@ -557,6 +571,7 @@ if cerr != null {
557571
} else {
558572
ev.event_action = "alert"
559573
}
574+
if !match(ev.event_action, r'^[a-z0-9_-]{1,64}$') { ev.event_action = "unknown" }
560575
561576
# Detection vs prevention: act=blocked/dropped is an enforced block.
562577
act = downcase(string(doc.act) ?? "")
@@ -568,6 +583,7 @@ if cerr != null {
568583
569584
proto = downcase(string(doc.proto) ?? "")
570585
if proto != "" { ev.network_transport = proto }
586+
if !match(ev.network_transport, r'^[a-z0-9_-]{1,64}$') { ev.network_transport = "unknown" }
571587
572588
sp = to_int(doc.spt) ?? null
573589
if sp != null { ev.source_port = sp }
@@ -807,6 +823,7 @@ if perr != null {
807823
} else {
808824
ev.event_action = "task_" + dtype
809825
}
826+
if !match(ev.event_action, r'^[a-z0-9_-]{1,64}$') { ev.event_action = "unknown" }
810827
} else {
811828
# pvedaemon/pveproxy auth failure: "authentication failure; rhost=<ip> user=<u> msg=..."
812829
afm, aferr = parse_regex(msg, r'authentication failure;\s*rhost=(?P<ip>\S+)\s+user=(?P<user>\S+)')
@@ -2496,3 +2513,169 @@ source = '''
24962513
assert_eq!(.source_ip, "10.65.1.10")
24972514
assert_eq!(.destination_ip, "10.66.2.20")
24982515
'''
2516+
2517+
# --- out-of-vocabulary derived-field bounds (clamp to a fixed sentinel) ---
2518+
# Each case below feeds a value through an upstream-controlled field that
2519+
# would otherwise land in a normalizer-derived column unbounded.
2520+
2521+
[[tests]]
2522+
name = "srx_rt_generic_fallback_bounds_invalid_chars_to_unknown"
2523+
[[tests.inputs]]
2524+
insert_at = "srx_ecs"
2525+
type = "raw"
2526+
value = '<14>1 2026-07-01T12:00:00.000Z vsrx-isp-b RT_IDS - RT_IDP!INJECTED [junos@2636.1.1.1.2.36 source-address="10.65.1.10" destination-address="10.66.2.20"]'
2527+
[[tests.outputs]]
2528+
extract_from = "srx_ecs"
2529+
[[tests.outputs.conditions]]
2530+
type = "vrl"
2531+
source = '''
2532+
assert_eq!(.event_action, "unknown")
2533+
'''
2534+
2535+
[[tests]]
2536+
name = "panos_traffic_subtype_with_space_bounds_event_action_to_unknown"
2537+
[[tests.inputs]]
2538+
insert_at = "panos_ecs"
2539+
type = "raw"
2540+
value = '<14>Jun 06 23:20:00 panosvm.example.com ,2026/06/06 23:20:00,007054000012345,TRAFFIC,end bad,,2026/06/06 23:20:00,203.0.113.50,198.51.100.20,0.0.0.0,0.0.0.0,allow-trust-to-untrust,,,ssl,vsys1,trust,untrust,ethernet1/2,ethernet1/1,,,40001,1,52344,443,0,0,0x0,tcp,allow,8000,3000,5000,40,2026/06/06 23:19:30,30,any,,1001,0x0,203.0.113.0-203.0.113.255,US,,22,18,tcp-fin'
2541+
[[tests.outputs]]
2542+
extract_from = "panos_ecs"
2543+
[[tests.outputs.conditions]]
2544+
type = "vrl"
2545+
source = '''
2546+
assert_eq!(.event_action, "unknown")
2547+
assert_eq!(.network_transport, "tcp")
2548+
'''
2549+
2550+
[[tests]]
2551+
name = "panos_threat_subtype_over_length_bound_becomes_unknown"
2552+
[[tests.inputs]]
2553+
insert_at = "panos_ecs"
2554+
type = "raw"
2555+
value = '<14>Jun 06 23:22:00 panosvm.example.com ,2026/06/06 23:22:00,007054000012345,THREAT,aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,,2026/06/06 23:22:00,198.51.100.77,203.0.113.8,0.0.0.0,0.0.0.0,allow-untrust-to-trust,,,web-browsing,vsys1,untrust,trust,ethernet1/1,ethernet1/2,,,40003,1,44012,80,0,0,0x0,tcp,reset-both,exploit.example/path,30001,code-execution,critical,client-to-server,1003,0x0,US,US'
2556+
[[tests.outputs]]
2557+
extract_from = "panos_ecs"
2558+
[[tests.outputs.conditions]]
2559+
type = "vrl"
2560+
source = '''
2561+
assert_eq!(.event_action, "unknown")
2562+
'''
2563+
2564+
[[tests]]
2565+
name = "panos_generic_fallback_subtype_with_delimiter_bounds_to_unknown"
2566+
[[tests.inputs]]
2567+
insert_at = "panos_ecs"
2568+
type = "raw"
2569+
value = '<14>Jun 06 23:28:00 panosvm.example.com ,2026/06/06 23:28:00,007054000012345,HIPMATCH,match bad value,,2026/06/06 23:28:00,203.0.113.50,198.51.100.20,0.0.0.0,0.0.0.0,,,,,vsys1,,,,,,,,,,,,,,,,,,,,,,,,,'
2570+
[[tests.outputs]]
2571+
extract_from = "panos_ecs"
2572+
[[tests.outputs.conditions]]
2573+
type = "vrl"
2574+
source = '''
2575+
assert_eq!(.event_action, "unknown")
2576+
assert_eq!(.ext."panw.panos.type", "HIPMATCH")
2577+
'''
2578+
2579+
[[tests]]
2580+
name = "panos_traffic_protocol_with_delimiter_bounds_transport_to_unknown"
2581+
[[tests.inputs]]
2582+
insert_at = "panos_ecs"
2583+
type = "raw"
2584+
value = '<14>Jun 06 23:21:00 panosvm.example.com ,2026/06/06 23:21:00,007054000012345,TRAFFIC,deny,,2026/06/06 23:21:00,198.51.100.99,203.0.113.5,0.0.0.0,0.0.0.0,default-deny,,,incomplete,vsys1,untrust,trust,ethernet1/1,ethernet1/2,,,40002,1,51000,3389,0,0,0x0,tcp bad,deny,200,200,0,2,2026/06/06 23:20:30,0,any,,1002,0x0,198.51.100.0-198.51.100.255,US,,2,0,policy-deny'
2585+
[[tests.outputs]]
2586+
extract_from = "panos_ecs"
2587+
[[tests.outputs.conditions]]
2588+
type = "vrl"
2589+
source = '''
2590+
assert_eq!(.event_action, "flow_deny")
2591+
assert_eq!(.network_transport, "unknown")
2592+
'''
2593+
2594+
[[tests]]
2595+
name = "unifi_cef_policy_name_with_delimiters_bounds_event_action_to_unknown"
2596+
[[tests.inputs]]
2597+
insert_at = "unifi_ips"
2598+
type = "raw"
2599+
value = 'Jun 14 19:49:59 UCK-G2-Plus-site-controller CEF:0|Ubiquiti|UniFi Network|10.68.57|200|Threat Detected|7|UNIFIcategory=Security UNIFIsite=Default UNIFIhost=UCK G2 Plus site-controller proto=TCP spt=38738 dpt=22 act=allowed app=SSH UNIFIrisk=medium UNIFIpolicyName=Scanning; bad value UNIFIpolicyType=IDS/IPS UNIFIdirection=outgoing UNIFIdeviceMac=02:00:01:27:fb:2b UNIFIdeviceName=Gateway Max UNIFIdeviceIp=198.51.100.1 UNIFIsrcClientAlias=ssdf-vector UNIFIsrcClientMac=02:01:01:02:a1:46 UNIFIsrcZone=Internal UNIFIdstClientMac=02:00:01:27:fb:2c UNIFIdstZone=External UNIFIipsSessionId=1190371755462149 UNIFIipsSignature=ET SCAN Potential SSH Scan OUTBOUND UNIFIipsSignatureId=2003068 UNIFIutcTime=2026-06-14T19:49:59.858Z msg=A network intrusion attempt has been detected.'
2600+
[[tests.outputs]]
2601+
extract_from = "unifi_ips"
2602+
[[tests.outputs.conditions]]
2603+
type = "vrl"
2604+
source = '''
2605+
assert_eq!(.event_action, "unknown")
2606+
'''
2607+
2608+
[[tests]]
2609+
name = "unifi_cef_protocol_with_space_bounds_transport_to_unknown"
2610+
[[tests.inputs]]
2611+
insert_at = "unifi_ips"
2612+
type = "raw"
2613+
value = 'Jun 14 19:49:59 UCK-G2-Plus-site-controller CEF:0|Ubiquiti|UniFi Network|10.68.57|200|Threat Detected|7|UNIFIcategory=Security UNIFIsite=Default UNIFIhost=UCK G2 Plus site-controller proto=TCP bad spt=38738 dpt=22 act=allowed app=SSH UNIFIrisk=medium UNIFIpolicyName=Scanning Activity UNIFIpolicyType=IDS/IPS UNIFIdirection=outgoing UNIFIdeviceMac=02:00:01:27:fb:2b UNIFIdeviceName=Gateway Max UNIFIdeviceIp=198.51.100.1 UNIFIsrcClientAlias=ssdf-vector UNIFIsrcClientMac=02:01:01:02:a1:46 UNIFIsrcZone=Internal UNIFIdstClientMac=02:00:01:27:fb:2c UNIFIdstZone=External UNIFIipsSessionId=1190371755462149 UNIFIipsSignature=ET SCAN Potential SSH Scan OUTBOUND UNIFIipsSignatureId=2003068 UNIFIutcTime=2026-06-14T19:49:59.858Z msg=A network intrusion attempt has been detected.'
2614+
[[tests.outputs]]
2615+
extract_from = "unifi_ips"
2616+
[[tests.outputs.conditions]]
2617+
type = "vrl"
2618+
source = '''
2619+
assert_eq!(.event_action, "alert_scanning-activity")
2620+
assert_eq!(.network_transport, "unknown")
2621+
'''
2622+
2623+
[[tests]]
2624+
name = "panos_system_subtype_with_space_bounds_event_action_to_unknown"
2625+
[[tests.inputs]]
2626+
insert_at = "panos_ecs"
2627+
type = "raw"
2628+
value = '<14>Jun 06 23:25:00 panosvm.example.com ,2026/06/06 23:25:00,007054000012345,SYSTEM,general bad,,2026/06/06 23:25:00,vsys1,general,,,,general,informational,System started successfully'
2629+
[[tests.outputs]]
2630+
extract_from = "panos_ecs"
2631+
[[tests.outputs.conditions]]
2632+
type = "vrl"
2633+
source = '''
2634+
assert_eq!(.event_action, "unknown")
2635+
assert_eq!(.event_category, ["host"])
2636+
'''
2637+
2638+
[[tests]]
2639+
name = "panos_config_subtype_with_space_bounds_event_action_to_unknown"
2640+
[[tests.inputs]]
2641+
insert_at = "panos_ecs"
2642+
type = "raw"
2643+
value = '<14>Jun 06 23:27:00 panosvm.example.com ,2026/06/06 23:27:00,007054000012345,CONFIG,set bad,,2026/06/06 23:27:00,198.51.100.225,vsys1,set,admin,198.51.100.199,Succeeded,vsys vsys1 rulebase security'
2644+
[[tests.outputs]]
2645+
extract_from = "panos_ecs"
2646+
[[tests.outputs.conditions]]
2647+
type = "vrl"
2648+
source = '''
2649+
assert_eq!(.event_action, "unknown")
2650+
assert_eq!(.event_category, ["configuration"])
2651+
'''
2652+
2653+
[[tests]]
2654+
name = "proxmox_task_start_dtype_uppercase_bounds_event_action_to_unknown"
2655+
[[tests.inputs]]
2656+
insert_at = "proxmox_ecs"
2657+
type = "raw"
2658+
value = "<86>1 2026-06-14T20:05:00.000000+00:00 pve3 pvedaemon 1234 - - <root@pam> starting task UPID:pve3:00001A2B:0000ABCD:686D1234:QMSTART:210:root@pam:"
2659+
[[tests.outputs]]
2660+
extract_from = "proxmox_ecs"
2661+
[[tests.outputs.conditions]]
2662+
type = "vrl"
2663+
source = '''
2664+
assert_eq!(.event_action, "unknown")
2665+
assert_eq!(.event_category, ["configuration"])
2666+
'''
2667+
2668+
[[tests]]
2669+
name = "proxmox_task_end_dtype_uppercase_bounds_event_action_to_unknown"
2670+
[[tests.inputs]]
2671+
insert_at = "proxmox_ecs"
2672+
type = "raw"
2673+
value = "<86>1 2026-06-14T20:05:05.000000+00:00 pve3 pvedaemon 1234 - - <root@pam> end task UPID:pve3:00001A2B:0000ABCD:686D1234:QMSTART:210:root@pam: OK"
2674+
[[tests.outputs]]
2675+
extract_from = "proxmox_ecs"
2676+
[[tests.outputs.conditions]]
2677+
type = "vrl"
2678+
source = '''
2679+
assert_eq!(.event_action, "unknown")
2680+
assert_eq!(.event_outcome, "success")
2681+
'''

0 commit comments

Comments
 (0)