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

Display Unicode URIs side-by-side with their Punycode encoding #15488

Merged

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented May 31, 2023

06174a9 didn't properly fix the issue of us showing homoglyphs in our
URI tooltip. This commit introduces a different approach where we
display both, the Punycode and Unicode encoding, whenever we encounter
an IDN. This isn't perfect but simple to implement.

Closes #15432

Validation Steps Performed

  • https://www.xn--fcbook-3nf5b.com/ (which contains confusing glyphs)
    is shown both in its Punycode and Unicode form simultaneously. ✅

@microsoft-github-policy-service microsoft-github-policy-service bot added Issue-Bug It either shouldn't be doing this or needs an investigation. Area-User Interface Issues pertaining to the user interface of the Console or Terminal Priority-1 A description (P1) Product-Terminal The new Windows Terminal. labels May 31, 2023
@@ -3042,56 +3042,85 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_core.ClearHoveredCell();
}

winrt::fire_and_forget TermControl::_hoveredHyperlinkChanged(IInspectable /*sender*/,
IInspectable /*args*/)
// Attackers abuse Unicode characters that happen to look similar to ASCII characters. Cyrillic for instance has
Copy link
Member Author

Choose a reason for hiding this comment

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

@lhecker
Copy link
Member Author

lhecker commented May 31, 2023

This is what it looks like:
image

This is what happens if you use a right-to-left override (RTLO):
image

}

const auto uriText = sanitizeURI(_core.HoveredUriText());
Copy link
Member Author

@lhecker lhecker May 31, 2023

Choose a reason for hiding this comment

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

I'm not sure if we should encode URIs to Punycode a little earlier than this... If the encoding to Punycode fails, we shouldn't even allow the option to click it. On the other hand, the old code didn't handle that either and this fixes the immediate issue.

Copy link
Member

Choose a reason for hiding this comment

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

Honestly, I am OKAY with this.

Thanks so much.

@zadjii-msft
Copy link
Member

wait can you ctrl+click invalid URIs?

@DHowett
Copy link
Member

DHowett commented May 31, 2023

send a screenshot!

@lhecker
Copy link
Member Author

lhecker commented May 31, 2023

wait can you ctrl+click invalid URIs?

Yep, you can. It just might not work, because the OS validates them. For instance, this doesn't work:

"`n`e]8;;https://www.`u{202e}xn--fcbook-3nf5b.com/`e\TOTALLY REAL FACEBOOK LINK. YOU CAN TRUST ME.`e]8;;`e\ `n`n"

but this does (the a and e in "facebook" are not ASCII):

"`n`e]8;;https://www.`u{202e}fаcеbook.com/`e\TOTALLY REAL FACEBOOK LINK. YOU CAN TRUST ME.`e]8;;`e\ `n`n"

...which is a little concerning. You get this message instead:
image

send a screenshot!

What would you like to see? A comment above shows 2 situations - I'd be happy to make more.

@DHowett
Copy link
Member

DHowett commented May 31, 2023

06174a9 didn't properly fix the issue of us showing homoglyphs

to be clear, it was not intended to

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

Notes and Qs.

Generally, I am 100% happy with this. Just the UI thread concern!

}

const auto uriText = sanitizeURI(_core.HoveredUriText());
Copy link
Member

Choose a reason for hiding this comment

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

Honestly, I am OKAY with this.

Thanks so much.

