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

Warn the user on links that dont match their text #1573

Merged
merged 7 commits into from
Oct 2, 2023
Merged

Conversation

pfrazee
Copy link
Collaborator

@pfrazee pfrazee commented Sep 29, 2023

Adds an interstitial for links in posts that dont match their text. If the text is not a URL, it just gives the user a normal "Leaving this site". If the text is a URL that doesnt match the target, it gives a "Possibly misleading" warning. If the link is the URL, it opens as usual.

CleanShot 2023-09-28 at 19 32 13@2x
CleanShot 2023-09-28 at 19 33 31@2x
CleanShot 2023-09-28 at 19 33 38@2x

@ansh
Copy link
Contributor

ansh commented Sep 29, 2023

CleanShot 2023-09-29 at 07 18 47@2x Dark mode broken

Comment on lines 172 to 174
const urip = new URL(uri)
label = label.replace(/^http(s?):\/\//i, '')
return !label.startsWith(urip.hostname)
Copy link

@intrnl intrnl Sep 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URL#host and URL#hostname are normalized, so new URL('https://Example.com') with Example.com wouldn't match, should label be lowercased here?

A random post I've found that can showcase this: https://bsky.app/profile/did:plc:msrbmpy5pqxwsgdgl3hyeapw/post/3kaixgqung42o

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code, it normalizes now and ignores case

@intrnl
Copy link

intrnl commented Sep 29, 2023

because of the startsWith use, shouldn't it need to check what comes after the host? if there's more after the host, but the next character isn't /, ?, #, then it should be rejected

can imagine a scenario where someone would link to website.com but in actually it links to website.co or site.pages.dev to site.page, which is a different site entirely

edit: got a bit confused writing this so let's make it clear

// label.startsWith(actualDomain)
'website.com'.startsWith('website.co')
'site.pages.dev'.startsWith('site.page')

@DavidBuchanan314
Copy link
Contributor

DavidBuchanan314 commented Sep 29, 2023

Something you might want to consider is an additional emphasis on the apex domain, in the interstitial. Web users often do not understand the counterintuitive order of trust anchoring in domains. For example:

https://paypal.com.billing-department-enquiries.example.com/blah-blah-blah

@pfrazee
Copy link
Collaborator Author

pfrazee commented Oct 2, 2023

Good suggestion @DavidBuchanan314

Listed TLD:

CleanShot 2023-10-02 at 14 13 11@2x

Non-listed TLD:

CleanShot 2023-10-02 at 14 13 31@2x

@pfrazee
Copy link
Collaborator Author

pfrazee commented Oct 2, 2023

@intrnl dumb thing for me to be lazy about. Fixed now.

@pfrazee
Copy link
Collaborator Author

pfrazee commented Oct 2, 2023

@ansh Can't believe I missed dark mode, thanks for hitting that

Should be good to go

@pfrazee pfrazee merged commit fd5bbb2 into main Oct 2, 2023
4 checks passed
@pfrazee pfrazee deleted the link-warnings branch October 2, 2023 21:47
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

Successfully merging this pull request may close these issues.

4 participants