Skip to content

Repeated headers cause problems in json audit logs #2777

Open

Description

@jbohanon

Describe the bug

Current implementation of json audit logs generates log entries with duplicated keys in the event of repeated headers in either the request or response. This is technically not invalid json per RFC 7159 Section 4, but most implementations silently drop all-but-first or all-but-last instances of duplicated keys. In some cases however, the behavior is undefined and an error is thrown. I found this issue in the nginx repo outlining a similar difficulty. The prevailing idea over there seemed to be to convert repeated header fields into a single array value containing all of the previously enumerated values. The HTTP specification states in RFC 9110 Section 5.2 that field values for repeated headers should be able to be concatenated delimited by commas. I think either of these are reasonable solutions with pros and cons...

Arrays
Pros:

  • Can easily handle different data types

Cons:

  • Less aligned with typical representations of multiple values for a single header

Comma-delimited concatenated strings
Pros:

  • Part of RFC spec for HTTP

Cons:

  • Really only applies to string values

To Reproduce

curl -H "test: value" -H "test: another-value" "https://<site-behind-modsec>"

Server (please complete the following information):

  • ModSecurity version (and connector): ModSecurity v3.0.4 with envoy connector v0.1.0
  • WebServer: envoy 1.19
  • OS (and distro): linux ubuntu

Rule Set (please complete the following information):

  • Running any public or commercial rule set? OWASP_CRS
  • What is the version number? 3.2.0

Activity

  1. martinhsv commented on Jul 26, 2022

    @martinhsv
    Contributor

    Hi @jbohanon ,

    Actually the issue that you found ( owasp-modsecurity/ModSecurity-nginx#230 ) is exactly the same issue. Or, more precisely, that other issue is describing two sub-issues, one of which is the json-formatting issue for duplicates.

    As you may gathered from my comments at owasp-modsecurity/ModSecurity-nginx#230 (comment) , I do prefer the array format as the solution.

  2. added
    3.x
    on Jan 26, 2024
  3. fzipi commented on Oct 12, 2026

    @fzipi
    Collaborator

    Revisiting this one. Confirmed in the JSON writer (src/transaction.cc): the request and response headers objects are emitted with one LOGFY_ADD per header value, so repeated headers produce duplicate keys in the same object. Emitting an array when a name repeats, as @martinhsv preferred, is a contained change in that loop (collect by name first, then write string or array). Marking as a bug.

  4. added
    bug
    on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.xbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions