Skip to content

fix(iis): strip IPv6 zone/scope id from client IP string - #3631

Merged
airween merged 2 commits into
owasp-modsecurity:v2/masterfrom
A13501350:fix/iis-ipv6-scope-id
Nov 29, 2026
Merged

airween merged 2 commits into
owasp-modsecurity:v2/masterfrom
A13501350:fix/iis-ipv6-scope-id

Conversation

@A13501350

Copy link
Copy Markdown

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

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.
@coderabbitai

coderabbitai Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e8724f3e-b0da-495f-9260-6b3011c50001

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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.h for strchr.
  • Strips %zone suffixes 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.

@airween airween added Platform - IIS 2.x Related to ModSecurity version 2.x labels Sep 17, 2026
@sonarqubecloud

sonarqubecloud Bot commented Oct 8, 2026

Copy link
Copy Markdown

@fzipi fzipi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

  1. (non-blocking) Error/audit logs will now show the address without the zone (fe80::1 instead of fe80::1%6). That's the right trade-off for rule matching, just mentioning it so it's a conscious choice.
  2. (non-blocking) #include <string.h> isn't strictly needed, but it's harmless and makes the strchr dependency explicit, so fine to keep.

LGTM. We'll squash on merge to drop the merge-from-base commit.

@airween

airween commented Nov 29, 2026

Copy link
Copy Markdown
Member

Thanks for the PR @A13501350 and for the review @fzipi - merging now.

@airween
airween merged commit 0245e18 into owasp-modsecurity:v2/master Nov 29, 2026
93 checks passed
@A13501350
A13501350 deleted the fix/iis-ipv6-scope-id branch November 30, 2026 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.x Related to ModSecurity version 2.x Platform - IIS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants