]> git.kaiwu.me - haproxy.git/commit
BUG/MEDIUM: mjson: stop the lookup when the matched element ends
authorOlivier Houchard <ohouchard@haproxy.com>
Wed, 25 Nov 2026 14:53:23 +0000 (15:53 +0100)
committerOlivier Houchard <cognet@ci0.org>
Wed, 25 Nov 2026 14:53:20 +0000 (15:53 +0100)
commit24e1f81bee94de8bf6336f2d4b5fbc363d46d100
treec561f7c009befab96ac41e5425ebaf5265198873
parent6da41b95f41548e1e51a966374fb8827f340afac
BUG/MEDIUM: mjson: stop the lookup when the matched element ends

When a JSON path component matches, mjson_find() does not detect that
the matching element ends without containing the rest of the path, and
keeps matching the remaining components against what follows. A value
may then be returned for a path which does not exist:

  $.a[0].b on {"a":[{"x":1},{"b":"other"}]}     returns "other"
  $.a[0]   on {"a":[],"b":["other"]}            returns "other"
  $.a.b.c  on {"a":{"b":1},"x":[{"c":"evil"}]}  returns "evil"

This affects json_query(), jwt_header_query() and jwt_payload_query(),
and can be reproduced with req.body,json_query('$.a[0].b') and the first
document above.

Let's stop the lookup when a scalar matches a component while the path
is not finished, when a comma follows the matching element, and when
the container holding it is closed. Commas are also only counted as
array separators when an index is expected. The library fixed part of
this after it was imported, in its commit d2d9e4658 ("Fix #32 - fail
search if value not found in the requested array elem").

This exists since the library was imported in 2.4-dev17 by commit
41007a683 ("MINOR: sample: converter: Add mjson library."). It must be
backported to all supported versions.
src/mjson.c