Bug #9525
opentls: server_name with a trailing dot evades anchored tls.sni rules
Description
Summary¶
Suricata keeps a trailing dot in the TLS server_name. A ClientHello for example.com. puts example.com. in tls.sni, so rules that anchor the end of the name don't match it. This includes the pattern shown in the dotprefix documentation (dotprefix; content:".example.com"; endswith;), exact matches (content:"example.com"; startswith; endswith;), bsize and exact-match datasets. No app-layer event is raised.
RFC 6066 section 3 says the host name is sent "without a trailing dot", so compliant clients never send one. Nothing stops a client from sending it on purpose, though, and a server the sender controls can complete the handshake.
Affected Versions¶
Found by code reading at:
maind622b4f695e8 (2026-12-03)main-8.0.x0ff030dce6a3 (2026-12-02)main-7.0.x872704f72fa4 (2026-07-08). Here the SNI is NUL-terminated andtls.sniusesstrlen(), but the dot is kept the same way.
Preconditions¶
- TLS parsing enabled (the default).
- A rule that anchors the end of
tls.sni. - The client adds one or more dots to the end of
server_name. The client controls this field, so no special access is needed.
Security Impact¶
Rules that alert on, drop or reject a domain by its SNI don't fire when the client adds a trailing dot. Policies that pass listed domains and drop everything else fail closed instead: the dotted name is dropped. There is no crash or memory-safety impact.
Vulnerable Code¶
src/app-layer-ssl.c, TLSDecodeHSHelloExtensionSni() (main, line 1044): the name is copied as received. The only checks are the name type, a length of 1 to 255, and duplicate extensions.
ssl_state->curr_connp->sni_len = sni_len;
ssl_state->curr_connp->sni = SCMalloc(sni_len);
...
if (SafeMemcpy(ssl_state->curr_connp->sni, 0, sni_len, initial_input, consumed, input_len,
sni_len) != 0) {
src/detect-tls-sni.c, GetData() (main, line 123): the buffer is that copy, changed only by the rule's own transforms.
const uint32_t data_len = ssl_state->client_connp.sni_len;
const uint8_t *data = ssl_state->client_connp.sni;
SCInspectionBufferSetupAndApplyTransforms(
det_ctx, list_id, buffer, data, data_len, transforms);
Reproduction¶
The pcap has two TLS flows that differ only in server_name: example.com and example.com..
alert tls any any -> any any (msg:"exact"; tls.sni; content:"example.com"; startswith; endswith; nocase; sid:1;) alert tls any any -> any any (msg:"dotprefix"; tls.sni; dotprefix; content:".example.com"; endswith; nocase; sid:2;) alert tls any any -> any any (msg:"bsize"; tls.sni; bsize:11; content:"example.com"; nocase; sid:3;) alert tls any any -> any any (msg:"control, unanchored"; tls.sni; content:"example.com"; nocase; sid:4;)
Expected: all four rules alert on both flows.
Actual: on the example.com. flow only sid 4 alerts. eve/tls logs the SNI as example.com., and no TLS anomaly is logged.
Fix Recommendation¶
- Strip all trailing dots from the server name before it reaches
tls.sni, as libhtp already does for URI host names (normalized_hostname()inrust/htp/src/uri.rs). That fixes existing rules with no rule changes. Logging the raw name in eve/tls would keep the attempt visible. - Consider an app-layer event for a
server_namewith a trailing dot, since RFC 6066 forbids it. IPS users could then drop those handshakes. - An opt-in transform alone isn't enough: it would help new rules but leave existing rulesets open.
Related: http.host¶
http.host has the same gap in most cases:
- Host from an absolute-form request URI (
GET http://example.com./ HTTP/1.1): libhtp lowercases it and strips trailing dots (rust/htp/src/uri.rs, line 128), sohttp.hostisexample.com. - Host from the
Hostheader: only lowercased (rust/htp/src/transaction.rs, line 821), soHost: example.com.givesexample.com.. - HTTP/2:
http2_normalize_host()inrust/src/http2/detect.rsremoves userinfo and the port and lowercases, but keeps the dot.
Unlike SNI, a trailing dot is valid in a URI host (RFC 3986 section 3.2.2), so the fix there is to normalize for matching rather than flag it. This can be split into its own ticket if preferred.
Files