Skip to content

IMAP protocol parser, logger and sticky buffers v9#15730

Open
glongo wants to merge 4 commits into
OISF:mainfrom
glongo:dev-imap-proto-v9
Open

IMAP protocol parser, logger and sticky buffers v9#15730
glongo wants to merge 4 commits into
OISF:mainfrom
glongo:dev-imap-proto-v9

Conversation

@glongo

@glongo glongo commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Changes:

Link to ticket: https://redmine.openinfosecfoundation.org/issues/8276

Previous PR: #15648

SV_BRANCH=OISF/suricata-verify#2908

glongo added 4 commits June 25, 2026 14:29
This introduces a parser for IMAP protocol.

An IMAP transaction has two states driven by the 'complete' field:
  - Open (complete = false): waiting for a matching tagged response.
  - Complete (complete = true): tagged response received, or special
    conditions met (BYE, server greeting).

  Completion logic (is_complete):
  - If a tagged request exists: requires a matching tagged response.
  - No tagged request + BYE: complete (server closing).
  - No tagged request + any response: complete (server greeting).

  Transactions are created in three places:
  1. Request parser: every parsed command creates a new tx.
  2. Response parser (tagged, no matching request): midstream/async;
     orphan tagged response gets its own tx.
  3. Response parser (untagged, no incomplete tx): server greeting or
     unsolicited response.

  Once open, messages accumulate:
  - Request side: continuation and literal data attach to the most
    recent incomplete tx.
  - Response side: untagged responses attach to the most recent
    incomplete tx; tagged responses attach via find_request(tag).

  Email extraction happens at most once per tx:
  - From literal data in APPEND commands (request side).
  - From FETCH response data (response side).

  Seven hard limits prevent unbounded growth:
  - IMAP_MAX_TX (256, configurable): total transactions. Exceeded:
    all incomplete txs force-completed with TooManyTransactions event.
  - IMAP_MAX_MSGS_PER_TX (512): requests/responses per tx. Exceeded:
    message silently dropped.
  - IMAP_MAX_LINES (512): request/response lines per tx. Exceeded:
    line silently dropped.
  - IMAP_MAX_BODY_SIZE (10MB): email body in ImapParsedEmail.
    Exceeded: body truncated, BodyTooLarge event.
  - IMAX_MAX_HEADERS (512): Numbers of headers parsed and stored. Exceeded:
    TooManyHeaders event.
  - IMAP_MAX_LINE_SIZE (8KB): request/response line max length. Exceeded:
    LineTooLong event.
  - Literal size (u32): bounded by declared size in {N} specifier.

  IMAP_MAX_TX only is configurable limit via app-layer.protocols.imap.max-tx.

Ticket OISF#8276
This introduces a logger for IMAP protocol.

Ticket OISF#8276
This implements the following sticky buffers for IMAP protocol:
- imap.request
- imap.response

The following frames have been added:
- imap.body
- imap.headers
- imap.pdu

The following email sticky buffers have been updated to work with IMAP:
- email.from
- email.subject
- email.to
- email.cc
- email.date
- email.message_id
- email.x_mailer

The following email sticky buffers have been added and are supported
only for IMAP:
- email.command
- email.body
- email.header
- email.header.name
- email.header.value

Ticket OISF#8276
@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.87805% with 403 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.97%. Comparing base (09f0851) to head (9fd858c).

Additional details and impacted files
@@            Coverage Diff            @@
##             main   #15730     +/-   ##
=========================================
  Coverage   82.96%   82.97%             
=========================================
  Files        1003     1006      +3     
  Lines      275031   277647   +2616     
=========================================
+ Hits       228192   230366   +2174     
- Misses      46839    47281    +442     
Flag Coverage Δ
fuzzcorpus 60.92% <13.83%> (-0.55%) ⬇️
livemode 18.31% <11.95%> (-0.07%) ⬇️
netns 22.57% <11.95%> (-0.18%) ⬇️
pcap 45.58% <66.12%> (+0.19%) ⬆️
suricata-verify 67.06% <79.31%> (+0.11%) ⬆️
unittests 58.40% <53.39%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread doc/userguide/upgrade.rst
suricata.yaml is now 1 MiB instead of 0/unlimited.
- LLMNR protocol parser, logger and sticky buffers are implemented.
- IMAP protocol parser is enabled by default.
- IMAP logger and sticky buffers are implemented.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not a changelog, only important changes to existing deployments should be mentioned

Comment thread rust/src/imap/imap.rs
#[derive(Default, Debug)]
pub struct ImapTransaction {
pub tx_id: u64,
pub complete: bool,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll need a per direction tx state (progress) tracking. A Tx can be complete in one direction, but not the other. We need this for the firewall work. In the simplest form this would be complete_ts, complete_tc. It needs to be real time too, so ts can't wait for tc.

Comment thread rust/src/imap/detect.rs
};
let _ = helper_keyword_register_multi_buffer(&kw);

G_IMAP_REQUEST_BUFFER_ID = SCDetectHelperMultiBufferMpmRegister(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are registered at progress 0, but it's unclear if that is the correct time. See also the required progress tracking update mention elsewhere in the PR.

Comment thread rust/src/imap/imap.rs
LiteralInfo, IMAP_MAX_BODY_SIZE, IMAP_MAX_LINE_SIZE,
};
use nom::character::complete::crlf;
use nom7 as nom;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new parser should use nom 8

@suricata-qa

Copy link
Copy Markdown

WARNING:

field baseline test %
SURI_TLPR1_stats_chk
.app_layer.flow.ftp_data 604 678 112.25%
.app_layer.error.ftp.parser 17 0 -

Pipeline = 32260

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants