#16938: fix(media): reject unsupported URL schemes with clear error message
channel: whatsapp-web
size: XS
experienced-contributor
Cluster:
Media Handling Improvements
## Summary
When AI agents hallucinate invalid URL schemes (e.g., `vector://`, `ftp://`), the code previously attempted to read them as local paths, resulting in confusing ENOENT errors like:
```
ENOENT: no such file or directory, open 'vector://vector/home/user/file.xlsx'
```
This change detects unsupported schemes early and throws a clear, actionable error:
```
Unsupported media URL scheme "vector://". Use file:// for local files, http(s):// for remote URLs, or a direct file path.
```
## Changes
- Added URL scheme validation in `loadWebMediaInternal()` before processing
- Supported schemes: `file://`, `http://`, `https://`, and direct paths
- Added test cases for unsupported schemes (`vector://`, `ftp://`, `magnet://`)
## Testing
- Added unit tests in `src/web/media.test.ts`
- Verified existing tests still pass
Fixes #14575
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds early URL scheme validation in `loadWebMediaInternal()` to reject unsupported protocols (e.g., `vector://`, `ftp://`) with a clear, actionable error message instead of letting them fall through to confusing ENOENT errors.
- Validates URL schemes using an RFC 3986-compliant regex, allowing only `file://`, `http://`, `https://`, and direct file paths
- Validation is correctly placed after `MEDIA:` prefix stripping and before scheme-specific handling
- Adds test coverage for three unsupported scheme variants (`vector://`, `ftp://`, `magnet://`)
- No issues found — this is a focused, well-scoped defensive fix
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge — it only adds an early-rejection guard for invalid URL schemes with no impact on existing valid paths.
- The change is minimal and purely additive: a single validation check with a clear error path. It does not modify any existing logic for supported schemes (file/http/https/local paths). The regex is correct per RFC 3986, and edge cases like Windows drive letters (`C:/`) and `data:` URIs are unaffected since they don't match the `://` pattern. Tests cover the new behavior adequately.
- No files require special attention.
<sub>Last reviewed commit: 9e34875</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#9817: fix(media): resolve relative paths before reading local files (#8759)
by lailoo · 2026-02-05
79.7%
#18811: fix(media): require file extension for ambiguous MEDIA: path detection
by aldoeliacim · 2026-02-17
78.4%
#8076: fix(web): handle data URLs in loadWebMedia to prevent ENAMETOOLONG
by batumilove · 2026-02-03
75.1%
#17944: fix(security): fail-closed for local media paths without sandboxRoot
by Operative-001 · 2026-02-16
74.0%
#19868: fix: prevent media token regex from matching markdown bold text
by sanketgautam · 2026-02-18
73.8%
#22178: test(web): allow fixture roots in media local file tests
by Kansodata · 2026-02-20
72.5%
#22356: test(web): fix media test fixture local root handling
by AIflow-Labs · 2026-02-21
72.3%
#10257: fix(security): anchor MIME sanitization regex and block fullwidth b...
by nu-gui · 2026-02-06
72.2%
#14794: fix: parse inline MEDIA: tokens in agent replies
by explainanalyze · 2026-02-12
72.2%
#16990: fix(media): strip auth headers on cross-origin redirect in download...
by AI-Reviewer-QS · 2026-02-15
72.1%