<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 &lt;<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>&gt; 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="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</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:&nbsp;<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="">
&gt; On 20 Jun 2016, at 19:26, Vladimir.S &lt;<a href="mailto:svabox@gmail.com" class="">svabox@gmail.com</a>&gt; wrote:<br class="">
&gt;<br class="">
&gt; Very interesting.<br class="">
&gt;<br class="">
&gt; Btw, IBM Swift Sandbox shows these spaces:<br class="">
&gt; <a href="https://swiftlang.ng.bluemix.net/" rel="noreferrer" target="_blank" class="">https://swiftlang.ng.bluemix.net/</a><br class="">
&gt; But my mail client does not - i.e. I saw exactly the same "test"&amp;"abc"<br class="">
&gt;<br class="">
&gt; 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="">
&gt;<br class="">
&gt; 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="">
&gt;<br class="">
&gt; On 20.06.2016 20:51, João Pinheiro via swift-evolution wrote:<br class="">
&gt;&gt; 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="">
&gt;&gt;<br class="">
&gt;&gt; I would like to propose a change to prohibit the use of invisible characters in identifier names.<br class="">
&gt;&gt;<br class="">
&gt;&gt; I'm including an example of problematic code at the bottom of this email.<br class="">
&gt;&gt;<br class="">
&gt;&gt; Sincerely,<br class="">
&gt;&gt; João Pinheiro<br class="">
&gt;&gt;<br class="">
&gt;&gt;<br class="">
&gt;&gt; /* The output for this code is:<br class="">
&gt;&gt; A<br class="">
&gt;&gt; B<br class="">
&gt;&gt; C<br class="">
&gt;&gt; 1<br class="">
&gt;&gt; 2<br class="">
&gt;&gt; 3<br class="">
&gt;&gt; */<br class="">
&gt;&gt;<br class="">
&gt;&gt; func test() { print("A") }<br class="">
&gt;&gt; func t​est() { print("B") }<br class="">
&gt;&gt; func te​st() { print("C") }<br class="">
&gt;&gt;<br class="">
&gt;&gt; let abc = 1<br class="">
&gt;&gt; let a​bc = 2<br class="">
&gt;&gt; let ab​c = 3<br class="">
&gt;&gt;<br class="">
&gt;&gt; test()<br class="">
&gt;&gt; t​est()<br class="">
&gt;&gt; te​st()<br class="">
&gt;&gt;<br class="">
&gt;&gt; print(abc)<br class="">
&gt;&gt; print(a​bc)<br class="">
&gt;&gt; print(ab​c)<br class="">
&gt;&gt; _______________________________________________<br class="">
&gt;&gt; swift-evolution mailing list<br class="">
&gt;&gt; <a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
&gt;&gt; <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="">
&gt;&gt;<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>