Skip to content

fix: safely quote injected object JSON#48

Merged
alexz-phantom merged 1 commit into
masterfrom
security/injected-object-json-escaping
Jul 23, 2026
Merged

fix: safely quote injected object JSON#48
alexz-phantom merged 1 commit into
masterfrom
security/injected-object-json-escaping

Conversation

@alexz-phantom

@alexz-phantom alexz-phantom commented Jul 23, 2026

Copy link
Copy Markdown

Quote injectedJavaScriptObject JSON as a JavaScript string on Android and Apple platforms.

  • Prevent template-literal interpolation from executing object data.
  • Preserve nested JSON, control characters, and Unicode line separators.
  • Add focused Android string-encoding coverage.

Tests: yarn lint, existing Jest suite, focused Java encoding harness.

Summary by CodeRabbit

  • Bug Fixes

    • Improved safety when injecting JavaScript objects into WebViews on Android and Apple platforms.
    • Preserved nested JSON, control characters, and Unicode line separators during injection.
    • Prevented injected content from being interpreted as executable template-literal code.
  • Tests

    • Added coverage for escaping, nested JSON, special characters, and null values.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: dcf38815-ccc5-4811-b666-afad3d5d77ae

📥 Commits

Reviewing files that changed from the base of the PR and between 413d5ea and a45290f.

📒 Files selected for processing (6)
  • .changeset/quote-injected-object-json.md
  • android/build.gradle
  • android/src/main/java/com/reactnativecommunity/webview/RNCJavaScriptString.java
  • android/src/main/java/com/reactnativecommunity/webview/RNCWebView.java
  • android/src/test/java/com/reactnativecommunity/webview/RNCJavaScriptStringTest.java
  • apple/RNCWebViewImpl.m

📝 Walkthrough

Walkthrough

The change adds platform-specific JavaScript string quoting for injectedJavaScriptObject on Android and Apple WebViews, replaces template-literal interpolation, adds Android escaping tests, and includes the Android JUnit test dependency.

Changes

Injected object quoting

Layer / File(s) Summary
Android JavaScript quoting
android/src/main/java/com/reactnativecommunity/webview/RNCJavaScriptString.java, android/src/main/java/com/reactnativecommunity/webview/RNCWebView.java, android/src/test/..., android/build.gradle
Adds JavaScript string escaping, uses it when generating injectedObjectJson, and tests nested JSON, control characters, line separators, injection characters, and null values.
Apple JavaScript quoting
apple/RNCWebViewImpl.m, .changeset/quote-injected-object-json.md
JSON-serializes and escapes injected strings before embedding them in the generated WKUserScript, with a patch changeset documenting the platform behavior.

Sequence Diagram(s)

sequenceDiagram
  participant NativeWebView
  participant StringQuoter
  participant JavaScriptBridge
  participant WebPage
  NativeWebView->>StringQuoter: quote injected object JSON
  StringQuoter-->>NativeWebView: escaped JavaScript string literal
  NativeWebView->>JavaScriptBridge: define injectedObjectJson()
  JavaScriptBridge->>WebPage: return quoted object JSON
Loading

Suggested reviewers: jamonholmgren

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: safely quoting injected object JSON to prevent template-literal injection.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch security/injected-object-json-escaping

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Checkov (3.3.8)
android/build.gradle

Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in
from checkov.main import Checkov
ModuleNotFoundError: No module named 'checkov'


Comment @coderabbitai help to get the list of available commands.

@alexz-phantom
alexz-phantom merged commit 4c3995f into master Jul 23, 2026
10 of 16 checks passed
@alexz-phantom
alexz-phantom deleted the security/injected-object-json-escaping branch July 23, 2026 03:55
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