Skip to content

Sanitize IDL text written into generated comments and strings - #240

Merged
gangatp merged 2 commits into
developfrom
fix/generated-comment-injection
Sep 30, 2026
Merged

gangatp merged 2 commits into
developfrom
fix/generated-comment-injection

Conversation

@martinweismann

@martinweismann martinweismann commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Summary

ACT copied several IDL values verbatim into generated source files. A crafted IDL could close the surrounding comment or string literal and inject code into the generated bindings and implementation stubs. This is a potential code injection vulnerability for anyone who generates code from an IDL they don't fully control.

Changes

  • License headers: the copyright attribute and the <license> lines are now sanitized for each header comment style before they are written:

    • C-style (/* */, used for C, C++, C#, Go, Node, Java and JavaScript):
      • */ and /* are broken up.
      • Java unicode escapes such as \u002a/ are neutralized.
      • A trailing backslash or ??/ trigraph is neutralized, so C/C++ line splicing can't assemble */ across lines.
    • Pascal ((* *)): *) and (* are broken up.
    • Python ('''): backslashes and single quotes are escaped.
    • CMake (#[[ ]]): ]] is broken up.
    • All styles: control characters are replaced with spaces.

    ACT logs a warning once per affected value. Existing IDLs keep working, and headers whose text needs no sanitizing are byte-for-byte unchanged.

  • Descriptions: method, class, function type, parameter, error, enum and enum option descriptions that could terminate the comment they are written into are now rejected. This covers */, /*, *), (*, Java unicode escapes, trailing backslashes and control characters.

    • The allowed character sets include * and /, so these sequences were previously accepted.
    • Parameter descriptions were never validated, because the method check tested the method description instead. Function type parameter, enum and enum option descriptions had no validation at all.
  • Escaping at write time: function type descriptions are escaped before being written into a Python string literal, and descriptions written into Javadoc comments are sanitized.

  • Tests: new unit tests in Source/languagewriter_test.go and Source/componentdefinition_test.go.

  • Example build image: Build/Dockerfile now pins emsdk to 4.0.21 instead of latest. The example build failed independently of this change: Emscripten 4.0.22 and later require Python 3.10, and the CentOS 8 image only provides Python 3.9.

Testing

  • GO111MODULE=off go test -vet=off . in Source passes. -vet=off is needed because go vet already fails on existing int-to-string conversions in componentdiff.go.
  • I regenerated all 22 example IDLs with the old and the new binary:
    • Each IDL succeeds or fails the same way with both.
    • All 407 generated files are identical apart from GUIDs that ACT randomizes on every run.
    • No example triggers a warning.
  • I also ran crafted IDLs through both binaries:
    • Old binary: code injected through the copyright, split license lines, method descriptions and enum descriptions compiles as real C++. The injected Python assignment is real code, and the Java header contains a raw \u002a/.
    • New binary: the header payloads are neutralized, the generated C++ headers compile cleanly with -Wall -Werror, and the Python bindings contain no injected code. The description payloads are rejected with a validation error.

Values from the IDL were copied verbatim into generated source files. A
crafted IDL could close the surrounding comment or string literal and
inject code into the generated bindings and implementation stubs.

- Sanitize the copyright and license lines for each license header
  comment style (C-style, Pascal, Python, CMake), including C/C++
  backslash line splicing and Java unicode escapes, and warn when a
  value is changed.
- Reject method, class, function type, parameter, error, enum and enum
  option descriptions that could terminate the comment they are written
  into. Parameter descriptions are now validated; the method check
  previously validated the method description instead.
- Escape function type descriptions written into Python string literals
  and sanitize descriptions written into Javadoc comments.
- Add unit tests for the sanitizer and the description validation.
@martinweismann
martinweismann changed the base branch from master to develop September 29, 2026 19:30
@martinweismann
martinweismann force-pushed the fix/generated-comment-injection branch from 12c06ea to bcc6fda Compare September 29, 2026 19:30
Emscripten 4.0.22 and later require Python 3.10, but the CentOS 8 image
only provides Python 3.9, so installing the latest emsdk fails.

Co-authored-by: Cursor <cursoragent@cursor.com>
@gangatp
gangatp self-requested a review September 30, 2026 07:25
@gangatp
gangatp merged commit 4d551b9 into develop Sep 30, 2026
19 checks passed
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.

2 participants