[GH-ISSUE #2325] [Issue]: Spotify percent_decode_component panics on '%' followed by a multi-byte UTF-8 char (non-char-boundary slice) #1152

Closed
opened 2026-10-21 05:28:01 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @Romuromylus on GitHub (Jun 5, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2325

Originally assigned to: @Xelvanis on GitHub.

Summary

Severity: Low — Crash (feature-level DoS). Spotify's percent_decode_component slices a &str at a byte index that can land inside a multi-byte UTF-8 character, so a query value containing % immediately followed by a multi-byte char panics ("byte index is not a char boundary"). Reachable from the loopback OAuth callback server and from a user-pasted callback URL.

Expected behavior

Percent-decoding should never panic on arbitrary input. A malformed %-sequence should fall through to literal handling, not crash the callback task / connect command.

Actual behavior

src-tauri/src/commands/storage/integrations/spotify_callback.rs:119-120 (duplicated at spotify.rs:3083-3084):

b'%' if index + 2 < bytes.len() => {
    let hex = &value[index + 1..index + 3];
    if let Ok(byte) = u8::from_str_radix(hex, 16) {

The guard index + 2 < bytes.len() passes, but &value[index + 1..index + 3] can fall inside a 3-byte UTF-8 sequence — there is no is_char_boundary check. Verified empirically: input "%\u{2026}x" (bytes 25 E2 80 A6 78) panics with "end byte index 3 is not a char boundary; it is inside '…'".

Two reachable entry points: (1) the loopback callback server bound to 127.0.0.1:8754 (start_callback_listener → handle_callback_request → parse_query → percent_decode_component); (2) the IPC connect/exchange path (spotify.rs:2977) parsing a user-pasted callbackUrl. Default unwind (no panic="abort" in Cargo.toml), so the panic kills the spawned callback task / rejects the command promise rather than aborting the whole process — a feature-level DoS (OAuth completion silently fails until the flow is restarted).

Steps to reproduce

  1. Connect Spotify and either:
    • (a) paste a redirect URL whose query contains % followed by a multibyte UTF-8 char, or
    • (b) GET http://127.0.0.1:8754/spotify/callback?code=%… with a raw % + multibyte char (bytes 25 E2 80 A6) in a value.
  2. percent_decode_component panics; the OAuth task/command dies.

Impact area

  • Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime

Environment

  • Branch or commit: refactor @ b0e5561d
  • Run mode: Tauri desktop (also server mode)
  • OS + version: not relevant (static source audit; panic reproduced)
  • Node + pnpm versions: not relevant
  • Rust version, if relevant: reproduced on stable
  • Remote Runtime URL configured? not relevant (applies to both)
  • Provider, model, or integration, if relevant: Spotify OAuth

Logs, screenshots, or video

Reproduced panic message: end byte index 3 is not a char boundary; it is inside '…'.

Regression notes

Found via static audit of the refactor branch; not verified against main. Single non-core integration, no data loss, no whole-process crash; realistic path-(1) trigger needs a local process hitting the loopback port during the ~10-min auth window, hence low — but a clean, trivially-fixable crash bug.

Additional context

Suggested fix: decode hex from the two raw bytes (bytes[index+1], bytes[index+2]) instead of slicing the &str, or add a value.is_char_boundary(index + 3) guard before slicing (falling through to the literal-% branch otherwise). Apply to both copies and consider deduplicating the two identical percent_decode_component implementations.

Template check

Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Romuromylus on GitHub (Jun 5, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2325 Originally assigned to: @Xelvanis on GitHub. ## Summary **Severity: Low — Crash (feature-level DoS).** Spotify's `percent_decode_component` slices a `&str` at a byte index that can land inside a multi-byte UTF-8 character, so a query value containing `%` immediately followed by a multi-byte char panics ("byte index is not a char boundary"). Reachable from the loopback OAuth callback server and from a user-pasted callback URL. ## Expected behavior Percent-decoding should never panic on arbitrary input. A malformed `%`-sequence should fall through to literal handling, not crash the callback task / connect command. ## Actual behavior `src-tauri/src/commands/storage/integrations/spotify_callback.rs:119-120` (duplicated at `spotify.rs:3083-3084`): ```rust b'%' if index + 2 < bytes.len() => { let hex = &value[index + 1..index + 3]; if let Ok(byte) = u8::from_str_radix(hex, 16) { ``` The guard `index + 2 < bytes.len()` passes, but `&value[index + 1..index + 3]` can fall inside a 3-byte UTF-8 sequence — there is no `is_char_boundary` check. Verified empirically: input `"%\u{2026}x"` (bytes `25 E2 80 A6 78`) panics with "end byte index 3 is not a char boundary; it is inside '…'". Two reachable entry points: (1) the loopback callback server bound to `127.0.0.1:8754` (`start_callback_listener` → `handle_callback_request` → `parse_query` → `percent_decode_component`); (2) the IPC connect/exchange path (`spotify.rs:2977`) parsing a user-pasted `callbackUrl`. Default unwind (no `panic="abort"` in `Cargo.toml`), so the panic kills the spawned callback task / rejects the command promise rather than aborting the whole process — a feature-level DoS (OAuth completion silently fails until the flow is restarted). ## Steps to reproduce 1. Connect Spotify and either: - (a) paste a redirect URL whose query contains `%` followed by a multibyte UTF-8 char, or - (b) `GET http://127.0.0.1:8754/spotify/callback?code=%…` with a raw `%` + multibyte char (bytes `25 E2 80 A6`) in a value. 2. `percent_decode_component` panics; the OAuth task/command dies. ## Impact area - [x] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime ## Environment - Branch or commit: refactor @ b0e5561d - Run mode: Tauri desktop (also server mode) - OS + version: not relevant (static source audit; panic reproduced) - Node + pnpm versions: not relevant - Rust version, if relevant: reproduced on stable - Remote Runtime URL configured? not relevant (applies to both) - Provider, model, or integration, if relevant: Spotify OAuth ## Logs, screenshots, or video Reproduced panic message: `end byte index 3 is not a char boundary; it is inside '…'`. ## Regression notes Found via static audit of the refactor branch; not verified against main. Single non-core integration, no data loss, no whole-process crash; realistic path-(1) trigger needs a local process hitting the loopback port during the ~10-min auth window, hence low — but a clean, trivially-fixable crash bug. ## Additional context Suggested fix: decode hex from the two raw bytes (`bytes[index+1]`, `bytes[index+2]`) instead of slicing the `&str`, or add a `value.is_char_boundary(index + 3)` guard before slicing (falling through to the literal-`%` branch otherwise). Apply to both copies and consider deduplicating the two identical `percent_decode_component` implementations. ## Template check Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:28:01 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1152
No description provided.