Escape untrusted JavaScript literals - #622
Conversation
|
Warning Review limit reached
Next review available in: 59 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR hardens the JavaScript transpiler against code-injection by routing untrusted AST string values through a centralized JavaScript string-literal encoder and by escaping regex-literal delimiters/line separators in pattern text, with targeted regressions to prevent reintroducing vulnerable sinks.
Changes:
- Centralizes JS string emission via
js_string_literal(...)and applies it to multiple previously-interpolated string fields (headers, time formats, describe/test descriptions, type assertions, container metadata, map keys, and ordinary string literals). - Strengthens
regex_escape(...)to prevent closing out generated regex literals and to handle JS line separators safely. - Adds regression tests for adversarial header names/time formats and verifies describe/test descriptions are emitted as valid JS string literals.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/transpiler/javascript.rs |
Introduces js_string_literal and expands regex_escape to prevent JS literal/regex breakouts; updates transpiler emission sites to use the centralized encoder. |
tests/transpiler_test.rs |
Adds regressions ensuring untrusted header/time-format strings can’t escape generated JS and that describe/test descriptions are emitted as JS strings. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Superseded by #632, which preserves this security fix in the consolidated Rust-source hardening PR. The combined head is mergeable and all required CI checks are green. |
Summary
Security impact
Several AST string fields were interpolated directly into single-quoted generated JavaScript. A crafted, valid WFL source file could close those literals and inject JavaScript into transpiler output. Generated strings now use a centralized quoted encoder that escapes code boundaries, control characters, and line separators.
Validation
git diff --checknode --checkagainst representative generated header, time-format, and regex fragmentsProduction readiness