]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
websocket: trigger raw stream inspection
authorShivani Bhardwaj <shivani@oisf.net>
Wed, 21 May 2025 07:18:48 +0000 (12:48 +0530)
committerVictor Julien <victor@inliniac.net>
Wed, 21 May 2025 17:42:06 +0000 (19:42 +0200)
Internals
---------
Suricata's stream engine returns data for inspection to the detection
engine from the stream when the chunk size is reached.

Bug
---
Inspection triggered only in the specified chunk sizes may be too late
when it comes to inspection of smaller protocol specific data which
could result in delayed inspection, incorrect data logged with a transaction
and logs misindicating the pkt that triggered an alert.

Fix
---
Fix this by making an explicit call from all respective applayer parsers to
trigger raw stream inspection which shall make the data available for inspection
in the following call of the stream engine. This needs to happen per direction
on the completion of an entity like a request or a response.

Important notes
---------------
1. The above mentioned behavior with and without this patch is
affected internally by the following conditions.
- inspection depth
- stream depth
In these special cases, the inspection window will be affected and
Suricata may not consider all the data that could be expected to be
inspected.
2. This only applies to applayer protocols running over TCP.
3. The inspection window is only considered up to the ACK'd data.
4. This entire issue is about IDS mode only.

Websocket parser creates a new PDU per transaction in each direction. Appropriate
calls to trigger raw stream inspection have been added on succesful parsing of
each PDU.

Task 7026
Bug 7004

rust/src/websocket/websocket.rs

index 11378d631a342084022c5ec9977ae790c9fd4cc9..f077f7a41617707964291a07e88ce2db409613ae 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2023 Open Information Security Foundation
+/* Copyright (C) 2023-2025 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
@@ -18,7 +18,7 @@
 use super::parser;
 use crate::applayer::{self, *};
 use crate::conf::conf_get;
-use crate::core::{ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_TCP};
+use crate::core::{ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_TCP, sc_app_layer_parser_trigger_raw_stream_inspection};
 use crate::direction::Direction;
 use crate::flow::Flow;
 use crate::frames::Frame;
@@ -282,6 +282,9 @@ impl WebSocketState {
                             }
                         }
                     }
+                    if tx.pdu.fin {
+                        sc_app_layer_parser_trigger_raw_stream_inspection(flow, direction as i32);
+                    }
                     self.transactions.push_back(tx);
                 }
                 Err(nom::Err::Incomplete(needed)) => {