That actually strikes me as very desirable. (Especially in light of the old maxim that "programs must be written for people to read, and only incidentally for machines to execute".)
And, actually, there was some really really cursed Soviet encoding that did this to save bits. The Russian railway company still uses it[1] to this day.
I know at least 10 stories that start like this
Well, as a moderately old Czech, I'm somewhat familiar with Cyrillic. They kind of used to force it on us in schools.
this was a royal pain in the arse to figure out if I had live examples in the specs, because vim also just rendered them "correctly"
That's because vim supports Farsi/Arabic natively from day one. Even if the OS does not support it, you can still write bidirectional and right-to-left text in vim. Never knew the reason, but thanks Bram Molenaar.And here's what it looks like in various conditions/viewers:
With the fix, this is how it looks in the browser in the Gitlab interface:
if (accessLevel != "user�") {� // Check if admin ��
Without the fix, viewed raw (and thus viewed in a vulnerable way), it looks like this: if (accessLevel != "user") { // Check if admin
And in a hex viewer, it looks like this: 000005b0: 2020 2020 2020 2069 6620 2861 6363 6573 if (acces
000005c0: 734c 6576 656c 2021 3d20 2275 7365 72e2 sLevel != "user.
000005d0: 80ae 20e2 81a6 2f2f 2043 6865 636b 2069 .. ...// Check i
000005e0: 6620 6164 6d69 6ee2 81a9 20e2 81a6 2229 f admin... ...")
000005f0: 207b 0a20 2020 2020 2020 2020 2020 2020 {.
00000600: 2063 6f6e 736f 6c65 2e6c 6f67 2822 596f console.log("Yo
00000610: 7520 6172 6520 616e 2061 646d 696e 2e22 u are an admin."I was expecting a big fat warning on the merge request itself, or maybe on the lines containing the dangerous chars.
In the end, it is a small ? character inserted were the unicode control chars are, and a mouseover tooltip warning about a potential issue.
The warning is good, but why so subtle? Sorry for the criticism. The feature is still a huge positive.
GitHub by comparison went down the alert banner route, from what I can see. I'm not opposed to adding something to that effect as well though - especially for inexperienced reviewers, it would be nice to include some more information about the potential exploit. That could be something we revisit when we add the homoglyph highlighting.
var accessLevel = "user";
if (accessLevel != "user� �// Check if admin� �") {
console.log("You are an admin.");
}
than this: var accessLevel = "user";
if (accessLevel != "user�") {� // Check if admin��
console.log("You are an admin.");
}Have you tried something similar to what the browsers do where highlighting is only enabled when there are multiple scripts mixed within the same token? Source code seems like it would be harder since you have many tokens rather than just a single one as in a hostname, and I'd be curious how much legitimate usage mixes scripts for technical reasons because you have something like a language or framework convention that certain names start with a particular English-derived term.
I gotta say that I always make sure that I understand each piece of code that I copy paste but I do copy paste and never thought of this type of attack. Maybe that's something I should pay attention to in the future.
For someone with more gumption than me:
Future copy & paste will default have intermediate screenshot and OCR steps. Voila: charset scrubbing for free.
Why not? Already today misc UIs and renderings disallow text selection. Drives me nuts.
To clarify, by default copy and paste works the normal way, but you can open the app switcher to use the OCR copy/paste which works on non-selectable text too, even in images.
I've never seen it used for Japanese. I don't think there is a valid use case for Japanese.
Hebrew would be a more valid second example I think. I'd be curious to know how many languages maintain their RTL preference online.
⸻⸻⸻
1. All of this also applies to Chinese and Korean. Interestingly, traditional Mongolian script is also written vertically, but in columns left to right rather than right to left.
Which, if one is suspicious of code, can be defeated in vim with: set encoding=latin1
The homoglyph attack is interesting but it really should be noticed as part of a code review process, as it requires adding the imitation function calls at some point too. It'd also likely be pretty frustrating to end users if we were to highlight every single unicode character that looks like the latin alphabet.
It's certainly a good lesson in not copy/pasting random snippets from the internet and pasting them into a root shell, however :D (we do always highlight the bidi characters on GitLab snippets, though)
Aside: this was a royal pain in the arse to figure out if I had live examples in the specs, because vim also just rendered them "correctly". I ended up checking the files in Windows Notepad on another machine to sanity check them.
Thanks to the authors for responsible disclosure.