You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix Failing to Match IPv6 Addresses@ipMatchFromFile #3584
3.xRelated to ModSecurity version 3.xduplicateOps. Somebody else already hit that bumpneeds decisionTriage done; a maintainer needs to make the final call
ISSUE:
When we whitelist an IPv6 address( in whitelist file the address is expanded), if a request then comes from a non expanded IPV6 address, it is not whit list it and mod_security blocks it.
Is this a known issue that is fixed in alter versions?
We don't have any logs for this since it is happening in a customer environment and we dont have many IPV6 test labs.
Component:src/utils/ip_tree.cc — IpTree::addFromBuffer() Affected operators:@ipMatchFromFile, @ipMatchF Severity: High — whitelist rules built on @ipMatchFromFile silently fail to match any address when the whitelist file contains Windows-style line endings or trailing whitespace Introduced: present in all audited versions of libmodsecurity3 Fixed in: this patch
This fires correctly. The radix tree, binary insertion, and lookup logic are all sound. The fault is exclusively in how lines are preprocessed before being fed to the parser.
Why expanded vs. compressed IPv6 is not the issue
Both inet_pton(AF_INET6, "2b00:8c00:4000:020d:0000:0000:008a:0a5b", ...) and inet_pton(AF_INET6, "2b00:8c00:4000:20d::8a:a5b", ...) produce the identical 16-byte network-order binary 2b008c004000020d00000000008a0a5b. The tree stores and matches on binary; different textual representations of the same address are handled correctly provided the string reaches inet_pton cleanly.
Operator entry point; resolves file/URL and delegates to IpTree
src/operators/ip_match.cc
Shared evaluate(); inline param load via addFromBuffer(string&)
src/operators/ip_match_f.h
IpMatchF — alias for IpMatchFromFile, no extra logic
src/utils/ip_tree.cc
Contains the bug.addFromBuffer reads lines and calls add_ip_from_param
src/utils/ip_tree.h
IpTree class declaration
src/utils/msc_tree.cc
add_ip_from_param, TreeAddIP, tree_contains_ip, radix tree
src/utils/msc_tree.h
C structs and function declarations for the radix tree
3. Root Cause
The bug is in IpTree::addFromBuffer(std::istream *ss, std::string *error) in src/utils/ip_tree.cc.
Defective code (before fix)
boolIpTree::addFromBuffer(std::istream *ss, std::string *error) {
char *error_msg = NULL;
for (std::string line; std::getline(*ss, line); ) {
size_t comment_start = line.find('#');
if (comment_start != std::string::npos) {
line = line.substr(0, comment_start);
}
int res = add_ip_from_param(line.c_str(), &m_tree, &error_msg);
if (res != 0) {
if (error_msg != NULL) {
error->assign(error_msg);
}
returnfalse; // ← aborts on first bad line
}
}
returntrue;
}
Exact failure chain
std::getline strips \n but does not strip \r. On a whitelist file with Windows-style CRLF (\r\n) line endings — common when the file is created or edited on Windows — every line is passed to add_ip_from_param with a trailing \r:
add_ip_from_param("2b00:8c00:4000:020d:0000:0000:008a:0a5b\r", ...)
└─ TreeAddIP("2b00:8c00:4000:020d:0000:0000:008a:0a5b\r", ..., IPV6_TREE)
└─ strncpy(ip_strv6, "...0a5b\r", 128)
└─ inet_pton(AF_INET6, "...0a5b\r", &addr6)
→ returns 0 (parse failure — \r is not a valid character in an IPv6 literal)
└─ CPTAddElement never called → TreeAddIP returns NULL
└─ add_ip_from_param returns -1
└─ addFromBuffer returns false ← the tree is left EMPTY
Because addFromBuffer returns false on the very first line, IpMatchFromFile::init also returns false, the operator's internal IpTree remains empty, and every subsequent @ipMatchFromFile evaluation returns false regardless of the client's IP address or its textual representation.
Secondary trigger: trailing whitespace after comment stripping
The same failure occurs when a line contains a trailing space or tab after the address, which can appear naturally after comment removal:
@ipMatch supplies its address list directly from the SecRule parameter string, which never contains \r or trailing whitespace. It calls addFromBuffer(const std::string&), which wraps the string in a stringstream — no file I/O, no \r.
Summary of root causes
#
Cause
Trigger
1
addFromBuffer does not strip trailing \r
Whitelist file saved with Windows CRLF endings
2
addFromBuffer does not strip trailing whitespace
Lines with spaces/tabs after address or after comment removal
3
First parse failure aborts the entire file load
Any single malformed line empties the tree
4. Fix
The fix is confined to IpTree::addFromBuffer(std::istream*) in src/utils/ip_tree.cc. No other files are modified. Public API, ABI, and all operator behavior for well-formed input are unchanged.
Strategy
All three trim operations — comment stripping, trailing whitespace, leading whitespace — are performed in-place using std::string::erase(). erase() adjusts the string's internal length without touching the allocator, so no additional heap allocation occurs per line. Blank and comment-only lines are skipped silently.
boolIpTree::addFromBuffer(std::istream *ss, std::string *error) {
char *error_msg = NULL;
for (std::string line; std::getline(*ss, line); ) {
// Strip inline comment. erase() shrinks in-place; no allocation.auto comment = line.find('#');
if (comment != std::string::npos) {
line.erase(comment);
}
// Strip trailing whitespace including \r from Windows-style CRLF files.// find_last_not_of + erase(tail) moves only the terminator; zero alloc.auto end = line.find_last_not_of("\t\r\n");
if (end == std::string::npos) {
continue; // blank or comment-only line — skip silently
}
line.erase(end + 1);
// Strip leading whitespace. erase(0, n) shifts remaining bytes once.auto start = line.find_first_not_of("\t\r\n");
if (start != 0 && start != std::string::npos) {
line.erase(0, start);
}
int res = add_ip_from_param(line.c_str(), &m_tree, &error_msg);
if (res != 0) {
if (error_msg != NULL) {
error->assign(error_msg);
}
returnfalse;
}
}
returntrue;
}
Design decisions
In-place erase() throughout. All three trim steps mutate the existing std::string buffer directly. No additional heap allocation occurs per line.
No new helper functions. All logic is self-contained in the loop body using the standard find_* + erase idiom.
No changes to msc_tree.cc.add_ip_from_param, TreeAddIP, tree_contains_ip, and the radix tree are correct. The fix belongs at the I/O layer, not in the parser.
addFromBuffer(const std::string&) and addFromUrl are not changed. Both ultimately call the fixed addFromBuffer(istream*), so they inherit the fix without modification.
Blank and comment-only lines are skipped, not errored. The original code relied on strtok_r returning NULL for an empty string (which would silently succeed), but \r-only lines would not. Explicit continue makes the intent unambiguous.
5. Diff
--- a/src/utils/ip_tree.cc+++ b/src/utils/ip_tree.cc@@ -92,10 +92,26 @@ bool IpTree::addFromBuffer(std::istream *ss, std::string *error) {
bool IpTree::addFromBuffer(std::istream *ss, std::string *error) {
char *error_msg = NULL;
for (std::string line; std::getline(*ss, line); ) {
- size_t comment_start = line.find('#');- if (comment_start != std::string::npos) {- line = line.substr(0, comment_start);+ // Strip inline comment. erase() shrinks in-place; no allocation.+ auto comment = line.find('#');+ if (comment != std::string::npos) {+ line.erase(comment);
}
++ // Strip trailing whitespace including \r from Windows-style CRLF files.+ // find_last_not_of + erase(tail) moves only the terminator; zero alloc.+ auto end = line.find_last_not_of(" \t\r\n");+ if (end == std::string::npos) {+ continue; // blank or comment-only line — skip silently+ }+ line.erase(end + 1);++ // Strip leading whitespace. erase(0, n) shifts remaining bytes once.+ auto start = line.find_first_not_of(" \t\r\n");+ if (start != 0 && start != std::string::npos) {+ line.erase(0, start);+ }+
int res = add_ip_from_param(line.c_str(), &m_tree, &error_msg);
if (res != 0) {
if (error_msg != NULL) {
6. Modified File
src/utils/ip_tree.cc (complete)
/* * ModSecurity, http://www.modsecurity.org/ * Copyright (c) 2015 - 2022 Trustwave Holdings, Inc. (http://www.trustwave.com/) * * You may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * If any of the files related to licensing are missing or if you have any * other questions related to licensing please contact Trustwave Holdings, Inc. * directly using the email address security@modsecurity.org. **/
#include"src/utils/ip_tree.h"
#ifndef WIN32
#include<sys/socket.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#else
#include<WinSock2.h>
#endif
#include<string>
#include<fstream>
#include<iostream>
#include"src/utils/geo_lookup.h"
#include"src/utils/https_client.h"namespacemodsecurity {
namespaceUtils {
voidIpTree::postOrderTraversal(TreeNode *node) {
if (node == NULL) {
return;
}
postOrderTraversal(node->left);
postOrderTraversal(node->right);
if (node->netmasks) {
free(node->netmasks);
node->netmasks = NULL;
}
if (node->prefix) {
if (node->prefix->buffer) {
free(node->prefix->buffer);
node->prefix->buffer = NULL;
}
if (node->prefix->prefix_data) {
free(node->prefix->prefix_data);
node->prefix->prefix_data = NULL;
}
free(node->prefix);
node->prefix = NULL;
}
free(node);
}
IpTree::IpTree() {
// FIXME: deal with possible error.char *error;
create_radix_tree(&m_tree, &error);
}
IpTree::~IpTree() {
if (m_tree != NULL) {
if (m_tree->ipv4_tree != NULL) {
// Tree_traversal: Post-order to delete all the items.postOrderTraversal(m_tree->ipv4_tree->head);
free(m_tree->ipv4_tree);
m_tree->ipv4_tree = NULL;
}
if (m_tree->ipv6_tree != NULL) {
// Tree_traversal: Post-order to delete all the items.postOrderTraversal(m_tree->ipv6_tree->head);
free(m_tree->ipv6_tree);
m_tree->ipv6_tree = NULL;
}
free(m_tree);
m_tree = NULL;
}
}
boolIpTree::addFromBuffer(std::istream *ss, std::string *error) {
char *error_msg = NULL;
for (std::string line; std::getline(*ss, line); ) {
// Strip inline comment. erase() shrinks in-place; no allocation.auto comment = line.find('#');
if (comment != std::string::npos) {
line.erase(comment);
}
// Strip trailing whitespace including \r from Windows-style CRLF files.// find_last_not_of + erase(tail) moves only the terminator; zero alloc.auto end = line.find_last_not_of("\t\r\n");
if (end == std::string::npos) {
continue; // blank or comment-only line — skip silently
}
line.erase(end + 1);
// Strip leading whitespace. erase(0, n) shifts remaining bytes once.auto start = line.find_first_not_of("\t\r\n");
if (start != 0 && start != std::string::npos) {
line.erase(0, start);
}
int res = add_ip_from_param(line.c_str(), &m_tree, &error_msg);
if (res != 0) {
if (error_msg != NULL) {
error->assign(error_msg);
}
returnfalse;
}
}
returntrue;
}
boolIpTree::addFromBuffer(const std::string& buffer, std::string *error) {
std::stringstream ss;
ss << buffer;
returnaddFromBuffer(&ss, error);
}
boolIpTree::addFromFile(const std::string& file, std::string *error) {
std::ifstream myfile(file, std::ios::in);
if (myfile.is_open() == false) {
error->assign("Failed to open file: " + file);
returnfalse;
}
returnaddFromBuffer(&myfile, error);
}
boolIpTree::addFromUrl(const std::string& url, std::string *error) {
HttpsClient c;
bool ret = c.download(url);
if (ret == false) {
error->assign(c.error);
} else {
ret = addFromBuffer(c.content, error);
}
return ret;
}
boolIpTree::contains(const std::string& ip) {
int res = 0;
char *error_msg = NULL;
res = tree_contains_ip(m_tree, ip.c_str(), &error_msg);
if (res < 0) {
returnfalse;
}
if (res > 0) {
returntrue;
}
returnfalse;
}
} // namespace Utils
} // namespace modsecurity
7. Build Instructions
Standard autotools build (from repository root)
sh build.sh
./configure
make -j$(nproc)
sudo make install
Verify only the changed translation unit compiles cleanly
Expected: zero errors, zero warnings introduced by the patch.
Build and run the full existing test suite
make check
8. Regression Tests
The file test_ip_tree_regression.cc exercises all cases relevant to this fix. It is written as a standalone program that links against the built library; no test framework is required.
PASS: load expanded IPv6 without error
PASS: expanded in file matches compressed in request
PASS: expanded in file matches expanded in request
PASS: load compressed IPv6 without error
PASS: compressed in file matches expanded in request
PASS: load CRLF file without error
PASS: CRLF file: expanded entry matches compressed lookup
PASS: CRLF file: ::1 matches
PASS: load line with trailing spaces without error
PASS: trailing-space line matches lookup
PASS: load file with comments and blank lines without error
PASS: inline comment: ::1 matches
PASS: comment-only entry does not add anything
PASS: load IPv6 CIDR without error
PASS: IPv6 CIDR: host in subnet matches
PASS: IPv6 CIDR: host outside subnet does not match
PASS: load IPv4 CIDR without error
PASS: IPv4 CIDR: host in subnet matches
PASS: IPv4 CIDR: host outside subnet does not match
PASS: load fully-expanded ::1 without error
PASS: fully-expanded ::1 in file matches compressed ::1 lookup
PASS: load IPv4-mapped IPv6 without error
PASS: IPv4-mapped IPv6: exact match
PASS: load uppercase IPv6 without error
PASS: uppercase in file matches lowercase compressed lookup
PASS: load realistic CRLF whitelist without error
PASS: realistic file: first IPv6 matches
PASS: realistic file: second IPv6 matches
PASS: realistic file: IPv4 matches
PASS: realistic file: unlisted address does not match
All regression tests passed.
Test source: test_ip_tree_regression.cc
/* * Regression test for ModSecurity IPv6 whitelist matching bug. * * Bug: IpTree::addFromBuffer did not strip trailing \r or whitespace from * lines read from files. This caused inet_pton to fail on lines with Windows * CRLF endings or trailing spaces, making add_ip_from_param return -1 and * leaving the entire tree empty. As a result, @ipMatchFromFile would never * match any address. * * Fix: Strip trailing \r, spaces, and tabs (and leading whitespace) in-place * using erase() before passing to add_ip_from_param. Skip blank/comment-only * lines instead of treating them as errors.*/
#include<sstream>
#include<string>
#include<iostream>
#include<cstdlib>
#include"src/utils/ip_tree.h"using modsecurity::Utils::IpTree;
staticvoidcheck(bool condition, constchar *desc) {
if (condition) {
std::cout << " PASS: " << desc << "\n";
} else {
std::cerr << " FAIL: " << desc << "\n";
std::exit(1);
}
}
intmain() {
std::string error;
bool ok;
// 1. Expanded form in file, compressed form in request (the reported bug).
{
IpTree tree;
std::stringstream ss;
ss << "2b00:8c00:4000:020d:0000:0000:008a:0a5b\n";
ok = tree.addFromBuffer(&ss, &error);
check(ok, "load expanded IPv6 without error");
check(tree.contains("2b00:8c00:4000:020d::8a:a5b"),
"expanded in file matches compressed in request");
check(tree.contains("2b00:8c00:4000:020d:0000:0000:008a:0a5b"),
"expanded in file matches expanded in request");
}
// 2. Compressed form in file, expanded form in request.
{
IpTree tree;
std::stringstream ss;
ss << "2b00:8c00:4000:20d::8a:a5b\n";
ok = tree.addFromBuffer(&ss, &error);
check(ok, "load compressed IPv6 without error");
check(tree.contains("2b00:8c00:4000:020d:0000:0000:008a:0a5b"),
"compressed in file matches expanded in request");
}
// 3. Windows CRLF line endings (\r\n) — the primary root cause.
{
IpTree tree;
std::stringstream ss;
ss << "2b00:8c00:4000:020d:0000:0000:008a:0a5b\r\n";
ss << "::1\r\n";
ok = tree.addFromBuffer(&ss, &error);
check(ok, "load CRLF file without error");
check(tree.contains("2b00:8c00:4000:20d::8a:a5b"),
"CRLF file: expanded entry matches compressed lookup");
check(tree.contains("::1"),
"CRLF file: ::1 matches");
}
// 4. Trailing spaces after address.
{
IpTree tree;
std::stringstream ss;
ss << "2b00:8c00:4000:020d:0000:0000:008a:0a5b \n";
ok = tree.addFromBuffer(&ss, &error);
check(ok, "load line with trailing spaces without error");
check(tree.contains("2b00:8c00:4000:20d::8a:a5b"),
"trailing-space line matches lookup");
}
// 5. Comment lines and inline comments.
{
IpTree tree;
std::stringstream ss;
ss << "# This is a comment\n";
ss << "::1 # loopback\n";
ss << "\n";
ss << "\n";
ok = tree.addFromBuffer(&ss, &error);
check(ok, "load file with comments and blank lines without error");
check(tree.contains("::1"),
"inline comment: ::1 matches");
check(!tree.contains("10.0.0.1"),
"comment-only entry does not add anything");
}
// 6. CIDR IPv6.
{
IpTree tree;
std::stringstream ss;
ss << "2b00:8c00:4000:020d::/64\n";
ok = tree.addFromBuffer(&ss, &error);
check(ok, "load IPv6 CIDR without error");
check(tree.contains("2b00:8c00:4000:020d::1"),
"IPv6 CIDR: host in subnet matches");
check(!tree.contains("2b00:8c00:4001::1"),
"IPv6 CIDR: host outside subnet does not match");
}
// 7. CIDR IPv4.
{
IpTree tree;
std::stringstream ss;
ss << "192.168.1.0/24\n";
ok = tree.addFromBuffer(&ss, &error);
check(ok, "load IPv4 CIDR without error");
check(tree.contains("192.168.1.100"),
"IPv4 CIDR: host in subnet matches");
check(!tree.contains("192.168.2.1"),
"IPv4 CIDR: host outside subnet does not match");
}
// 8. ::1 — fully expanded in file, compressed in lookup.
{
IpTree tree;
std::stringstream ss;
ss << "0000:0000:0000:0000:0000:0000:0000:0001\n";
ok = tree.addFromBuffer(&ss, &error);
check(ok, "load fully-expanded ::1 without error");
check(tree.contains("::1"),
"fully-expanded ::1 in file matches compressed ::1 lookup");
}
// 9. IPv4-mapped IPv6.
{
IpTree tree;
std::stringstream ss;
ss << "::ffff:192.168.1.1\n";
ok = tree.addFromBuffer(&ss, &error);
check(ok, "load IPv4-mapped IPv6 without error");
check(tree.contains("::ffff:192.168.1.1"),
"IPv4-mapped IPv6: exact match");
}
// 10. Uppercase hex digits in IPv6.
{
IpTree tree;
std::stringstream ss;
ss << "2B00:8C00:4000:020D:0000:0000:008A:0A5B\n";
ok = tree.addFromBuffer(&ss, &error);
check(ok, "load uppercase IPv6 without error");
check(tree.contains("2b00:8c00:4000:20d::8a:a5b"),
"uppercase in file matches lowercase compressed lookup");
}
// 11. Realistic CRLF whitelist with comments, blank lines, mixed address// types — mirrors a real-world deployment scenario.
{
IpTree tree;
std::stringstream ss;
ss << "# Whitelist\r\n";
ss << "2b00:8c00:4000:020d:0000:0000:008a:0a5b\r\n";
ss << "2b00:8c00:4000:020d:0000:0000:008a:0a5c\r\n";
ss << "\r\n";
ss << "127.0.0.1\r\n";
ok = tree.addFromBuffer(&ss, &error);
check(ok, "load realistic CRLF whitelist without error");
check(tree.contains("2b00:8c00:4000:20d::8a:a5b"),
"realistic file: first IPv6 matches");
check(tree.contains("2b00:8c00:4000:20d::8a:a5c"),
"realistic file: second IPv6 matches");
check(tree.contains("127.0.0.1"),
"realistic file: IPv4 matches");
check(!tree.contains("10.0.0.1"),
"realistic file: unlisted address does not match");
}
std::cout << "\nAll regression tests passed.\n";
return0;
}
Test coverage matrix
Case
File entry
Lookup value
Expected
Reported bug
2b00:...:020d:0000:...:0a5b (expanded)
2b00:...:20d::8a:a5b (compressed)
match
Reverse
2b00:...:20d::8a:a5b (compressed)
2b00:...:020d:0000:...:0a5b (expanded)
match
CRLF endings
...0a5b\r
compressed
match
Trailing spaces
...0a5b
compressed
match
Inline comment
::1 # note
::1
match
Comment-only line
# comment
any
no entry added
Blank line
/ \r\n
any
skipped, no error
IPv6 CIDR
2b00::.../64
host in subnet
match
IPv4 CIDR
192.168.1.0/24
192.168.1.100
match
Loopback expanded
0000:...:0001
::1
match
IPv4-mapped IPv6
::ffff:192.168.1.1
same
match
Uppercase hex
2B00:8C00:...
lowercase compressed
match
Unlisted address
—
10.0.0.1
no match
9. Performance Impact
Load path (one-time initialization)
addFromBuffer is called once at rule-set load time, not per request. The three erase() calls added per line each run in O(L) where L is the line length (≤ ~50 characters for IP list lines). This is dominated by the subsequent inet_pton call and radix tree insertion (O(128) bit-steps each); the trim cost is immeasurable in practice.
erase() never calls the allocator. The std::string line buffer allocated by std::getline is reused across all loop iterations. Net additional memory pressure per file load: zero.
Query path (runtime, per request)
IpTree::contains → tree_contains_ip → inet_pton → CPTIpMatch. None of these functions are touched by this patch. Runtime query performance is identical to before.
changed the title [-]ModSecurity: Fix Failing to Match IPv6 Addresses@ipMatchFromFile[/-][+]Fix Failing to Match IPv6 Addresses@ipMatchFromFile[/+]on Jun 27, 2026
ISSUE: When we whitelist an IPv6 address( in whitelist file the address is expanded), if a request then comes from a non expanded IPV6 address, it is not whit list it and mod_security blocks it.
could you attach a file or a few lines from a file at least? I try to check the issue.
Is this a known issue that is fixed in alter versions?
And please clarify what version you use exactly.
We don't have any logs for this since it is happening in a customer environment and we dont have many IPV6 test labs.
It's no problem, but please clarify the version and show some lines from the file.
/* * ModSecurity, http://www.modsecurity.org/ * Copyright (c) 2015 - 2024 Trustwave Holdings, Inc. (http://www.trustwave.com/) * * ip_tree.cc — C++ wrapper around msc_tree (unchanged from the CRLF fix). * postOrderTraversal is a no-op: memory is now managed by TreeRoot's * destructor (std::vector RAII), so the old manual tree walk is not needed.*/
#include"src/utils/ip_tree.h"
#ifndef WIN32
# include<sys/socket.h>
# include<sys/types.h>
# include<netinet/in.h>
# include<arpa/inet.h>
#else
# include<WinSock2.h>
#endif
#include<string>
#include<fstream>
#include<sstream>
#include"src/utils/geo_lookup.h"
#include"src/utils/https_client.h"namespacemodsecurity {
namespaceUtils {
/* postOrderTraversal: was needed to walk and free the old radix tree nodes. The new implementation stores data in std::vector inside TreeRoot, which is freed automatically by destroy_radix_tree() in ~IpTree(). This function is kept in the public interface for ABI compatibility but has no work to do. */voidIpTree::postOrderTraversal(TreeNode * /*node*/) {}
IpTree::IpTree() {
create_radix_tree(&m_tree);
}
IpTree::~IpTree() {
/* destroy_radix_tree() is used instead of `delete m_tree` so that ip_tree.cc does not need to see TreeRoot's full definition. msc_tree.h only forward-declares TreeRoot; a raw `delete` on an incomplete type is undefined behaviour (and triggers -Wdelete-incomplete with GCC). destroy_radix_tree() is defined in msc_tree.cc where the full definition is visible. */destroy_radix_tree(m_tree);
m_tree = nullptr;
}
boolIpTree::addFromBuffer(std::istream *ss, std::string *error) {
for (std::string line; std::getline(*ss, line); ) {
/* Strip inline comment. erase() shrinks in-place; no allocation. */auto comment = line.find('#');
if (comment != std::string::npos) {
line.erase(comment);
}
/* Strip trailing whitespace including \r from Windows CRLF files. */auto end = line.find_last_not_of("\t\r\n");
if (end == std::string::npos) {
continue; /* blank or comment-only line */
}
line.erase(end + 1);
/* Strip leading whitespace. */auto start = line.find_first_not_of("\t\r\n");
if (start != 0 && start != std::string::npos) {
line.erase(0, start);
}
int res = add_ip_from_param(line.c_str(), &m_tree);
if (res != 0) {
if (error != nullptr) {
error->assign("Failed to parse and add IP: " + line);
}
returnfalse;
}
}
returntrue;
}
boolIpTree::addFromBuffer(const std::string &buffer, std::string *error) {
std::stringstream ss;
ss << buffer;
returnaddFromBuffer(&ss, error);
}
boolIpTree::addFromFile(const std::string &file, std::string *error) {
std::ifstream myfile(file, std::ios::in);
if (!myfile.is_open()) {
error->assign("Failed to open file: " + file);
returnfalse;
}
returnaddFromBuffer(&myfile, error);
}
boolIpTree::addFromUrl(const std::string &url, std::string *error) {
HttpsClient c;
bool ret = c.download(url);
if (!ret) {
error->assign(c.error);
} else {
ret = addFromBuffer(c.content, error);
}
return ret;
}
boolIpTree::contains(const std::string &ip) {
int res = tree_contains_ip(m_tree, ip.c_str());
return res > 0;
}
} // namespace Utils
} // namespace modsecurity
msc_tree.h
/* * ModSecurity, http://www.modsecurity.org/ * Copyright (c) 2015 - 2024 Trustwave Holdings, Inc. (http://www.trustwave.com/) * * You may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Replacement for msc_tree.{h,cc}. * * The original radix-tree implementation had three structural bugs: * 1. InsertNetmask: malloc without copying the previous netmasks array, * silently losing all prior CIDR entries on every reallocation. * 2. CPTAddElement (found!=0 branch): same malloc-without-copy pattern. * 3. CPTFindElementIPNetblock: destructively masked ipdata[] in-place, * corrupting the caller's buffer and every subsequent recursive lookup. * * This replacement uses a sorted interval vector (one per address family). * Each CIDR prefix is expanded to a [lo, hi] closed integer interval and * stored in a flat std::vector kept sorted by lo. Lookup is std::lower_bound, * O(log n). Build is O(n log n). Memory is 32 bytes per entry. The * implementation is ~150 lines of standard C++17 with no new dependencies. * * Public C API (extern "C") is kept identical to msc_tree.h so ip_tree.cc * requires zero changes.*/
#ifndef SRC_UTILS_MSC_TREE_H_
#defineSRC_UTILS_MSC_TREE_H_/* ── legacy type aliases kept for ip_tree.cc ─────────────────────────────── *//* ip_tree.cc only uses TreeRoot* (opaque) and calls the five C functions below. We keep the name but redefine the struct internally. */
#defineIPV4_TREE0x1
#defineIPV6_TREE0x2
#defineIPV4_LEN0x20
#defineIPV6_LEN0x80
#defineNETMASK_2560x100
#defineNETMASK_1280x80
#defineNETMASK_640x40
#defineNETMASK_320x20
#defineNETMASK_160x10
#defineNETMASK_80x8
#defineNETMASK_40x4
#defineNETMASK_20x2
#defineFALSE0
#defineTRUE1/* Opaque handle used by ip_tree.cc */structTreeRoot;
/* Legacy node type referenced only in IpTree::postOrderTraversal. That function now does nothing (memory is owned by TreeRoot internals), but the signature must compile. We provide a minimal stub. */structTreeNode { int _unused; };
extern"C" {
unsignedcharis_netmask_v4(char *ip_strv4);
unsignedcharis_netmask_v6(char *ip_strv6);
/* IMPORTANT: all entries must be added (via add_ip_from_param / ip_tree_from_param) before the first call to tree_contains_ip() on a given tree. The interval vectors are sorted and merged lazily, exactly once, on first query (std::call_once in msc_tree.cc). Entries added after that first query are appended unsorted and will not be found reliably, and can even break lookups for entries added before the first query. This matches how IpMatch/IpMatchFromFile use the tree (all inserts happen in init(), all queries happen later in evaluate()), but any other caller must preserve that ordering. */inttree_contains_ip(TreeRoot *rtree, constchar *value);
intadd_ip_from_param(constchar *param, TreeRoot **rtree);
intip_tree_from_param(constchar *param, TreeRoot **rtree);
intcreate_radix_tree(TreeRoot **rtree);
/* Destroy a tree created by create_radix_tree. Caller must set the pointer to nullptr afterwards. Using this instead of a raw `delete` keeps ip_tree.cc free of TreeRoot's full definition, which is an implementation detail of msc_tree.cc. */voiddestroy_radix_tree(TreeRoot *rtree);
} /* extern "C" */
#endif/* SRC_UTILS_MSC_TREE_H_ */
msc_tree.cc
/* * ModSecurity, http://www.modsecurity.org/ * Copyright (c) 2015 - 2026 Trustwave Holdings, Inc. (http://www.trustwave.com/) * * You may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Replacement implementation for msc_tree.cc. * See msc_tree.h for the full rationale. * * Design * ────── * Each CIDR entry (or single host = CIDR/32 or /128) is converted to a * closed integer interval [lo, hi] and stored in a flat sorted std::vector. * IPv4 uses uint32_t; IPv6 uses __uint128_t (supported on all GCC/Clang * targets that ModSecurity already builds on; no new dependency). * * Insert: find position with lower_bound, O(n) shift (build is one-time). * Lookup: upper_bound + backward scan, O(log n + k) where k is the number * of intervals sharing the same lo (k=1 for non-overlapping sets). * * Overlapping CIDR prefixes (e.g. 10/8 and 10.0/16 and 10.0.0/24 on the * same tree) are handled correctly by sorting equal-lo intervals by hi DESC * (wider first) and scanning backward past all intervals whose lo <= query. * * Memory: IPv4: 8 bytes/entry IPv6: 32 bytes/entry*/
#ifdef MODSECURITY_BUILD
# include"src/utils/msc_tree.h"
#else/* standalone / test build — header provided via -include flag */
#endif
#include<cstdint>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<new>
#include<mutex>
#ifndef WIN32
# include<sys/socket.h>
# include<netinet/in.h>
# include<arpa/inet.h>
#else
# include"src/compat/msvc.h"
# include<WinSock2.h>
# include<WS2tcpip.h>/* MSVC has no strtok_r (POSIX-only). Its strtok_s takes the same (str, delim, &saveptr) signature, so it's a drop-in replacement. */
# definestrtok_r strtok_s
/* MSVC provides strdup as the underscored _strdup (same signature). */
# definestrdup _strdup
#endif/* ── Integer Address Types & MSVC Compatibility ────────────────────────── */usingu32 = uint32_t;
#if defined(_MSC_VER) && !defined(__clang__)
// Custom 128-bit integer structure for MSVC compilationstructu128 {
uint64_t high;
uint64_t low;
u128() : high(0), low(0) {}
u128(uint64_t val) : high(0), low(val) {}
u128(int val) : high(0), low(static_cast<uint64_t>(val)) {}
u128(uint64_t h, uint64_t l) : high(h), low(l) {}
u128operator<<(int shift) const {
if (shift <= 0) return *this;
if (shift >= 128) returnu128(0, 0);
if (shift >= 64) returnu128(low << (shift - 64), 0);
// shift in [1, 63] range: safe shift, (64 - shift) is also in [1, 63] - no UBreturnu128((high << shift) | (low >> (64 - shift)), low << shift);
}
u128operator|(uint64_t val) const {
returnu128(high, low | val);
}
u128operator|(constu128& o) const {
returnu128(high | o.high, low | o.low);
}
u128operator&(constu128& o) const {
returnu128(high & o.high, low & o.low);
}
u128operator~() const {
returnu128(~high, ~low);
}
u128operator+(uint64_t val) const {
uint64_t new_low = low + val;
uint64_t new_high = high + (new_low < low ? 1 : 0);
returnu128(new_high, new_low);
}
booloperator<(constu128& o) const {
return high < o.high || (high == o.high && low < o.low);
}
booloperator<=(constu128& o) const {
return high < o.high || (high == o.high && low <= o.low);
}
booloperator>(constu128& o) const {
return high > o.high || (high == o.high && low > o.low);
}
booloperator>=(constu128& o) const {
return high > o.high || (high == o.high && low >= o.low);
}
booloperator==(constu128& o) const {
return high == o.high && low == o.low;
}
booloperator!=(constu128& o) const {
return !(*this == o);
}
};
#elseusingu128 = __uint128_t;
#endif/* ── Interval Definitions ───────────────────────────────────────────────── */structIv4 { u32 lo, hi; };
structIv6 { u128 lo, hi; };
structTreeRoot {
std::vector<Iv4> v4;
std::vector<Iv6> v6;
std::once_flag once; // Thread-safe trigger for lazy normalization on first query
};
/* ── IP Address Parsers ────────────────────────────────────────────────── */staticboolparse4(constchar *s, u32 *out) {
structin_addr a;
if (inet_pton(AF_INET, s, &a) != 1) returnfalse;
*out = ntohl(a.s_addr);
returntrue;
}
staticboolparse6(constchar *s, u128 *out) {
structin6_addr a;
if (inet_pton(AF_INET6, s, &a) != 1) returnfalse;
u128 v = 0;
for (int i = 0; i < 16; i++) {
v = (v << 8) | static_cast<uint64_t>(a.s6_addr[i]);
}
*out = v;
returntrue;
}
/* ── Interval Merging Algorithms ────────────────────────────────────────── */staticvoidcompress4(std::vector<Iv4> &vec) {
if (vec.size() < 2) return;
// Sort by lo ascending, and by hi descending if lo is equal (wider intervals first)std::sort(vec.begin(), vec.end(), [](const Iv4 &a, const Iv4 &b) {
return a.lo < b.lo || (a.lo == b.lo && b.hi < a.hi);
});
size_t write_idx = 0;
for (size_t i = 1; i < vec.size(); ++i) {
Iv4 &curr = vec[write_idx];
Iv4 &next = vec[i];
if (next.lo <= curr.hi) {
// Overlapping or nested intervals -> merge directlyif (curr.hi < next.hi) {
curr.hi = next.hi;
}
} elseif (curr.hi != ~static_cast<u32>(0) && next.lo == curr.hi + 1) {
// Adjacent intervals without overflow risk (e.g., 10.0.0.1 and 10.0.0.2) -> merge
curr.hi = next.hi;
} else {
write_idx++;
vec[write_idx] = next;
}
}
vec.resize(write_idx + 1);
}
staticvoidcompress6(std::vector<Iv6> &vec) {
if (vec.size() < 2) return;
// Sort by lo ascending, and by hi descending if lo is equalstd::sort(vec.begin(), vec.end(), [](const Iv6 &a, const Iv6 &b) {
return a.lo < b.lo || (a.lo == b.lo && b.hi < a.hi);
});
size_t write_idx = 0;
for (size_t i = 1; i < vec.size(); ++i) {
Iv6 &curr = vec[write_idx];
Iv6 &next = vec[i];
if (next.lo <= curr.hi) {
// Overlapping or nested intervals -> merge directlyif (curr.hi < next.hi) {
curr.hi = next.hi;
}
} elseif (curr.hi != ~u128(0) && next.lo == curr.hi + 1) {
// Adjacent intervals without overflow risk -> merge
curr.hi = next.hi;
} else {
write_idx++;
vec[write_idx] = next;
}
}
vec.resize(write_idx + 1);
}
/* ── Fast Appends ───────────────────────────────────────────────────────── */staticvoidinsert4(std::vector<Iv4> &vec, u32 lo, u32 hi) {
vec.push_back(Iv4{lo, hi});
}
staticvoidinsert6(std::vector<Iv6> &vec, u128 lo, u128 hi) {
vec.push_back(Iv6{lo, hi});
}
/* ── Parse and Load Single Rule ─────────────────────────────────────────── */staticbooladd_entry(TreeRoot *root, constchar *entry) {
char buf[128];
constchar *slash = strchr(entry, '/');
int prefix_len = -1;
if (slash != nullptr) {
size_t host_len = static_cast<size_t>(slash - entry);
if (host_len >= sizeof(buf)) returnfalse;
memcpy(buf, entry, host_len);
buf[host_len] = '\0';
/* atoi() returns 0 for non-numeric input (e.g. "10.0.0.1/xx"), which would silently become a /0 "match everything" rule. Use strtol() and verify the whole suffix was consumed. */char *endptr = nullptr;
long parsed = strtol(slash + 1, &endptr, 10);
if (*endptr != '\0' || endptr == slash + 1) returnfalse;
if (parsed < 0 || parsed > 128) returnfalse;
prefix_len = static_cast<int>(parsed);
} else {
if (strlen(entry) >= sizeof(buf)) returnfalse;
strcpy(buf, entry);
}
bool is_v6 = (strchr(buf, ':') != nullptr);
if (!is_v6) {
if (prefix_len < 0) prefix_len = 32;
if (prefix_len < 0 || prefix_len > 32) returnfalse;
u32 host;
if (!parse4(buf, &host)) returnfalse;
u32 mask = (prefix_len == 0) ? 0u : (~0u << (32 - prefix_len));
insert4(root->v4, host & mask, (host & mask) | ~mask);
} else {
if (prefix_len < 0) prefix_len = 128;
if (prefix_len < 0 || prefix_len > 128) returnfalse;
u128 host;
if (!parse6(buf, &host)) returnfalse;
u128 mask = (prefix_len == 0)
? u128(0)
: (~u128(0) << (128 - prefix_len));
insert6(root->v6, host & mask, (host & mask) | ~mask);
}
returntrue;
}
/* ═══════════════════════════════════════════════════════════════════════════ Public C API Implementation (Extern "C") ═══════════════════════════════════════════════════════════════════════════ */extern"C" {
unsignedcharis_netmask_v4(char *ip_strv4) {
unsignedchar netmask_v4 = 32;
if (ip_strv4 == nullptr) return netmask_v4;
char *mask_str = strchr(ip_strv4, '/');
if (mask_str) {
*(mask_str++) = '\0';
if (strchr(mask_str, '.') != nullptr) return0;
char *endptr = nullptr;
long cidr = strtol(mask_str, &endptr, 10);
if (*endptr != '\0' || endptr == mask_str) return0;
if (cidr == 32) return32;
if (cidr < 0 || cidr > 32) return0;
netmask_v4 = static_cast<unsignedchar>(cidr);
}
return netmask_v4;
}
unsignedcharis_netmask_v6(char *ip_strv6) {
unsignedchar netmask_v6 = 128;
if (ip_strv6 == nullptr) return netmask_v6;
char *mask_str = strchr(ip_strv6, '/');
if (mask_str) {
*(mask_str++) = '\0';
if (strchr(mask_str, ':') != nullptr) return0;
char *endptr = nullptr;
long cidr = strtol(mask_str, &endptr, 10);
if (*endptr != '\0' || endptr == mask_str) return0;
if (cidr < 0 || cidr > 128) return0;
netmask_v6 = static_cast<unsignedchar>(cidr);
}
return netmask_v6;
}
intcreate_radix_tree(TreeRoot **rtree) {
*rtree = new (std::nothrow) TreeRoot();
return (*rtree == nullptr) ? -1 : 0;
}
intadd_ip_from_param(constchar *param, TreeRoot **rtree) {
if (!param || !rtree || !*rtree) return -1;
char *copy = strdup(param);
if (!copy) return -1;
char *saved = nullptr;
char *tok = strtok_r(copy, ",", &saved);
while (tok != nullptr) {
while (*tok == '' || *tok == '\t') ++tok;
if (*tok != '\0') {
if (!add_entry(*rtree, tok)) {
free(copy);
return -1;
}
}
tok = strtok_r(nullptr, ",", &saved);
}
free(copy);
return0;
}
intip_tree_from_param(constchar *param, TreeRoot **rtree) {
if (create_radix_tree(rtree) != 0) return -1;
returnadd_ip_from_param(param, rtree);
}
inttree_contains_ip(TreeRoot *rtree, constchar *value) {
if (!rtree || !value) return0;
// Trigger thread-safe lazy interval merging on first querystd::call_once(rtree->once, [rtree]() {
compress4(rtree->v4);
compress6(rtree->v6);
});
if (strchr(value, ':') == nullptr) {
u32 addr;
if (!parse4(value, &addr)) return -1;
constauto &vec = rtree->v4;
if (vec.empty()) return0;
auto it = std::upper_bound(vec.begin(), vec.end(), addr,
[](u32 v, const Iv4 &iv) { return v < iv.lo; });
if (it == vec.begin()) return0;
--it;
return (addr >= it->lo && addr <= it->hi) ? 1 : 0;
} else {
u128 addr;
if (!parse6(value, &addr)) return -1;
constauto &vec = rtree->v6;
if (vec.empty()) return0;
auto it = std::upper_bound(vec.begin(), vec.end(), addr,
[](u128 v, const Iv6 &iv) { return v < iv.lo; });
if (it == vec.begin()) return0;
--it;
return (addr >= it->lo && addr <= it->hi) ? 1 : 0;
}
}
voiddestroy_radix_tree(TreeRoot *rtree) {
delete rtree;
}
} /* extern "C" */
ISSUE:
When we whitelist an IPv6 address( in whitelist file the address is expanded), if a request then comes from a non expanded IPV6 address, it is not whit list it and mod_security blocks it.
so this is the content, and these are the expanded IPv6 addresses.
May I ask you what does it mean "a request then comes from a non expanded IPV6 address"?
ISSUE:
When we whitelist an IPv6 address( in whitelist file the address is expanded), if a request then comes from a non expanded IPV6 address, it is not whit list it and mod_security blocks it.
so this is the content, and these are the expanded IPv6 addresses.
May I ask you what does it mean "a request then comes from a non expanded IPV6 address"?
Revisiting this one. This duplicates #2192 verbatim, and the investigation it triggered produced the real finding in #3588 (a bug in the radix tree's netmask handling). Let's close this one and keep #3588.
3.xRelated to ModSecurity version 3.xduplicateOps. Somebody else already hit that bumpneeds decisionTriage done; a maintainer needs to make the final call
Activity
JIFVGWHvAseSovQ commentedon Jun 27, 2026
Component:
src/utils/ip_tree.cc—IpTree::addFromBuffer()Affected operators:
@ipMatchFromFile,@ipMatchFSeverity: High — whitelist rules built on
@ipMatchFromFilesilently fail to match any address when the whitelist file contains Windows-style line endings or trailing whitespaceIntroduced: present in all audited versions of libmodsecurity3
Fixed in: this patch
Table of Contents
1. Background
Observed symptom
A SecRule using
@ipMatchFromFileagainstREMOTE_ADDRfails to fire even when the client address is present in the whitelist file:SecRule REMOTE_ADDR "@ipMatchFromFile /etc/opt/modsec/whitelist.txt" \ "id:250000004,phase:1,nolog,allow"whitelist.txt:Request
REMOTE_ADDR:2b00:8c00:4000:20d::8a:a5bResult: rule does not fire.
Confirming the operator itself works
This fires correctly. The radix tree, binary insertion, and lookup logic are all sound. The fault is exclusively in how lines are preprocessed before being fed to the parser.
Why expanded vs. compressed IPv6 is not the issue
Both
inet_pton(AF_INET6, "2b00:8c00:4000:020d:0000:0000:008a:0a5b", ...)andinet_pton(AF_INET6, "2b00:8c00:4000:20d::8a:a5b", ...)produce the identical 16-byte network-order binary2b008c004000020d00000000008a0a5b. The tree stores and matches on binary; different textual representations of the same address are handled correctly provided the string reachesinet_ptoncleanly.2. Call Chain Analysis
Load path —
@ipMatchFromFile/@ipMatchFLoad path —
@ipMatch(works correctly; no file I/O)Runtime query path (shared by both operators)
Key files and their roles
src/operators/ip_match_from_file.ccIpTreesrc/operators/ip_match.ccevaluate(); inline param load viaaddFromBuffer(string&)src/operators/ip_match_f.hIpMatchF— alias forIpMatchFromFile, no extra logicsrc/utils/ip_tree.ccaddFromBufferreads lines and callsadd_ip_from_paramsrc/utils/ip_tree.hIpTreeclass declarationsrc/utils/msc_tree.ccadd_ip_from_param,TreeAddIP,tree_contains_ip, radix treesrc/utils/msc_tree.h3. Root Cause
The bug is in
IpTree::addFromBuffer(std::istream *ss, std::string *error)insrc/utils/ip_tree.cc.Defective code (before fix)
Exact failure chain
std::getlinestrips\nbut does not strip\r. On a whitelist file with Windows-style CRLF (\r\n) line endings — common when the file is created or edited on Windows — every line is passed toadd_ip_from_paramwith a trailing\r:Because
addFromBufferreturnsfalseon the very first line,IpMatchFromFile::initalso returnsfalse, the operator's internalIpTreeremains empty, and every subsequent@ipMatchFromFileevaluation returns false regardless of the client's IP address or its textual representation.Secondary trigger: trailing whitespace after comment stripping
The same failure occurs when a line contains a trailing space or tab after the address, which can appear naturally after comment removal:
Why
@ipMatchis unaffected@ipMatchsupplies its address list directly from the SecRule parameter string, which never contains\ror trailing whitespace. It callsaddFromBuffer(const std::string&), which wraps the string in astringstream— no file I/O, no\r.Summary of root causes
addFromBufferdoes not strip trailing\raddFromBufferdoes not strip trailing whitespace4. Fix
The fix is confined to
IpTree::addFromBuffer(std::istream*)insrc/utils/ip_tree.cc. No other files are modified. Public API, ABI, and all operator behavior for well-formed input are unchanged.Strategy
All three trim operations — comment stripping, trailing whitespace, leading whitespace — are performed in-place using
std::string::erase().erase()adjusts the string's internal length without touching the allocator, so no additional heap allocation occurs per line. Blank and comment-only lines are skipped silently.Design decisions
erase()throughout. All three trim steps mutate the existingstd::stringbuffer directly. No additional heap allocation occurs per line.find_*+eraseidiom.msc_tree.cc.add_ip_from_param,TreeAddIP,tree_contains_ip, and the radix tree are correct. The fix belongs at the I/O layer, not in the parser.addFromBuffer(const std::string&)andaddFromUrlare not changed. Both ultimately call the fixedaddFromBuffer(istream*), so they inherit the fix without modification.strtok_rreturning NULL for an empty string (which would silently succeed), but\r-only lines would not. Explicitcontinuemakes the intent unambiguous.5. Diff
6. Modified File
src/utils/ip_tree.cc(complete)7. Build Instructions
Standard autotools build (from repository root)
sh build.sh ./configure make -j$(nproc) sudo make installVerify only the changed translation unit compiles cleanly
g++ -std=c++14 -c src/utils/ip_tree.cc \ -I. -I./others \ $(pkg-config --cflags libxml-2.0 yajl) \ -Wall -Wextra \ -o /tmp/ip_tree.oExpected: zero errors, zero warnings introduced by the patch.
Build and run the full existing test suite
8. Regression Tests
The file
test_ip_tree_regression.ccexercises all cases relevant to this fix. It is written as a standalone program that links against the built library; no test framework is required.Build the test binary
Expected output:
Test source:
test_ip_tree_regression.ccTest coverage matrix
2b00:...:020d:0000:...:0a5b(expanded)2b00:...:20d::8a:a5b(compressed)2b00:...:20d::8a:a5b(compressed)2b00:...:020d:0000:...:0a5b(expanded)...0a5b\r...0a5b::1 # note::1# comment/\r\n2b00::.../64192.168.1.0/24192.168.1.1000000:...:0001::1::ffff:192.168.1.12B00:8C00:...10.0.0.19. Performance Impact
Load path (one-time initialization)
addFromBufferis called once at rule-set load time, not per request. The threeerase()calls added per line each run in O(L) where L is the line length (≤ ~50 characters for IP list lines). This is dominated by the subsequentinet_ptoncall and radix tree insertion (O(128) bit-steps each); the trim cost is immeasurable in practice.erase()never calls the allocator. Thestd::string linebuffer allocated bystd::getlineis reused across all loop iterations. Net additional memory pressure per file load: zero.Query path (runtime, per request)
IpTree::contains→tree_contains_ip→inet_pton→CPTIpMatch. None of these functions are touched by this patch. Runtime query performance is identical to before.Complexity summary
[-]ModSecurity: Fix Failing to Match IPv6 Addresses@ipMatchFromFile[/-][+]Fix Failing to Match IPv6 Addresses@ipMatchFromFile[/+]airween commentedon Jun 27, 2026
HI @JIFVGWHvAseSovQ,
thanks for this report.
It's a very old issue, now you reported the same problem, but:
you still mention version
2.7.3(and later sent a patch for libmodsecurity3).Sorry to say but it's very confusing.
could you attach a file or a few lines from a file at least? I try to check the issue.
And please clarify what version you use exactly.
It's no problem, but please clarify the version and show some lines from the file.
JIFVGWHvAseSovQ commentedon Jun 27, 2026
@airween
ModSecurity-nginx v1.0.4
libmodsecurity3 version 3.0.15
Regression Tests
ip_tree.cc
test_ip_tree_regression.cc
JIFVGWHvAseSovQ commentedon Jun 27, 2026
ip_tree.ccmsc_tree.hmsc_tree.ccairween commentedon Jun 27, 2026
thanks,
Ahm, I meant
these or this file(s).
I guess you suspect the issue is there.
JIFVGWHvAseSovQ commentedon Jun 27, 2026
cat /etc/opt/cpf/conf/modsecurity_whitelist
2b00:8c00:4000:020d:0000:0000:008a:0a5b
2b00:8c00:4000:020d:0000:0000:008a:0a5c
2b00:8c00:4000:020d:0000:0000:008a:0a57
airween commentedon Jun 27, 2026
@JIFVGWHvAseSovQ - thanks.
You wrote:
so this is the content, and these are the expanded IPv6 addresses.
May I ask you what does it mean "a request then comes from a non expanded IPV6 address"?
JIFVGWHvAseSovQ commentedon Jun 27, 2026
Request IPv6 (compressed): 2001:8a00:6000:13b0::b566:ffd1
whitelist IPv6 (expanded): 2001:8a00:6000:13b0:0000:0000:b566:ffd1
@ipMatch/@ipMatchFromFile— Bug Report & Fixfzipi commentedon Oct 12, 2026
Revisiting this one. This duplicates #2192 verbatim, and the investigation it triggered produced the real finding in #3588 (a bug in the radix tree's netmask handling). Let's close this one and keep #3588.
fzipi commentedon Dec 1, 2026
Closing as a duplicate of #3588, which has the root cause in the radix tree netmask handling and fixes in #3660 (v3) and #3671 (v2).