{
auto weakThis{ get_weak() };
co_await wil::resume_foreground(Dispatcher());
Copy link
Member

Choose a reason for hiding this comment

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

This is another instance where we were switching to the foreground to make touching UI objects safe. Are we convinced that this is safe?

Copy link
Member Author

Choose a reason for hiding this comment

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

The only place _hoveredHyperlinkChanged is called from is the _core.HoveredHyperlinkChanged() event. _HoveredHyperlinkChangedHandlers is only called in ControlCore::_updateHoveredCell, which in turn is only called by SetHoveredCell and ClearHoveredCell. The former is only called by ControlInteractivity::PointerMoved which is a UI-thread-only function and the latter is only called by TermControl::_PointerExitedHandler which is the same. BTW It's somewhat weird that PointerMoved us in ControlInteractivity, but "pointer exited" isn't.

So yeah this can only be called from the UI thread.

Copy link
Member

Choose a reason for hiding this comment

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

That's technically an implementation detail, but I'll allow it ;P

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Jun 1, 2023
@@ -178,6 +178,10 @@
<data name="HowToOpenRun.Text" xml:space="preserve">
<value>Ctrl+Click to follow link</value>
</data>
<data name="InvalidUri" xml:space="preserve">
<value>Invalid URI</value>
<comment>Whenever we encounter an invalid URI or URL we show this string as a warning.</comment>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<comment>Whenever we encounter an invalid URI or URL we show this string as a warning.</comment>
<comment>Whenever we encounter an invalid URI or URL we show this string as an error.</comment>

nit

Copy link
Member Author

@lhecker lhecker Jun 8, 2023

Choose a reason for hiding this comment

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

Hmm I feel like "as a warning" is better in this case. 🤔
After all, this doesn't prevent you from clicking the URL.

src/cascadia/TerminalControl/TermControl.cpp Outdated Show resolved Hide resolved
Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

I am okay merging without fixing Carlos' comments honestly

Co-authored-by: Carlos Zamora <carlos.zamora@microsoft.com>
@lhecker lhecker added the AutoMerge Marked for automatic merge by the bot when requirements are met label Jun 8, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot merged commit f1aa699 into main Jun 8, 2023
14 of 15 checks passed
@microsoft-github-policy-service microsoft-github-policy-service bot deleted the dev/lhecker/15432-homoglyph-uris branch June 8, 2023 23:56
@DHowett DHowett added this to To Cherry Pick in 1.17 Servicing Pipeline via automation Jul 27, 2023
@DHowett DHowett added this to To Cherry Pick in 1.18 Servicing Pipeline via automation Jul 27, 2023
@DHowett DHowett moved this from To Cherry Pick to Cherry Picked in 1.17 Servicing Pipeline Jul 27, 2023
DHowett pushed a commit that referenced this pull request Jul 27, 2023
06174a9 didn't properly fix the issue of us showing homoglyphs in our
URI tooltip. This commit introduces a different approach where we
display both, the Punycode and Unicode encoding, whenever we encounter
an IDN. This isn't perfect but simple to implement.

Closes #15432

## Validation Steps Performed
* `https://www.xn--fcbook-3nf5b.com/` (which contains confusing glyphs)
  is shown both in its Punycode and Unicode form simultaneously. ✅

---------

Co-authored-by: Carlos Zamora <carlos.zamora@microsoft.com>
(cherry picked from commit f1aa699)
Service-Card-Id: 90012448
Service-Version: 1.17
@DHowett DHowett moved this from To Cherry Pick to Cherry Picked in 1.18 Servicing Pipeline Jul 27, 2023
DHowett pushed a commit that referenced this pull request Jul 27, 2023
06174a9 didn't properly fix the issue of us showing homoglyphs in our
URI tooltip. This commit introduces a different approach where we
display both, the Punycode and Unicode encoding, whenever we encounter
an IDN. This isn't perfect but simple to implement.

Closes #15432

## Validation Steps Performed
* `https://www.xn--fcbook-3nf5b.com/` (which contains confusing glyphs)
  is shown both in its Punycode and Unicode form simultaneously. ✅

---------

Co-authored-by: Carlos Zamora <carlos.zamora@microsoft.com>
(cherry picked from commit f1aa699)
Service-Card-Id: 90012449
Service-Version: 1.18
@DHowett DHowett moved this from Cherry Picked to Validated in 1.17 Servicing Pipeline Aug 2, 2023
@lhecker lhecker moved this from Cherry Picked to Validated in 1.18 Servicing Pipeline Sep 25, 2023
@DHowett DHowett moved this from Validated to Shipped in 1.18 Servicing Pipeline Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-User Interface Issues pertaining to the user interface of the Console or Terminal AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal.
Development

Successfully merging this pull request may close these issues.

Homoglyphs in URL tooltips
4 participants