-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
Fix the check for misleading links #1901
Conversation
Hi, thanks for the PR! Will try to review today.
Can you move It's our only unit test (was created as a proof of concept) and I think the unit test you created would fit well in there! |
Sorry, didn't get to the review today. Will do it first thing in the morning! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, looks good!
I only added comments to explain the test cases and realized that URLs can contain hyphens but those were nitpicks so I just pushed the changes myself. I hope you don't mind.
no problem at all, thanks! |
Thanks ed! Do you have a lightning address I can send sats to? |
Yes, you can send to simplestacker@getalby.com. Thanks so much! Hope to keep contributing to this great project :) |
Description
Fix/address issue #323
Currently,
isMisleadingLink
inlib/rehype-sn.js
checks whether links are misleading by comparing the link text to the href. If the link text is URL-like (contains letters, numbers, underscores, and dots), the function addshttp://
to the link-text and then checks whether the URL's origin has the same origin as href.The issue is that if the link text contains other characters, like
:
or/
, which are common in URLs,isMisleadingLink
will return false (doesn't identify the link as misleading). This PR fixes the issue by checking if the link text is any valid URL. If it is, it compares the origin of the link text to that of the href, and if the two are different,isMisleadingLink
will return true (is misleading).Before:
[https://bing.com](https://google.com)
renders the text as https://bing.com and the href as https://google.com[bing.com](https://google.com)
renders both the text and href as https://google.comAfter:
[https://bing.com](https://google.com)
renders both the text and href as https://google.com[bing.com](https://google.com)
renders both the text and href as https://google.comAdditional Context
This patch does not fix (potentially) misleading links where the domain of the link text and the href are the same. For example,
[https://stacker.news/items/123](https://stacker.news/items/321)
will render the link text as https://stacker.,news/items/123 while linking to https://stacker.news/items/321. It was considered that there may be legitimate use cases of having a link text and the href be different while sharing the same origin, while not being able to do phishing attacks by this vector. See #323Checklist
Are your changes backwards compatible? Please answer below:
Some link texts that weren't caught and replaced by
isMisleadingLink
before will now be caught and replaced. However, I've never observed such a link while using stacker newsOn a scale of 1-10 how well and how have you QA'd this change and any features it might affect? Please answer below:
7: I've tested it on local instance with various posts. I'm not sure how to test effects on performance / impact on existing SN posts.
Also, here is a small unit test of
isMisleadingLink
that I did manually:Output:
For frontend changes: Tested on mobile, light and dark mode? Please answer below:
not frontend change
Did you introduce any new environment variables? If so, call them out explicitly here:
no