Chat attachments: fetch only from trusted hosts on arrival, and check every redirect
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
Research direction
Start with encrypted_image_message.dart and attachment_providers.dart to trace automatic image fetching, then read rust/src/nostr/blossom.rs for download and redirect handling. Check the attachment payload parser and existing tests before changing the fetch rules. Done means untrusted image hosts wait for a user action, unsafe hosts and redirects are refused, and the listed host, redirect, and widget cases pass.
Written by the indexing model from the issue text.
Description
Summary
The URL of a chat attachment is chosen by whoever sent it, and the app fetches it with only two checks: it must be https and end in a 64-hex hash. Two things follow:
- An image is fetched as soon as its bubble is shown, from any host. A counterparty can send an
image_encryptedmessage whoseblossom_urlpoints at a server it runs, and learn the other party's IP address the moment the chat is opened. No tap is needed. Mostro keeps the two parties apart; this hands one of them the other's address. - Redirects are followed without checking them again. An
httpsURL can redirect tohttp, to127.0.0.1or to a private address, and the app makes that request. The hash check protects what gets decrypted, but it runs after the request: a counterparty can make the app send GET requests into the user's own network.
Both came up in the review of MostroP2P/protocol#88, which adds these rules to the attachments spec (Receiving, rules 2 and 3, and the automatic-fetch paragraph). Line references are at main, ab0fa199.
1. Images are fetched on arrival, from any host
Where: EncryptedImageMessage watches attachmentDataProvider, which downloads the blob as soon as the bubble builds ("downloaded and decrypted on arrival, as v1 does"). payload::parse accepts any https host.
What happens: the fetch reaches the host the sender named, on every target. On the web, the browser sends the request whatever the CORS answer is. File bubbles are not affected: they download only when the user taps Open, Share or Save.
Fix: fetch automatically only from the servers the app uploads to (BLOSSOM_SERVERS). For any other host, show the bubble with that host and a Download action, and fetch only once the user taps it.
2. Redirects are followed without checking them again
Where: download_blob checks https:// on the URL it was given, then fetch_verified uses http_client, a default reqwest::Client.
What happens: reqwest 0.12's default policy follows up to 10 redirects, including from https to http (it only drops the Referer), and https_only is off. Nothing checks the host either, before or after a redirect, so https://127.0.0.1/<hash>, https://192.168.1.1/<hash> or a redirect to either is fetched. This applies to the native targets. On the web, the browser's mixed-content and private-network rules already refuse most of these.
Fix, for downloads:
- Refuse a host that is
localhostor an IP address in a loopback, private, link-local or unspecified range, IPv4 and IPv6 (IPv4-mapped included). - On native, check the resolved addresses too, through a reqwest DNS resolver that filters them. The connection then uses the same resolution, so a rebinding cannot slip a private address in between the check and the connect.
- Re-apply
httpsand the host rule on every redirect with a customredirect::Policy, or refuse redirects. Some Blossom servers redirect a GET to their storage, so a checked redirect is friendlier than none. Sethttps_only(true)on the download client.
Tests
- Unit tests for the host rule: loopback, private, link-local and unspecified addresses in IPv4 and IPv6, IPv4-mapped IPv6, and
localhost, all refused; a public host accepted. - A local server that redirects to
http://…and to127.0.0.1: both refused, and nothing is decrypted. - A widget test: an image from a host not in
BLOSSOM_SERVERSshows the host and fetches nothing until Download is tapped.
Related
- MostroP2P/protocol#87 and #88 also change the attachment file key so that a solver can open the files. That needs its own work here: a fallback reader first, then the new sender. It is not part of this issue.
- v1 fetches images on arrival as well ("as v1 does"), so MostroP2P/mobile has the same exposure.
- Dominant language
- Dart
- Stars
- 11
- Forks
- 9
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 16
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from MostroP2P/app
-
documentation priority: low
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
Maintainers usually reply within 1 day
-
area: ui bug priority: medium
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
area: ui bug priority: high
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Bug: Button "Share logs" does nothingPossibly taken @Luquitasjeffrey claimed this 7 days ago. Open
Difficulty 2/5 Half a day Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
area: rust-core bug priority: low
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
Similar issues
-
Python example: list a model's scenes and their camerasPossibly taken @rudraparmar76 claimed this today. Opendocumentation good first issue python
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
iamahsanmehmood/openskp#796 · 1 comment ·
Maintainers usually reply within 1 day
-
needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Plural rendering: first matching part wins, but gen-l10n lets the last one win (=1 shadows one)Openbug help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
crowdin/flutter-sdk#97 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
MrSpideyNihal/lockfeed#16 ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
InlitX/GymMane#529 · 1 comment ·
Maintainers usually reply within 1 day