<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I agree that treating zero-width spaces as non-existent would be a possible solution, but I think it would make more sense to consider it as white space and thus not admissible in identifier names. I'm not sure of what the best way to handle left-to-right and right-to-left markers would be. Does it make sense to allow mixed text orientation in identifiers?<div class=""><br class=""></div><div class="">Removing ambiguity between unicode confusables is a much more complicated issue which implies defining a canonical unicode representation for identifiers and a way to resolve them. It would also make it impractical to use certain valid mathematical symbols as identifiers.</div><div class=""><br class=""></div><div class="">João Pinheiro</div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 20 Jun 2016, at 20:23, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">On Mon, Jun 20, 2016 at 2:17 PM, João Pinheiro <span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></span> wrote:<br class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Nice feature in the IBM Swift Sandbox. Xcode doesn't display zero-width spaces either so the identifier names look exactly the same.<br class="">
<br class="">
The issue with left-to-right and right-to-left markers is interesting and has previously been exploited in email phishing attacks.<br class="">
<br class="">
It would be possible to highlight invisible characters in Xcode as a stopgap measure, but that doesn't solve the problem for developers using other editors or in other platforms. I think it would be a better idea to sanitise the set of allowed (or prohibited) characters for identifiers at the language level.<br class=""></blockquote><div class=""><br class=""></div><div class="">This is a potential security problem, but no need try to invent an ad-hoc solution here, particularly one as drastic as prohibiting characters. The same security considerations are applicable elsewhere and there's a lot of work about Unicode security. See here: <a href="http://www.unicode.org/reports/tr39/" class="">http://www.unicode.org/reports/tr39/</a></div><div class=""><br class=""></div><div class="">Unicode maintains a list of "confusable" characters. See here: <a href="http://www.unicode.org/Public/security/latest/confusables.txt" class="">http://www.unicode.org/Public/security/latest/confusables.txt</a></div><div class=""><br class=""></div><div class="">It should be sufficient to regard confusables as the same glyph for the purpose of identifier names; zero-width and invisible marks would then be regarded as non-existent, so that `test` and `t[invisible glyph]est` would refer to the same variable.</div><div class=""><br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br class="">
Sincerely,<br class="">
João Pinheiro<br class="">
<div class=""><div class="h5"><br class="">
<br class="">
> On 20 Jun 2016, at 19:26, Vladimir.S <<a href="mailto:svabox@gmail.com" class="">svabox@gmail.com</a>> wrote:<br class="">
><br class="">
> Very interesting.<br class="">
><br class="">
> Btw, IBM Swift Sandbox shows these spaces:<br class="">
> <a href="https://swiftlang.ng.bluemix.net/" rel="noreferrer" target="_blank" class="">https://swiftlang.ng.bluemix.net/</a><br class="">
> But my mail client does not - i.e. I saw exactly the same "test"&"abc"<br class="">
><br class="">
> Also, I read about some issues with left-to-right and right-to-left markers that also somehow change the actual text of source - i.e. you see one text, but when it compiles - it works not as expected. I.e. viewer/editor processes these special codes and show you one text, but compiler treats text in another way.<br class="">
><br class="">
> I believe it is a potential security problem that all unicode chars are allowed for variables/func names in Swift. IMO We definitely should limit allowed charset for identifiers in sources.<br class="">
><br class="">
> On 20.06.2016 20:51, João Pinheiro via swift-evolution wrote:<br class="">
>> Recently there has been a screenshot going around Twitter about C++ allowing zero-width spaces in variable names. Swift also suffers from this problem which can be abused to create ambiguous, misleading, and potentially obfuscate nefarious code.<br class="">
>><br class="">
>> I would like to propose a change to prohibit the use of invisible characters in identifier names.<br class="">
>><br class="">
>> I'm including an example of problematic code at the bottom of this email.<br class="">
>><br class="">
>> Sincerely,<br class="">
>> João Pinheiro<br class="">
>><br class="">
>><br class="">
>> /* The output for this code is:<br class="">
>> A<br class="">
>> B<br class="">
>> C<br class="">
>> 1<br class="">
>> 2<br class="">
>> 3<br class="">
>> */<br class="">
>><br class="">
>> func test() { print("A") }<br class="">
>> func test() { print("B") }<br class="">
>> func test() { print("C") }<br class="">
>><br class="">
>> let abc = 1<br class="">
>> let abc = 2<br class="">
>> let abc = 3<br class="">
>><br class="">
>> test()<br class="">
>> test()<br class="">
>> test()<br class="">
>><br class="">
>> print(abc)<br class="">
>> print(abc)<br class="">
>> print(abc)<br class="">
>> _______________________________________________<br class="">
>> swift-evolution mailing list<br class="">
>> <a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
>> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
>><br class="">
<br class="">
_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
</div></div></blockquote></div><br class=""></div></div>
</div></blockquote></div><br class=""></div></body></html>