6 ms·
Whatever you may think of `null` (ahem https://en.wikipedia.org/wiki/Tony_Hoare#Apologies_and_retractions https://en.wikipedia.org/wiki/Tony_Hoare#Apologies_and
by eyelidlessness 10y ago
Whatever you may think of `null` (ahem https://en.wikipedia.org/wiki/Tony_Hoare#Apologies_and_retractions https://en.wikipedia.org/wiki/Tony_Hoare#Apologies_and_retra...), it is not a string type. It is horrifying to me that all of the problems described in the article are cases of allowing a user to execute arbitrary code by string input, and the article fails to point this out.
- martinko 10y agoType coercion does not necessarily imply the contents were execute as code.
- eyelidlessness 10y agoI'm not aware of any language that coerces the string `'null'` to the value `null`. Are you aware of any?
- DougBTX 10y agoA badly coded website could go in the other direction, eg in JS, someone writes a poor string equality check: function normalise(s) { return (s + "").toLowerCase(); } function isEqual(a, b) { return normalise(a) == normalise(b); } And then someone else uses it in some form validation logic: if (isEqual(surname, null)) { return error; }
- jerf 10y agoThen as the next step, some programmer somewhere notices that all the NULLs in the database have been converted into strings somewhere, and puts UPDATE table SET column = NULL WHERE column = "NULL" somewhere, maybe even in a trigger, and that's that. The problem with data destruction is that only one thing in the entire data pipeline has to spuriously map two distinct values to the same output value, and the data is destroyed and can not be recovered. Very few programmers think carefully about whether a serialization or data transfer format maps every single possible input to a different output. It may only take one oversight to ruin your year.
- DaiPlusPlus 10y agoJava and JavaScript do the opposite: null values are represented by the string "null" ( http://stackoverflow.com/questions/24591212/why-the-coercion-of-null-string-to-null-string http://stackoverflow.com/questions/24591212/why-the-coercion... ) - it's conceivable many programs processing strings would assume "null" in a string comes from a null value originally.
- nilved 10y agoYour inaccurate description gave me a small heart attack. We all know JavaScript is horrible, but that is next-level horrible. null is coerced to "null" when it's needed as a string. This behaviour is similar to printf in C. It's not the case that "null" === null like True == 1 in Python. (This would be my interpretation of "x is represented by y".)
- throwanem 10y agoIf you want 'next-level horrible', open your browser's console and take a look at what you get back from "typeof null".
- valleyer 10y agoJavaScriptCore: >>> typeof null object >>> typeof "null" string >>> typeof (null + "") string
- menssen 10y agoSomething always bugs me about this criticism: #1 arguably makes sense. Unless "null" were a "type" (which it isn't), the other possible options for this ("undefined", or "string", "number", "array", etc.) all make less sense. #2 is expected/correct. #3 makes sense if you accept that the "+" operator aggressively casts its arguments to strings when they are anything other than two numbers. Arguably that's a bad design, but it's not unexpected or unpredictable. The one completely unexplainable "+" behavior I know of in JS (i.e., a recent node/v8) is the second of these: > [] + {} '[object Object]' // makes sense because the string representation of [] is '' > {} + [] 0 // ??? > var x = {} + [] undefined > x '[object Object]' // but assigning to a variable first makes sense again
- saurik 10y agoIt tends to not be in programming languages but in textual data formats (including many standard implementations of comma-separated files) and even databases that can only hold string values by nature but also want a way to represent null (and fail to fix this by escaping the hell out of everything with quotation marks, and yet it isn't that "code" is executing).
- adzicg 10y agoColdFusion does. There was a famous stackoverflow thread on that "We have an employee whose last name is Null. Our employee lookup application is killed when that last name is used as the search term (which happens to be quite often now)" http://stackoverflow.com/questions/4456438/how-to-pass-null-a-real-surname-to-a-soap-web-service-in-actionscript-3 http://stackoverflow.com/questions/4456438/how-to-pass-null-...
- esrauch 10y agoRails at least used to do this when reading back from a database (eg if you had a nullable string field it would come back as nil if it happened to be the literal "nil") Edit: IIRC there was a directive that would prevent the behavior though?
- hoahluke 10y agoSeems far more likely to be type coercion, or over enthusiastic validation, rather than arbitrary code execution.
- deleted 10y ago[deleted]
- mcherm 10y agoIt is also security policies put together by overly cautious people. They say "I can't trust our developers to write properly secure code, and it won't hurt anyway so I'll just institute a blanket policy to block everything that might appear in an SQL injection attack. Let's see... we'll block quotes, ";", the word "null"... maybe a few more things."
- eyelidlessness 10y agoThis is also horrifying, as it indicates that they're taking wildly destructive precautions but still putting user input into SQL queries.
- kedean 10y agoI don't think the suggestion was that the policy is created because the data is going into sql queries. The policies are often in place because the people in charge of the policy flat out don't trust the developers. Say the policy comes out of the CTO's office, they have two options: 1) liberal password policy, risk a crappy developer screwing up, or 2) conservative policy, not have to worry at night.
- Buttons840 10y agoSlight change of topic here. Your comment made me realize that once a system gets too complicated the only change that can be made is to add more complexity. In this case. It would be better to ensure all SQL is properly escaped, but because that isn't a trivial task, instead you end up adding another layer of complexity.
- flomo 10y agoRight, and in larger organizations, the "they" are two completely different groups of people. My current situation: Developers in City A are expected to use secure coding standards. But the IT group in City B, halfway across the country, installs a intruder-alert proxy which blocks urls which might contain HTML or SQL. The CTO is probably too busy playing golf with Oracle salesfolks to care, everyone is just looking after their own end of the business.
- iopq 10y agoNo, it might be a conversion from a database to CSV that's doing it or something similar.
- InclinedPlane 10y ago"Types", sounds like someone doesn't understand dynamic languages, which are some of the most popular languages today.
- eyelidlessness 10y agoSadly, all of my professional work to date has been in dynamic languages. They still have types, and `null` is still not `"null"`. Edit: whoops, forgot the one time I wrote a one-off Mac app in Swift.
- InclinedPlane 10y agoI was kinda sorta being sarcastic, though that kind of thing is a big problem in dynamic languages. Javascript has the concept of "truthy" values of ... whatever rather than a simple boolean type. Realistically this particular problem is not due to dynamic languages per se. Most likely it's due to some stage of a process where data was serialized/deserialized without sufficient care. In general it's more of an "in band signaling" problem.
- eyelidlessness 10y agoTo be more clear than my previous response, I am well aware that dynamically typed languages do all sorts of nonsense, but nearly none of them consider this `null` to equal `"null"`, certainly not the widely popular ones. Side note: please refrain from "sounds like someone doesn't understand". It is extremely condescending, dissuades discussion by most people whether they actually know the topic or not, and can be especially deflating to people who are less educated but currently learning. If there is something that you feel I misunderstood about the way popular languages treat the string `"null"`, feel free to explain it (there are many other response comments I've gotten that are good examples). But if the purpose of your comment is to make me or anyone else feel ignorant, please just keep it to yourself.
- borski 10y agoI strongly believe parent was being sarcastic.