Repository navigation
fix(iis): strip IPv6 zone/scope id from client IP string - #3631
Conversation
Windows GetNameInfo() appends the zone/scope identifier (e.g. "%6") to link-local IPv6 addresses (fe80::/10) in their string form, because sin6_scope_id is the interface index for link-local addresses (per Microsoft docs: "fe80::208:74ff:feda:625c%5"). ModSecurity's IP-match parser rejects addresses containing a zone suffix, causing "IPmatch: bad IPv6 specification" and rule processing failures (e.g. id=905110) for clients connecting from link-local IPv6. Strip the "%<zone>" suffix from the textual IP passed to ModSecurity in GetIpAddr(). The binary address (sin6_addr) used for the actual socket is unaffected, and the zone id is irrelevant for IP matching.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🟢 Approval recommended
The reviewed change addresses the stated parsing issue without unresolved blocking concerns.
Pull request overview
Fixes IIS IPv6 link-local client IP parsing by removing Windows zone identifiers before ModSecurity matching.
Changes:
- Adds
string.hforstrchr. - Strips
%zonesuffixes from IPv6 address strings.
File summaries
| File | Description |
|---|---|
iis/mymodule.cpp |
Normalizes IPv6 client IP strings before ModSecurity processing. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
fzipi
left a comment
There was a problem hiding this comment.
Thanks @A13501350, nice catch!
I traced the flow by reading the code; it's IIS-only, so I can't run it here. GetIpAddr() is the only producer of client_ip/remote_ip on IIS. That string becomes msr->remote_addr and then REMOTE_ADDR. @ipMatch parses it with inet_pton(AF_INET6, ...) in tree_contains_ip(), which rejects the %<zone> suffix. That's exactly the bad IPv6 specification error from #3630. Cutting the string at the first % is safe:
- the buffer is NUL-terminated by
GetNameInfo, and the truncation happens in place; - the strip is limited to
AF_INET6; CopySockAddr()never carried the scope id anyway.
The IIS workflow builds green on this head.
- (non-blocking) Error/audit logs will now show the address without the zone (
fe80::1instead offe80::1%6). That's the right trade-off for rule matching, just mentioning it so it's a conscious choice. - (non-blocking)
#include <string.h>isn't strictly needed, but it's harmless and makes thestrchrdependency explicit, so fine to keep.
LGTM. We'll squash on merge to drop the merge-from-base commit.
|
Thanks for the PR @A13501350 and for the review @fzipi - merging now. |



Summary
Windows GetNameInfo() appends the zone/scope identifier (e.g. "%6") to
link-local IPv6 addresses (fe80::/10) in their string form, because
sin6_scope_id is the interface index for link-local addresses.
ModSecurity's IP-match parser rejects addresses containing a zone suffix,
causing "IPmatch: bad IPv6 specification" and rule processing failures
(e.g. id=905110) for clients connecting from link-local IPv6.
Root cause
iis/mymodule.cpp — GetIpAddr() builds the client IP string consumed as
REMOTE_ADDR / client_ip. The "%" suffix makes the address
unparseable by ModSecurity's IP matcher.
Fix
Strip the "%" suffix from the textual IP in GetIpAddr() for
AF_INET6. The binary address (sin6_addr) carried by CopySockAddr() is
unaffected, and the zone id is irrelevant for IP matching. Added
#include <string.h> for strchr().
Fixes #3630