Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link previews aren't working with Signal #9

Closed
ChimeraCoder opened this issue May 17, 2023 · 11 comments
Closed

Link previews aren't working with Signal #9

ChimeraCoder opened this issue May 17, 2023 · 11 comments

Comments

@ChimeraCoder
Copy link

I came here to file a feature request for link previews, but from the other issues, it looks like it's actually supported and working on other platforms. For some reason, the link previews don't seem to be working on Signal (either Android or iOS), even when link previews are available, and even though they work for Twitter links (both text and images).

Because Signal supports link previews for all sites served over SSL/TLS, and because it works for other websites on Signal but consistently not for psky, I think this is an issue on psky's end.

Example of missing preview before message is sent (psky):

Screenshot 2023-05-17 at 3 21 56 PM

Example of preview before message is sent (Twitter):

Screenshot 2023-05-17 at 3 22 13 PM

Example of preview after message is sent (Twitter):

Screenshot 2023-05-17 at 3 24 08 PM
@ianklatzco
Copy link
Owner

I wonder if the format that Signal expects is different from the format that psky is serving.

The next step would to figure out Signal's user agent, then curl a tweet with Signal's user agent, and post the response 🥺

@jasikpark
Copy link

jasikpark commented May 17, 2023

here's the signal ios link preview fetcher code, for example: https://github.com/signalapp/Signal-iOS/blob/2ee794f3171d1fbb56a9f5331edc9e82a2434e3f/SignalUI/Utils/LinkPreviewFetcher.swift#L4

derp that link is less useful than i thought...

@ChimeraCoder
Copy link
Author

ChimeraCoder commented May 17, 2023

It looks like Signal identifies itself as WhatsApp in the user agent, for Reasons™ (anti-fingerprinting, but also Twitter apparently only returns tags for known user agents).

See signalapp/Signal-Android#10060 (issue is closed, but some more recent issues suggest that it's still the case)

@ianklatzco
Copy link
Owner

Blegh, my usual testing flow (that works with Telegram and Discord) doesn't work here because I need https.......

public-server> nc -l 3029
*dm http://ip:3029 to a friend on signal*

iirc there should be a way to listen on https and get the raw HTTP data.... maybe httpbin?

@ianklatzco
Copy link
Owner

https://requestinspector.com/ does not work with Telegram or Signal embeds

OpenSSL might work but it'll probably be self-signed and Signal will probably not fetch it, but it might.

image

@ianklatzco
Copy link
Owner

ianklatzco commented May 17, 2023

I think just WhatsApp works:

curl -v -A "WhatsApp" https://twitter.com/TrustedSec/status/1196503244685684738

image

vxtwitter does a redirect for WhatsApp user agent, finding that vxtwitter code would be useful.....

Edit: no hits in vxtwitter source code, but it does look like WhatsApp is the correct user agent....

@ianklatzco
Copy link
Owner

ianklatzco commented May 17, 2023

Okay, success at original technique by using a Caddyfile as follows:

testing.psky.app {
        reverse_proxy localhost:6968
}
# sudo systemctl caddy reload
nc -l 6968

*dm link on signal*

GET / HTTP/1.1
Host: testing.psky.app
User-Agent: WhatsApp/2
Accept: text/html,application/xhtml+xml
Accept-Encoding: gzip,deflate
X-Forwarded-For: 5.42.201.8
X-Forwarded-Host: testing.psky.app
X-Forwarded-Proto: https

So it's WhatsApp/2.

What does vxtwitter do with that....... I think nothing, I think it just redir's to Twitter and Signal parses the preview out of there.

@ianklatzco
Copy link
Owner

I'm not sure what Signal is doing!

It could be that it relies on the oembed.json that I've commented out, but I'm skeptical.

Requests do hit the python process running psky.app, but Signal must not like the response for some reason.

This also doesn't work:

def generate_html_profileonly_signal(full_path):
    html = f"""
      <html>
      <meta name="description" content="fooooo">
    <body>
        <div class="post-content" itemprop="articleBody">
            <p>barrrrrr</p>
        </div>
    </body>
    <html>

    """
    return html

My guess is that Signal gets the full http response from e.g. Twitter, and parses out whatever fields it wants in some way. But I'm not sure how.

The code is here: https://github.com/signalapp/Signal-Desktop/blob/9ad9b4da0f4447876490e2dbc462a2b7316dd128/ts/services/LinkPreview.ts#L333

The logs reporting failure are pretty boring:

WARN  2023-05-17T21:18:00.640Z fetchLinkPreviewMetadata: failed to fetch link preview HTML; bailing
INFO  2023-05-17T21:18:00.640Z addLinkPreview: failed to load preview (not necessarily a problem)

This code does in fact parse it with DomParser inside Signal Desktop's TypeScript:

https://github.com/signalapp/Signal-Desktop/blob/9ad9b4da0f4447876490e2dbc462a2b7316dd128/ts/linkPreviews/linkPreviewFetch.ts#L419-L435

This is probably returning null because my HTML is malformed somewhere?

@ianklatzco
Copy link
Owner

Found it! Signal expects an og:title. Fixed!

Link previews should work across the board in Signal now. I'll commit the code another time since it's late.

Thanks for the issue and help, @ChimeraCoder and @jasikpark !

@jasikpark
Copy link

yayyyy

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

No branches or pull requests

3 participants