Dangerous examples in nftables documentation

Dmitry Konishchev <[email protected]> Tue, 6 Jan 2026 17:47:01 +0300
Newsgroups gmane.comp.security.firewalls.netfilter.general
Message-ID <CABYZ2k5wSkW7ifYSzw_QekqNz7yrcAG3tN9qKA-dCzaD_uUvhQ@mail.gmail.com>
Hi! Recently I've faced a problem: I have a rule that drops all new
TCP connections which start not with SYN packets:
ct state new tcp flags != syn counter goto bad_tcp_new_packet

It is a very common recommendation which you may find in many blogs.
But my version has a bug: it assumes that SYN packets may not have any
TCP flags enabled except SYN (which is not true) and it turns out that
this rule drops all connections (!) with enabled TCP Explicit
Congestion Notification
(https://en.wikipedia.org/wiki/Explicit_Congestion_Notification).

So `tcp flags & (syn|ack|rst|fin) != syn` should be used instead of
`tcp flags != syn`.

I've faced such a problem in real life. The details can be found in my
blog post:
* Original post in Russian – https://konishchev.ru/posts/nftables-tcp-ecn/
* Google Translated version in English –
https://konishchev-ru.translate.goog/posts/nftables-tcp-ecn/?_x_tr_sl=ru&_x_tr_tl=en&_x_tr_hl=en&_x_tr_pto=wapp

The problem I see is that the official documentation suggest unsafe
matching in its examples without any warning:
* `nft add rule filter input tcp flags != syn counter` in
https://wiki.nftables.org/wiki-nftables/index.php/Matching_packet_headers
* `nft add rule ip filter forward tcp flags syn tcp option maxseg size
set rt mtu` in https://wiki.nftables.org/wiki-nftables/index.php/Mangling_packet_headers
* `tcp flags syn tcp option maxseg size set 1360` in
https://www.netfilter.org/projects/nftables/manpage.html
* `tcp flags cwr` in
https://wiki.nftables.org/wiki-nftables/index.php/Quick_reference-nftables_in_10_minutes
* `tcp dport 8888 tcp flags syn notrack` in
https://wiki.nftables.org/wiki-nftables/index.php/Synproxy

... which then leads to the errors I've faced. And I am not the only
one – https://github.com/search?q=%22tcp+flags+%21%3D+syn%22&type=code

So I suggest to replace these examples in documentation with more safe versions.