fix: escape bytes field default value in generated toObject (GHSA-66ff-xgx4-vchm)#2351
Closed
greymoth-jp wants to merge 1 commit into
Closed
Conversation
Member
|
Thanks, though there is an argument to make here about whether it makes sense to keep maintaining 6.x. It's very old, and no longer supported (see). Users should upgrade to 8.x. Leaving this open for a bit, though, just in case. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The 6.x line still generates
toObjectcode that writes a bytes field's default value into the generated function as code. A schema-controlled, non-string default for abytesfield reaches the generated conversion function unescaped, so a crafted descriptor can run arbitrary JavaScript (GHSA-66ff-xgx4-vchm / CVE-2026-44293).This was fixed on 7.x and 8.x in 75392ea, released in
protobufjs-v7.5.6andprotobufjs-v8.0.2, but the same change was not carried to the 6.11.x line. 6.11.x is still published as thelatest-6dist-tag (6.11.6, May 2026), and 6.11.6 only picked up the type-name filter from that batch, not this one.Root cause
In
converter.toObject, the bytes default was turned into a literal string"[" + slice(typeDefault).join(",") + "]"and emitted with%s, which is inserted into the generated function body as-is.field.jsonly converts a default to a buffer when it is a string, so a non-string default (for example an array supplied through a JSON descriptor) keeps its raw value, and the joined text can close the array literal and append statements.Fix
Mirror the 7.x/8.x change: keep the default as an array and emit it with
%jinstead of building the literal by hand and emitting it with%s.Reproduction (published-version layer)
Verification
Added a regression test in
tests/api_converter_bytes_default.js. Reverting only thesrc/converter.jschange makes that test fail (the injected code runs inside the generatedtoObject); with the change it passes. The full source suite is green (1248/1248). For ordinary bytes defaults the generated output is unchanged, since%jof a numeric byte array produces the same text the old code built by hand.Refs: GHSA-66ff-xgx4-vchm, CVE-2026-44293, 75392ea