The Trojan Source paper has a decent treatment of the area too, seen in a different application: https://trojansource.codes/trojan-source.pdf.
In the article it is shown how this can be misused to show executable files as a different file type:
file[U+202e]fdp.exe shown as fileexe.pdf
~~~~~~~~^^^^^^^
| |--- read this right-to-left, i.e. exe.pdf
|----------- this is the Unicode character Right-To-Left OverrideIf you "sanitize" Unicode you're just removing that functionality. Remove that character, and the right to left reversal wont' be there, right?
If you have to break it in the name of security and sanity, it shouldn't exist in the first place.
I am continually baffled about why the HN comment sections are such a hotbed of anti-unicode sentiment. Perhaps most of y'all don't have to write software that deals with non-English text in any significant way.
If you just didn't have buffers you wouldn't have to avoid buffer overflow attacks! Come on.
Yes, this aspect of SQL is poorly conceived because the only way is to manipulate it with text processing.
Parameters should be inserted into a query language using AST manipulation, like a Lisp backquote.
Now within a particular program, we can wrap something like that around SQL generation, and solve the escaping problems in one place.
That approach doesn't apply to character data, which has to be literal and primitive in many situations.
The general answer is to not allow (e.g., ignore it, remove it, but do not render it) in any identifiers, filenames, domainname labels, usernames, and other security-sensitive strings, U+202E between characters of scripts that are not bi-directional and which flow in the same direction. More generally, do not allow mixing of scripts in certain contexts -- for example, do not allow mixed scripts in a single domainname label. Some of these rules need to be implemented by, e.g., DNS registries, and may need to be tailored to their specific needs (e.g., you might find that .kr has to allow mixing of ASCII letters and Hangul characters because it's common in South Korea to add "ing" to names to make brands out of them).
UTR #36 doesn't go far enough, in my opinion.