661 points · by ambuj · 13y ago · 236 comments
One developer at this company, who was annoyed with having to tweak a particular system every time they added a new possible status flag, wrote code which was, essentially:
if (InternalStringUtils.isAllLatinCharacters(employee.getJapaneseName()) {
/* no need to pay this 'employee' so remove them from batch
before we retrieve bank details for salary transfers */
...
}
Do I have to explain why I'm aware of this curious implementation choice?Japanese of Korean descent can also choose Kanji names I think, to use as legal aliases.
InternalStringUtils.isAllLatinCharacters("Patrick McKenzie") == trueThe org had 380K active entries, so it was definitely interesting being a dev on such a project, with a relatively common name, and conflicting dob and last 4-5 of my ssn.
The reason I ask is because rules like this are often used to de-duplicate records. It's not perfect but it is useful, especially when trying to integrate data from more than one system. It's also used quite a bit in fraud detection etc. to find connections in the data.
If you drop 380k users into 3.7M buckets, that's only ten times as many buckets as users. A lot of the buckets will be shared.
Japanese systems have wide, wide variability in what they do for 漢字名 for people who, ahem, don't have one. Some repeat the カナ名. Some do so but use half-width kana (半角 vs. 全角). Some managers who believe that there is such a thing as an "official name" think that one's official name should go in 漢字名, regardless of whether it is 漢字 or not.
A related problem: what happens when you have two systems which have different behaviors on this? For example, let's say you're a Japanese bank, and your branch employees were instructed in 2012 to update any 漢字名 of foreigners to be the name written on their foreigner registration card, in double-width characters. Let's further suppose that your web tier does Javascript validations when you try to sign up for online banking, and because any engineer can see that DOUBLEWIDTH latin characters are not 漢字, this means that it is literally impossible for the web tier to match the DB for affected customers.
Hilarity ensues.
There is an "official name" and it's on your registration certificate. That's the one that goes in the 漢字名 field and that's the one that the bank will accept (my registration had both the double with latin character and the katakana in parenthesis: no questions asked, they both go, parenthesis included). The validation of the kanji name is not done on the exact range of the characters ('is it really a kanji?') but if it's double width or not, double width latin characters are OK, you could use emoji the validation would pass. Half width katana would get rejected.
Protip: if you have a shitty registration name, have it change, that's easy and that's for you own good.
I once tried to apply for a Japanese credit card online about 10 years ago (certainly things have changed with some banks sine then). IIRC the form would not accept romaji and my kana name was too long for the kanji input field.
This was painfully frustrating at the time but helped frame my approach to forms and DB specification when I got into web development (e.g. always using UTF8 in MySQL, full name as a single field in some applications, etc.).
http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-b...
If you try to validate names, or if you don't safely escape names along with your other user-input strings, you're gonna have a bad time.
My given names in English are Mark Jason, and that's on my birth certificate. In Greek, they're Μάρκος Ιάσονας, which are the equivalents, and that's on my municipal birth records there (registered as a foreign birth at the time of baptism). There seems to be a move towards wanting to use "accurate" transliterations, though, rather than the more traditional method of translating names to equivalents (Mark<->Markos, George<->Georgios, Paul<->Pavlos, etc.). Sometimes people desire that: maybe someone named Михаил in Russian really doesn't want to be turned into Michael, but wants to go by Mikhail. That's fine, if they prefer. But in my case, I consider each of these translated forms to be my name in the respective languages, and do not consider the transliterated forms to be my name.
But in trying to sort out some paperwork, it appears that what I am supposed to do is one of these two things: 1) change my name in English from Mark Jason to Markos Iasonas, the transliteration of my Greek name; or 2) change my name in Greek from Μάρκος Ιάσονας to Μαρκ Τζέισον, the transliteration of my English name. But I don't want to do either of those things. #2 in particular is ridiculous, because it doesn't decline properly, and is trying to approximate a 'j' sound with 'tz'.
CSB: My mom signed me up for a book club when I was 6 or 7. For the Firstname field, she wrote, "R Edward" for reasons known only to her. For the next three years, every couple months, I'd get a package addressed to Redward <Lastname>. I could just imagine the shipping clerk in that company reading my shipping label and saying to himself, "Redward... what a goofy name."
One example: Many years ago I subscribed to TIME and filled out a form where I checked "Mr." Apparently the person who typed in my name decided to "correct" this error and I became a "Mrs."... and I wasn't even married :-)
The company I work at has offices in different cities, so most of the communication are done by email and instant messaging. I see a clear difference between the messages from people who know my gender, and those who probably think I'm female. Even attempts at flirting...
Not to mention it casts serious doubt as to your organic nature.
To compound the problems caused by this, I switched to using my first name as my primary name around the same time as I switched coast. People on the east coast know me as my middle name, people from the west coast know me as my first name. This can come in handy sometimes as it gives me a very quick indication of where I know somebody from, but gave me a good deal of trouble recently at a west-coast wedding with lots of east-coast people attending... The fact that some of my friends were introducing me to other people with just my last name made it quite... interesting.
Except now when I go to networking events or interviews, I tell people my middle name L* and then they point that out that my name tag or application says my first name is M* and I have to go through the whole song and dance of explaining the situation.
I'm frustrated enough to be looking into getting it legally changed. You might want to consider that as well if only to not have to deal with those phone calls any more.
I kid you not, at his wedding when the celebrant said, "Do you Susan, take this man Brian..." his bride exclaimed, "Who's Brian?"
Speaking of which, why don't all companies just move to automated support systems already? These guys are doing it right http://www.zocdoc.com/
It is Hélder Maurício Gomes Ferreira Filho
Common reasons for failure is being too long and having non ASCII characters, but sometimes it fails for other reasons, for example do not allow me to register without a middle name ( I don't haven't one actually... ), me confused and not knowing how to register Filho ( it is not a family name, neither a surname or a last name, but it is still part of my name. It means Son, my father has the same name as me, without the Filho part), or breaking when it cross check with somewhere ( for several reasons I ended registering my name in several different ways, usually omitting Hélder, that I did not even knew was on my name until I got to school and got forced to use because of stupid rules that assume your first name is your typical name )
Interesting, that's similar to Junior in the US, but there it generally isn't part of the "official" name, only informal.
Accented vowels are ASCII characters but in the extended set which people sometimes don't take account.
By contrast, there were national variants of ISO/IEC 646 (also a 7-bit character set, and essentially the internationalized version of ASCII) that included accented characters within those 128 code points. Generally these swapped out things like the at-sign (@) and the curly braces and vertical pipe character for accented vowels instead.
There were also lots of 8-bit character sets in ISO/IEC 8859 (e.g. Latin-1, or ISO/IEC 8859 part 1) that included accented characters within the "extended" set of code points 128-255.
ASCII is the 7-bit encoding ANSI_X3.4-1968, composed of 95 printable and 33 control characters.
I love how sometimes even on the same company, each place account ASCII differently.
I remember registering for a IM, and in one info screen my name was Maur&cio and in the site info screen Maur€cio and in the search screen was Maur£cio and so on...
(also we have "Neto" that means Grandson, it is quite popular, I know a bunch of guys like that, I don't think dro down boxes in other countries will expect that)
The thing is Dutch...
I am Hélder because of my father.
He is Hélder, because of the priest "Dom Hélder Câmara" (my Grandma was very Catholic)
Dom Hélder Câmara was named after the city of Den Helder in the Netherlands: http://en.wikipedia.org/wiki/Den_Helder
The result is kinda wonky (lots of people write it wrong, usually "Elder" that of course resulted into video game savy friends nicknaming me "Mr. Scrolls")
If text is truly free form then you don't need to validate or white list anything. Just make sure it's valid UTF-8 (or whatever encoding you're using) and escape it when you display it. That combined with using prepared statements with bind variables (aka named parameters) and you don't have any issues with user inputs.
One other benefit of this approach is that you end up with proper i18n support without doing anything special. From your apps perspective all text is the same. If user's want to use unicode characters or put html tags in their descriptions then let them. If you escape it then there's no XSS issue. Plus it's WYSIWYG[2] from a user's perspective.
Who am I to judge that a user putting "<script>alert('Haxors!');</script>" as the name of an object is a bad idea?
[1]: "Names" don't include usernames which generally should have a whitelisted character set (ex: ASCII [a-z][a-z0-9+]) or email addresses (use a a real validator ... not a regex!).
I've lately been coming around to the belief that anyone who uses the term "sanitize" in this domain, as in, "sanitize user input" really doesn't know what they are talking about (at least on average). The approach you describe is the generally correct approach; you need to ensure that the proper levels of escaping are being applied. Unfortunately this is nontrivial in practice, but it's still the correct solution.
The "sanitization" meme has resulted in me smacking down at least 3 commits from developers in my organization trying to "solve" XSS by scrubbing out all less than characters across all input from the user, or eliminating all quotes, apostrophes, less than, greater than, backticks (for shell interpolation problems), etc etc. Unfortunately, the problem is, these are in general all perfectly valid input values, and some of them really smack you in the face immediately. (For instance, names may contain apostrophes. You can't "sanitize" them away; you need to write your SQL layer to handle that correctly, such as with binding.) You handle them by managing your encoding layers correctly, not by "sanitizing" them.
(There's still some sanitization components in the resulting solution, I just don't think they are the way you should think about it. For instance, there are some characters that are flat-out forbidden in, say, an HTML attribute, and the right thing to do is just strip them out of any incoming string. But that should be thought of as a "sanitization" step being a importent element of proper encoding, but not the actual "answer".)
I've had this view for a long while. I think there's a common sense to it that either clicks or it doesn't. Plus people hear/read "escape your inputs!" so often it becomes a cargo cult.
> You can't "sanitize" them away; you need to write your SQL layer to handle that correctly, such as with binding.) You handle them by managing your encoding layers correctly, not by "sanitizing" them.
Exactly. Whitelisting the values that can be stored in field should be done to maintain the data integrity of the field. It's not an approach to solve security problems or prevent SQL injection.
> For instance, there are some characters that are flat-out forbidden in, say, an HTML attribute, and the right thing to do is just strip them out of any incoming string. But that should be thought of as a "sanitization" step being a importent element of proper encoding, but not the actual "answer".)
We ran into something like this in our app as well. When displaying meta data for an object we create related objects in the dom and reference them by id. Originally the ids were generated by simply escaping the name of the raw object but that doesn't work because as you mention there are additional restrictions on what can be used in an "id" field. The solution? Hash it! Obviously that's a very specific solution as we only cared about it being unique and tied to the other object on the same page but it worked.
Maybe you will output a data dump for someone else to print mailouts. Or you'll share the user database with a vendor's web forum. Or payment processing. Or any SaaS.
Unicode lets you represent lots of abstract characters, from different languages and societies, in one character set. That doesn't quite tell you how to render the characters. For that, you need to know what language the text is in. Unicode wants you to provide that information out-of-band, e.g. in an HTML "lang" attribute, which the renderer can use to paint the proper glyphs.
For example, the Arabic digits 4 through 7 (۴ U+06F4 .. ۷ U+06F7) have different glyphs in Persian, Sindhi, and Urdu. And a character like 直 (U+76F4) has Chinese and Japanese glyphs that may not be mutually recognizable.
Bottom line: if you want an internationalized system that can store and render multilingual text, storing the text in Unicode is a good start, but you will need to store additional info (like the language) to be able to properly render the text.
You probably need to know the language to do things like sorting, comparison, regex, etc. But if you're just storing and displaying user-entered strings and your software has no need to understand the meaning of the strings, I think it's enough to do what the parent says.
If you can't use a regexp to recognize the general case of email addresses, no finite automaton can..
This is what a proper email-validation regexp looks like: http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html
Not XSS, but you need to be careful about allowing through things like the LTR/RTL override characters.
Similar example: Do you lock your door, or does that make no sense to you? (Because if there's no absolute, perfect, 100% protection, there's apparently no difference at all between locked, closed and wide open; right?)
The article is pretty entertaining - it talks about him becoming semi-famous and getting pulled over because cops wanted their picture taken with him: http://articles.latimes.com/1986-06-23/news/vw-20054_1_licen...
The comp.risks article (where I originally read about this) is also amusing: http://catless.ncl.ac.uk/Risks/6.45.html
[1]: http://www.huffingtonpost.com/2012/02/16/no-tags-meet-sauced...
http://www.thesmokinggun.com/documents/florida/assorgy-story
For some reason Florida plates use 2 oranges now...
They never told me what the bug was, only that they fixed it. I have some idea though.
SOAP is maybe the most popular example and this is really why it's lost popularity against REST. However, similar "It works with values W, X, Y, but not Z" situations are found in any stack or standard that has too much magic going on. Rails certainly comes to mind.
This is the biggest argument in favour of using many small, isolated components rather than one big all-encompasing framework, in my opinion. If every piece of third party functionality you import into your project can be easily understood, problems like these shrink in size, because there's a limit to how deep the magic can go.
I'm very fond of the Node.js ecosystem for particularly this aspect (even though I dislike the language). There's a big bucketload of tiny components there, rather than 90% of the community relying on a single humongous framework, like is common for e.g. Ruby or C#.
In this case, the flex framework is handling the marshaling/unmarshaling process incorrectly, but these are not simple problems. Handling things like names, or dates is deceptively difficult.
>There's a big bucketload of tiny components there...
Are you sure that's a good thing? First, anything works when you have a small code-base, and a significant portion of JavaScript ecosystem involves building fairly small self-contained applications. I have a strong feeling micro-frameworks fail hard when the line count gets over a certain threshold.
I know it probably wasn't this guy's choice, but whooo boy.
I can't speak much to ColdFusion or WSDL though.
Of course since Adobe has all but abandoned the platform, it probably won't be much of an issue in the future... Kind of a shame, as Flex was actually pretty nice. If adobe was more open with the flash client as a platform, and focused on the tooling (where they make their money), it could have been integrated into browsers, and had a much better chance of sticking around.
It's a real shame, since the closed source aspect of Flash really led to a brain drain within the community. Flash for many years was the superior platform for making complex web applications, but sadly, it did not have the community and brain trust that more open standards did, like HTML and javascript did. In the long run, this led to serious stagnation with the platform.
[...] the value of types is super super important. [...] Everything that is syntacticly legal, that the compiler will accept, will eventually wind up in your code base and that's why I think that static typing is so valuable because it cuts down on what can kinda make it pass down there. I'm only getting stronger in my stands on static typing, static analysis.[...] - John Carmack, qcon keynote 2013
ActionScript 2 was a lot more like Javascript than ActionScript 3 is.
Now, I'll admit, SOAP anything is crazy, but based on the age of the application, may have been the best option at the time.
Falsyness is used in boolean-ish contexts (if, while and explicit boolean conversion), by default all of None (null), False, 0, 0.0, "" (the empty string, unicode or binary) and empty collections ([], (), {}, set()) are falsy and although UDTs are "truthy" it can be overridden.
This has nothing to do with making the distinction between ints and strings. You could actually implement the same thing in e.g. Haskell (by creating a "Booleanish" typeclass and implementing it on all the types you care for).
edit: please note that — in Python — 0 (the integer) is falsy but "0" (the string containing a single character 0x30) is truthy. I expect gtaylor talks about bugs in handling of IDs or sequence numbers and the like, not usernames. I know I've hit them when not being very attentive.
I have a photo of the receipt at http://www.righto.com/2008/05/importance-of-software-testing...
Obviously if your lookup app is having a problem with using "Null" as a string then you have data type issues.
It's not rocket science.
XML is a terrible encoding for data. Fortunately JSON does pretty well and has mostly replaced it for new stuff.
(a) standards
(b) poorly implemented standards
(c) poorly implemented programmers :-)
For example:
<elem>Null</elem> - element equal to "Null"
<elem/> - empty element (can also have a nil attribute set to true).
A lot of problems like these are down to programmers that try to fix bugs by fixing the symptoms.
You could Kickstarter the money with donations from database admins around the world.
First, many computer systems here can't fit names that long, leading to truncation, or in some cases, denial of account creation (some places have rules that whatever's on the account must match exactly what's on the passport; one was nice enough to add a new column to their database for the rest of my name).
Second, many systems don't support a-z, so we throw the name in as katakana or double-byte romaji, depending on what works. Sometimes neither will work, and we just have to give up and go somewhere else.
Finally, many computer systems can only link accounts if the names match exactly, for example inter-bank transfers and bill payments. Since my name is truncated differently in different places, and is formatted differently in different systems, in many cases it's just impossible.
For example, right now I'm charged a fee for transferring money between two bank accounts, since the free transfers only apply if the names match exactly. I just withdraw cash from one and deposit it into the other as a workaround.
Another example is my cell phone bill. To pay it by CC my name must match exactly, but all my cards have slightly different spellings.
Don't even get me started on my wife, who is ethnically Japanese but came with me as a foreigner and hence has a name written using a-z letters. It literally has set of fraud detection systems.
XXXX XXXX YYYY ZZZZ
The Visa papers does not support 'large' names.. So he has to abbreviate..
Imagine this guy has the same last name and first name of FBI wanted list.
Now, after sep - 11 everytime he has to go to the 'vip' room at border and there is large confusion as visa papers do not 'support' longer names...
This is US...
Not complaining but can the Prism people flag work it out ;)