Repository navigation
Conversation
|
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
|
|
|
Hi @A13501350, thanks for this patch - if I'm right, this fixes a bug. Could you add a test case which shows the issue and the correct behavior? The test could be here, with a new target, for eg. |
|
Happy to add tests. However, |
fzipi
left a comment
There was a problem hiding this comment.
Thanks @A13501350, the change looks right to me.
I reviewed it by reading the code; I haven't built or run it. Windows CI is green.
- Switching both unknown-header loops to
apr_table_addnfixes the overwrite. The keys and values are already copied intor->pool, so the no-copy variant is fine. - Your Set-Cookie explanation matches what the reporter saw in #2991: both
Set-Cookieand a custom header only showed the last instance. - I checked the engine's single-value lookups (
apr_table_geton request/response headers). They only use known header names (Content-Type, Content-Length, Transfer-Encoding, Referer, User-Agent, …), which still go through_TRANSHEADER. Moving from "last wins" to "first wins" for unknown names doesn't change anything there. - Nice side effect on the request side: a client can no longer hide a value in an earlier duplicate custom header from
REQUEST_HEADERSinspection.
On tests: I agree with @airween that we want one. You're also right that tests/regression/target runs against Apache, which already keeps duplicates, so a test there would pass with or without this change. Once the iis/tests harness from #3613 lands, could you add a small FTW case? Something like two X-Test request headers (via encoded_request, since the header map can't hold duplicate names) and SecRule &REQUEST_HEADERS:X-Test "@eq 2" "id:...,phase:1,deny,status:403". I'm fine with that being a follow-up rather than blocking this.
|
Thanks for this, and sorry it has waited this long. Switching to Duplicates of known headers. @fzipi checked that the engine's single-value lookups ( Your commit message describes this for Most backends take the last copy of a duplicated Could you check on IIS what HTTP.SYS really does with a request that has two Not caused by this PR, just so we know what it does not fix:
|
|
One addition to my previous comment, for the test that will come after #3613: please make it check exact counts in both directions, not just "more than one", e.g. two Not for this PR: |
Unknown headers were copied into headers_in/headers_out with apr_table_setn(), so any duplicate entries in pUnknownHeaders overwrote the previous value and only the last survived. For example, on the response side (such as multiple Set-Cookie headers or custom headers), IIS/HTTP.SYS keeps one known-header value in KnownHeaders and places additional instances in pUnknownHeaders, so previously only the last value was visible and the KnownHeaders entry was clobbered. Switch both unknown-header loops to apr_table_addn() so every entry exposed in pUnknownHeaders is preserved on both request and response sides (note that on the request side, HTTP.SYS usually rejects or coalesces duplicate client headers before the module runs). Fixes owasp-modsecurity#2991
|
@airween Thanks for the thorough check. I tested duplicated request and response headers directly against IIS/HTTP.SYS on Request side (HTTP.SYS ->
So on the request side, Response side (ARR backend ->
|
a4df483 to
484e405
Compare
|
|
@airween @fzipi The
The incident has since been resolved, and the failed workflow needs to be re-run. |



Fixes #2991
Problem
On IIS, when multiple response headers share the same name (e.g.
Set-Cookie), ModSecurity only records the last one. Consequently, rules using&RESPONSE_HEADERS:/Set-Cookie/(count) orRESPONSE_HEADERS:Set-Cookienever match earlier values, and audit log part F collapses duplicates to a single entry. The same defect exists for request-side unknown headers.Root cause
In
iis/mymodule.cpp, bothOnSendResponseandOnBeginRequestcopy unknown headers into the corresponding APR table withapr_table_setn(), which replaces any existing entry with the same key. HTTP.SYS already exposes every duplicate as a separateHTTP_UNKNOWN_HEADERentry inpUnknownHeaders[], but each loop iteration overwrote the previous one, so only the last value survived.Fix
Switch both unknown-header loops from
apr_table_setn()toapr_table_addn(), preserving all values of identically-named headers. ModSecurity's collection generators already iterate over every table entry, so duplicate headers become fully visible to rules and the audit log.