Skip to content

Commit 60f7462

Browse files
committed
fix: preserve query string and fragment in federation picture URLs
parse_picture rendered the validated picture URL via SafeUrl's Display, which is meant for safe logging and drops query/fragment. CDN avatars using sizing params or a signed query resolved to the wrong image. Use without_auth() + as_str() instead, which strips credentials while keeping the full URL. Fixes #553
1 parent d3c14ef commit 60f7462

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

rust/ecashapp/src/nostr.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,7 +1962,7 @@ impl PublicFederation {
19621962
if let Some(pic_url) = picture.as_str() {
19631963
// Verify that the picture is a URL
19641964
let safe_url = SafeUrl::parse(pic_url).ok()?;
1965-
return Some(safe_url.to_string());
1965+
return Some(safe_url.without_auth().ok()?.as_str().to_string());
19661966
}
19671967
}
19681968

@@ -2650,18 +2650,16 @@ mod tests {
26502650
}
26512651

26522652
#[test]
2653-
fn test_parse_picture_drops_the_query_string() {
2654-
// `SafeUrl`'s `Display` renders scheme, host, port and path only, so a
2655-
// picture URL loses its query and fragment on the way through. Avatars
2656-
// served with CDN sizing or a signature in the query therefore resolve to
2657-
// a different URL than the one announced. Pinned so the behaviour is
2658-
// visible rather than discovered through a blank avatar.
2653+
fn test_parse_picture_preserves_query_string() {
2654+
// The full URL (including query/fragment) is needed to fetch the
2655+
// correct image — e.g. CDN sizing params or a signed query. Using
2656+
// `SafeUrl`'s `Display` here previously truncated these away.
26592657
let json: serde_json::Value =
26602658
serde_json::from_str(r#"{"picture":"https://example.com/pic.png?w=64#frag"}"#)
26612659
.expect("valid json");
26622660
assert_eq!(
26632661
PublicFederation::parse_picture(&json).as_deref(),
2664-
Some("https://example.com/pic.png")
2662+
Some("https://example.com/pic.png?w=64#frag")
26652663
);
26662664
}
26672665

0 commit comments

Comments
 (0)