Fix code injection via unescaped doc comments in Java/Kotlin/C# generators#9038
Open
YLChen-007 wants to merge 1 commit intogoogle:masterfrom
Open
Fix code injection via unescaped doc comments in Java/Kotlin/C# generators#9038YLChen-007 wants to merge 1 commit intogoogle:masterfrom
YLChen-007 wants to merge 1 commit intogoogle:masterfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Sanitize documentation comments by escaping the block comment closing sequence '*/' to '* /' before emitting them into generated source code. This prevents a malicious .fbs schema from injecting arbitrary code into generated Java, Kotlin, and C# files by prematurely terminating the Javadoc/KDoc block comment. The fix is applied to three locations: - GenComment() in code_generators.cpp (used by Java and C# generators) - GenerateComment() in idl_gen_kotlin.cpp - GenerateComment() in idl_gen_kotlin_kmp.cpp
7870fc8 to
7120d3c
Compare
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
Fix a Code Injection vulnerability (CWE-94 / CWE-116) in the
flatccompiler where documentation comments (///) from.fbsschema files were directly concatenated into generated source code without sanitizing the block comment closing sequence*/.Details
When generating Java, Kotlin, or C# source code,
flatcwraps documentation comments inside/** ... */Javadoc/KDoc-style block comments. An attacker who provides a malicious.fbsschema can include the*/character sequence in a documentation comment to prematurely close the generated comment block, thereby injecting arbitrary code into the generated source files.For example, this malicious schema:
Would generate a Java file where the payload escapes the comment block and becomes executable code.
Fix
This PR sanitizes the
*/sequence by replacing it with* /(inserting a space) before emitting it into the generated output. The fix is applied to all three locations where comment content is written:GenComment()insrc/code_generators.cpp— shared by the Java and C# generatorsGenerateComment()insrc/idl_gen_kotlin.cpp— Kotlin generatorGenerateComment()insrc/idl_gen_kotlin_kmp.cpp— Kotlin KMP generatorTesting
flattestspass:ALL TESTS PASSEDBefore the patch (malicious code escapes the comment):
After the patch (payload remains inside the comment):