Skip to content

fix(streamdown-rn): optimize splitter and harden URL sanitization#26

Open
ronak-guliani wants to merge 1 commit intodarkresearch:mainfrom
ronak-guliani:fix/perf-dos-url-sanitize
Open

fix(streamdown-rn): optimize splitter and harden URL sanitization#26
ronak-guliani wants to merge 1 commit intodarkresearch:mainfrom
ronak-guliani:fix/perf-dos-url-sanitize

Conversation

@ronak-guliani
Copy link

Summary

Fixes two issues in streamdown-rn:

  1. Performance/DoS risk in splitter processing path.
  2. URL policy bypass for protocol-relative URLs and URL-like props.

What changed

  • Refactored splitter from per-character full rescans to incremental appended-content processing.
  • Added explicit close-index detection for code blocks and component blocks, with remainder processing in the same update.
  • Hardened URL sanitization:
    • Blocks protocol-relative (//...) and UNC-style (...) URLs.
    • Sanitizes URL-like prop keys even when values don’t match protocol regex.
  • Added regression tests for splitter boundary/chunk-size behavior and URL sanitization edge cases.

Verification

  • bun test (repo root): pass
  • bun run type-check (repo root): pass
  • bun run build (repo root): pass

Performance note

Quick local benchmark (production mode) improved from ~4000: 260ms / 8000: 953ms to ~4000: 1.82ms / 8000: 1.44ms for the audited splitter scenario.

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.

1 participant