security: sanitize schema strings in code generators#8998
Open
mohammadmseet-hue wants to merge 1 commit intogoogle:masterfrom
Open
security: sanitize schema strings in code generators#8998mohammadmseet-hue wants to merge 1 commit intogoogle:masterfrom
mohammadmseet-hue wants to merge 1 commit intogoogle:masterfrom
Conversation
…tion The .fbs parser processes escape sequences in string constants, but the C++, PHP, and Rust code generators concatenate the parsed (unescaped) values directly into generated source code. A crafted file_extension or native_include value containing newlines and quotes can inject arbitrary code into the generated output. This adds SanitizeStringForCodeGen() which escapes backslashes, quotes, newlines, and other control characters before embedding schema strings in generated source code. Applied to: - C++ generator: file_extension (line 705) and native_include (line 266) - PHP generator: file_extension (line 801) - Rust generator: file_extension (line 2660) Similar to the fix for CVE-2023-36665 in protobuf's ruby_package generator. The Python generator already hex-escapes file_identifier, confirming this risk was previously recognized.
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.
Summary
The C++, PHP, and Rust code generators concatenate parsed schema string values directly into generated source code without escaping. A crafted
.fbsschema with a maliciousfile_extensionornative_includevalue can inject arbitrary code into the generated output.This adds
SanitizeStringForCodeGen()to escape backslashes, quotes, newlines, and control characters before embedding schema strings. Applied to all affected code paths.Similar to the fix for CVE-2023-36665 in protobuf's ruby_package generator. The Python generator already hex-escapes
file_identifier, confirming this risk was previously recognized.Changes
include/flatbuffers/util.h— newSanitizeStringForCodeGen()utilitysrc/idl_gen_cpp.cpp— sanitizefile_extensionandnative_includesrc/idl_gen_php.cpp— sanitizefile_extensionsrc/idl_gen_rust.cpp— sanitizefile_extensionReproduction
Running
flatc --cppon this schema generates a header with a static initializer that executessystem("id")when compiled and run.