Skip to content

fix(deep-links): guard percent-decoding against malformed input - #1373

Merged
pedramamini merged 3 commits into
mainfrom
fix/1372-safe-decode-deep-link-urls
Aug 13, 2026
Merged

fix(deep-links): guard percent-decoding against malformed input#1373
pedramamini merged 3 commits into
mainfrom
fix/1372-safe-decode-deep-link-urls

Conversation

@pedramamini

@pedramamini pedramamini commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Closes #1372

What

All six decodeURIComponent calls in src/shared/deep-link-urls.ts now route through a shared safeDecodeURIComponent helper.

Why

Deep link input is user-supplied - a hand-typed maestro:// link, an OS protocol-handler payload, or a file path containing a literal %. Malformed percent encoding throws URIError. The parser's outer try/catch meant that error didn't escape the function, but it did drop the entire link (returning null) rather than degrading to the raw segment. So maestro://file/sess/report%20100%#L12 silently resolved to nothing.

Note on the issue premise

The issue says to use "the existing safeDecodeURIComponent helper from src/shared/stringUtils.ts". That helper did not exist on main - this PR adds it.

There was a broken local copy in src/renderer/components/AutoRun/AttachmentImage.tsx that called itself instead of decodeURIComponent, recursing until the stack overflowed while the bare catch swallowed the resulting RangeError - so it always returned the input undecoded, at the cost of thousands of stack frames per call. This PR deletes it and points the file at the shared helper.

Correction to an earlier revision of this description: that broken copy was NOT introduced by #1310. git blame dates it to 1a1d5cf46e (2026-03-31), four months earlier, and #1310 targeted rc, where AttachmentImage.tsx already imports the shared helper and has no local copy. The original attribution was wrong on both counts.

Changes

  • src/shared/stringUtils.ts - new safeDecodeURIComponent(value), decodes or returns the original value.
  • src/shared/deep-link-urls.ts - all six call sites use it. encodeURIComponent on the build side is untouched, so valid round-trips are unchanged.
  • src/renderer/components/AutoRun/AttachmentImage.tsx - deletes the self-recursive local copy, imports the shared one.

Tests

  • stringUtils.test.ts - valid decoding, malformed input (100%, %, %zz, %E0%A4%A, a Windows path), and pass-through cases.
  • deep-link-urls.test.ts - malformed session / tab / group / file segments now resolve to the raw segment, including the mixed case where one segment decodes and its sibling does not.

Verified the 3 new deep-link tests fail on main and pass here. npm run lint, eslint, prettier, and the full src/__tests__/shared + src/__tests__/renderer/components/AutoRun suites (1884 tests) all pass locally.

Summary by CodeRabbit

  • Bug Fixes

    • Improved deep-link handling for malformed percent-encoded values.
    • Preserved affected link segments while continuing to parse valid session, tab, group, and file information.
    • Maintained correct line-fragment handling and independent decoding of valid segments.
    • Attachment image links now handle malformed encoding without disrupting display.
  • Tests

    • Added coverage for safe decoding, malformed encoding, unchanged plain-text values, and valid link parsing.

Deep link URLs are user-supplied: they can arrive from a hand-typed
maestro:// link, an OS protocol handler, or a file path containing a
literal '%'. All six decodeURIComponent calls in deep-link-urls.ts were
unguarded, so malformed percent encoding threw URIError and the outer
catch dropped the entire link (returning null) instead of degrading to
the raw segment.

Adds a shared safeDecodeURIComponent to src/shared/stringUtils.ts and
routes all six call sites through it.

Also fixes AttachmentImage.tsx, which declared a local
safeDecodeURIComponent that called *itself* instead of
decodeURIComponent. Every invocation recursed until the stack blew, and
the try/catch swallowed the RangeError - so image srcs were never
actually decoded. It now imports the shared helper.

Closes #1372
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b2deea87-4354-4576-ac64-712da31d1c08

📥 Commits

Reviewing files that changed from the base of the PR and between 8f52ade and 6624928.

📒 Files selected for processing (5)
  • src/__tests__/shared/deep-link-urls.test.ts
  • src/__tests__/shared/stringUtils.test.ts
  • src/renderer/components/AutoRun/AttachmentImage.tsx
  • src/shared/deep-link-urls.ts
  • src/shared/stringUtils.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/tests/shared/deep-link-urls.test.ts
  • src/shared/deep-link-urls.ts
  • src/shared/stringUtils.ts
  • src/renderer/components/AutoRun/AttachmentImage.tsx
  • src/tests/shared/stringUtils.test.ts

📝 Walkthrough

Walkthrough

The change adds a shared safe URI decoder. Deep-link parsing and attachment image handling now use it. Tests cover valid decoding, malformed input preservation, and continued parsing of deep-link segments.

Changes

Safe URI decoding

