Skip to content

fix(grounding): harden native sanitizer and address review nits - #473

Merged
equationalapplications merged 2 commits into
stagingfrom
fix/grounding-sanitizer-cleanup
Jun 25, 2026
Merged

equationalapplications merged 2 commits into
stagingfrom
fix/grounding-sanitizer-cleanup

Conversation

@equationalapplications

Copy link
Copy Markdown
Owner

Description

Defense-in-depth cleanup for grounding HTML rendering, addressing follow-up items from the PR #472 Copilot review. Hardens the native WebView sanitizer to match the web allowlist behavior, clarifies attribute allowlist logic, and removes an unnecessary wheel listener re-subscription on web.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • Test update
  • Build/CI update

Related Issue

Follow-up to PR #472 Copilot review feedback.

Changes Made

  • Strip <base> tags in the native regex sanitizer alongside <link> and <meta>
  • Sanitize img src on the native path using the same isSafeHttpUrl gate as anchor href
  • Extract shared stripUnsafeUrlAttribute helper for anchor and img URL attributes
  • Refactor isAllowedGroundingAttribute into explicit on* / aria-* / data-* branches
  • Change the web scrollport wheel listener effect dependency array from [contentWidth] to []
  • Add native sanitizer unit tests for embed tags, resource tags, base tags, and img src validation

Testing

Platforms Tested

  • iOS
  • Android
  • Web

Test Steps

  1. npm run typecheck
  2. npm run lint
  3. npm run test -- --testPathPattern='sanitizeGroundingHtml|groundingShadowContent'

Screenshots

N/A — sanitizer and event-listener changes only; no visible UI change expected.

Before

N/A

After

N/A

Checklist

  • My code follows the code style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Additional Notes

None of these changes address active critical vulnerabilities; they align native sanitization with the existing web allowlist and close out low-priority maintainability items from the prior review.

Made with Cursor

Strip base tags and unsafe img src on native, clarify attribute
allowlist logic, and stop re-attaching the web wheel listener on layout sync.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copilot AI review requested due to automatic review settings June 25, 2026 23:13
@coderabbitai

coderabbitai Bot commented Jun 25, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5bfa70e3-2ad0-440a-956f-99c9872a0f86

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR tightens defense-in-depth sanitization for grounding HTML rendering, aligning the native regex-based path more closely with the web allowlist sanitizer, and removes an unnecessary wheel-listener re-subscription on web.

Changes:

  • Extend native executable-markup stripping to remove <base> alongside <link>/<meta>.
  • Add native <img src> URL sanitization using the same isSafeHttpUrl gate as anchor href, factoring shared helper logic.
  • Refine the web allowlist attribute check readability and make the web scrollport wheel listener attach only once; add/extend native sanitizer unit tests.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/utils/sanitizeGroundingHtml.ts Expands native regex sanitizer to strip <base> and sanitize <img src>, extracting shared URL-attribute stripping helper.
src/utils/groundingShadowContent.ts Clarifies attribute allowlist branching (on* reject, aria-*/data-* allow).
src/utils/tests/sanitizeGroundingHtml.test.ts Adds tests for additional removed tags and img src URL validation.
src/components/GroundingHtml.web.tsx Removes unnecessary effect re-run by changing the wheel listener effect deps to [].

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/utils/sanitizeGroundingHtml.ts Outdated
Comment thread src/utils/sanitizeGroundingHtml.ts
Comment thread src/utils/__tests__/sanitizeGroundingHtml.test.ts
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 25, 2026
Anchor href/src patterns now require start-of-attrs or whitespace (avoiding
data-href/data-src false positives), support xlink:href, and use last-wins
semantics when duplicate URL attributes are present.

Co-authored-by: Cursor <cursoragent@cursor.com>
@equationalapplications

Copy link
Copy Markdown
Owner Author

/fix-pr follow-up

Commit: 4c0e2071

Review resolution

  • HREF_ATTR_RE / SRC_ATTR_RE word-boundary false positives — Fixed: anchored attribute names to (?:^|\s) instead of \b, added (?:xlink:)? for SVG anchor xlink:href, and made patterns global (gi). (files: src/utils/sanitizeGroundingHtml.ts)
  • stripUnsafeUrlAttribute first-match bypass — Fixed: collect all URL-attribute matches, apply last-wins semantics (HTML parser behavior), strip all occurrences when the effective URL is unsafe, collapse duplicates when safe, and preserve self-closing /> syntax on <img>. (files: src/utils/sanitizeGroundingHtml.ts)
  • Missing regression tests for edge cases — Fixed: added tests for data-href/data-src non-matching, duplicate href/src with unsafe/safe last values, self-closing img, and xlink:href. (files: src/utils/__tests__/sanitizeGroundingHtml.test.ts)

Verification

  • typecheck — pass (npm run typecheck)
  • lint — pass (npm run lint)
  • tests — pass (npm run test)

@equationalapplications
equationalapplications merged commit 5820325 into staging Jun 25, 2026
3 checks passed
@equationalapplications
equationalapplications deleted the fix/grounding-sanitizer-cleanup branch June 25, 2026 23:28
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