Skip to content

Conversation

@Ky0toFu
Copy link
Contributor

@Ky0toFu Ky0toFu commented Dec 3, 2025

Summary

  • Escapes the */ terminator in TypeScript doc comments before emitting them into /** ... */ JSDoc blocks.
  • Prevents schema doc_comment lines from closing the JSDoc block and injecting top‑level JavaScript into the generated module.

Root cause

  • src/idl_gen_ts.cpp::GenDocComment previously wrote " *" + line + "\n" directly into a JSDoc block without escaping */.
  • A crafted .fbs doc line such as */console.log('PWNED_TS_RCE_FROM_GENERATED_CODE')/* would:
    • close the JSDoc block (*/),
    • emit console.log(...) as top‑level JS that runs on import/bundling,
    • and reopen a block comment (/*) so the final */ from the generator still parses.

Fix

  • For each doc comment line in GenDocComment, copy it into a local safe string and replace all occurrences of */ with *\/ before writing it into the JSDoc block.
  • This keeps the emitted code as a standard /** ... */ JSDoc block (so IDE/tooling hover docs still work), but user‑controlled docs can no longer terminate the comment and inject code.

Notes

  • The original issue also proposed rendering docs as line comments in TypeScript (// ...) to make early termination impossible by construction.
  • Given that many IDEs and the TS language service rely on /** ... */ JSDoc for hover documentation and IntelliSense, this change implements the minimal, backwards‑compatible escape‑based fix first.

Fixes #8725.

@google-cla
Copy link

google-cla bot commented Dec 3, 2025

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.

@github-actions github-actions bot added c++ javascript typescript codegen Involving generating code from schema labels Dec 3, 2025
Copy link
Collaborator

@bjornharrtell bjornharrtell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks clean to me.

@bjornharrtell bjornharrtell enabled auto-merge (squash) December 3, 2025 12:21
@bjornharrtell bjornharrtell merged commit b39f79e into google:master Dec 3, 2025
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ codegen Involving generating code from schema javascript typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TS codegen] Escape JSDoc terminator in doc comments to prevent comment closure and import‑time code execution

3 participants