Layer / File(s) Summary
Shared decoder and unit coverage
src/shared/stringUtils.ts, src/__tests__/shared/stringUtils.test.ts
Adds safeDecodeURIComponent, which preserves malformed input for URIError and rethrows other errors. Tests cover valid, malformed, empty, and unchanged values.
Consumer integration and deep-link coverage
src/shared/deep-link-urls.ts, src/renderer/components/AutoRun/AttachmentImage.tsx, src/__tests__/shared/deep-link-urls.test.ts
Applies safe decoding to deep-link identifiers, file paths, and attachment image values. Tests cover malformed segments, valid sibling segments, and line fragments.

Estimated code review effort: 2 (Simple) | ~10 minutes

Mergeability Score: ⚪ Minimal · up to 66249

The change safely handles malformed deep-link and attachment-path encoding while preserving valid decoding behavior; no actionable merge-blocking risk remains after normal checks and review.

Possibly related PRs

  • RunMaestro/Maestro#1310: Introduces the shared safeDecodeURIComponent usage pattern and updates AttachmentImage.tsx.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR replaces the six deep-link decoding paths, adds safe decoding behavior, and tests valid and malformed inputs required by issue #1372.
Out of Scope Changes check ✅ Passed The changes remain within the linked issue scope, including shared helper coverage and replacing the AttachmentImage local implementation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: protecting deep-link percent decoding from malformed input.
✨ 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 fix/1372-safe-decode-deep-link-urls

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.

❤️ Share

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

@greptile-apps

greptile-apps Bot commented Aug 11, 2026

Copy link
Copy Markdown

Greptile Summary

This PR centralizes guarded percent-decoding in a shared helper, uses it to preserve malformed deep-link segments, and replaces AttachmentImage’s recursive local implementation.

  • Adds safeDecodeURIComponent with coverage for valid, malformed, and unchanged input.
  • Routes all deep-link segment decoding through the helper.
  • Reuses the helper in AttachmentImage to restore decoding without recursive calls.
  • Adds malformed deep-link regression coverage.

Confidence Score: 4/5

The PR appears safe to merge; the only issue is the non-blocking omission of the new helper from the canonical shared-utilities guide.

The shared helper correctly catches malformed decoding, has no runtime dependencies, and is covered across direct and deep-link use cases; only repository-required utility documentation remains incomplete.

Files Needing Attention: src/shared/stringUtils.ts

Important Files Changed

Filename Overview
src/shared/stringUtils.ts Adds a correctly guarded shared decoding helper with focused tests, but the new canonical utility is missing from the required shared-utilities guide.
src/shared/deep-link-urls.ts Replaces throwing segment decoding with independent raw-value fallbacks while preserving valid decoding behavior.
src/renderer/components/AutoRun/AttachmentImage.tsx Removes the defective recursive helper and imports the dependency-free canonical shared implementation.
src/tests/shared/stringUtils.test.ts Covers valid UTF-8 and path decoding, malformed percent sequences, literal percent paths, and pass-through values.
src/tests/shared/deep-link-urls.test.ts Adds regression coverage for malformed identifiers, file paths, line fragments, and independently decoded sibling segments.

Reviews (1): Last reviewed commit: "fix(deep-links): guard percent-decoding ..." | Re-trigger Greptile

Comment thread src/shared/stringUtils.ts
* safeDecodeURIComponent('100%'); // '100%' (would throw URIError)
* ```
*/
export function safeDecodeURIComponent(value: string): string {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Document the shared decoder

safeDecodeURIComponent is now a canonical utility used by shared and renderer code, but it is absent from docs/agent-guides/SHARED-UTILS.md; this makes the helper harder to discover and encourages future duplicate implementations.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/shared/stringUtils.ts`:
- Around line 66-74: Update safeDecodeURIComponent to catch only URIError from
decodeURIComponent, return the original value for that specific
malformed-encoding error, and allow all other exceptions to propagate to Sentry.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6593badf-e8f3-49ba-b465-8ca70239809a

📥 Commits

Reviewing files that changed from the base of the PR and between 3070906 and 66edc19.

📒 Files selected for processing (5)
  • src/__tests__/shared/deep-link-urls.test.ts
  • src/__tests__/shared/stringUtils.test.ts
  • src/renderer/components/AutoRun/AttachmentImage.tsx
  • src/shared/deep-link-urls.ts
  • src/shared/stringUtils.ts

Comment thread src/shared/stringUtils.ts
pedramamini and others added 2 commits August 13, 2026 12:32
The bare catch swallowed everything, including failures that are real faults
rather than 'this was not valid encoding' - keeping them out of Sentry, which
is the silent-failure pattern CLAUDE.md warns against. Narrowed to URIError.

This also matches the implementation already merged on rc, so the branches
converge on this function instead of conflicting: both add the same symbol to
the same file, and a lazy conflict resolution would have kept whichever side
happened to be checked out.
@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

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.

Guard deep-link URL decoding against malformed percent encoding

1 participant