]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MEDIUM: mjson: decode the escaped slash in strings
authorOlivier Houchard <ohouchard@haproxy.com>
Wed, 25 Nov 2026 15:28:48 +0000 (16:28 +0100)
committerOlivier Houchard <cognet@ci0.org>
Wed, 25 Nov 2026 15:22:07 +0000 (16:22 +0100)
RFC 8259 allows the slash to be escaped in JSON strings as "\/", and
some encoders emit it by default (e.g. PHP's json_encode()). But
mjson_unescape() does not know this escape and fails, so no value is
returned for such strings by json_query(), jwt_header_query() and
jwt_payload_query(), nor to the ACME client which extracts strings the
same way. This can be reproduced with req.body,json_query('$.url') on
{"url":"\/a\/b"}.

Let's add the slash to the escapes known by mjson_esc().

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

index c8dc61738e0a88b980f0489bbe716ffbc6f0c95c..a60386dd1db0339a61008222f3f9ba1814751b12 100644 (file)
@@ -27,7 +27,7 @@
 static double mystrtod(const char *str, int len, char **end);
 
 static int mjson_esc(int c, int esc) {
-  const char *p, *esc1 = "\b\f\n\r\t\\\"", *esc2 = "bfnrt\\\"";
+  const char *p, *esc1 = "\b\f\n\r\t\\\"/", *esc2 = "bfnrt\\\"/";
   for (p = esc ? esc1 : esc2; *p != '\0'; p++) {
     if (*p == c) return esc ? esc2[p - esc1] : esc1[p - esc2];
   }