News for hackers. Stuff that matters.
Re:That people produce HTML with string templates is telling... by ngneer on Friday May 26, 2023 @10:19AM (#36084507)
I was hoping to see an explanation for why the pattern is prevalent, but the author does not know.

"One of my fundamental rules of system design is when people keep doing it wrong, the people are right and your system or idea is wrong."

I am not sure under what circumstances this is true, but for security it is definitely false. People keep forgetting to sanitize inputs, for example. Does that render input sanitization a broken idea?

Re:That people produce HTML with string templates is telling... by ncallaway on Friday May 26, 2023 @10:28AM (#36084621)
It’s actually a critical concept for security contexts.

If everyone forgets to sanitize input, that means our current processes are fucking broken.

I like to imagine if this excuse happened in aviation how it would sound.

“Everyone forgets to put down landing gear before landing, so does that mean landing gear is a bad idea?”

No, but it does mean the process for landing is catastrophically broken, and needs to be overhauled. If that happened twice, we’d implement strict rules around landing like checklists with standardized procedures to have a second person verifying that the process was followed and each task was accomplished, and defining a “sterile phase of flight” where talking about anything other than the landing process was disallowed.

So, input sanitization isn’t a broken idea, but the fact that it keeps going wrong clearly demonstrates that out process and culture around security are catastrophically broken.

Re:That people produce HTML with string templates is telling... by ngneer on Friday May 26, 2023 @10:43AM (#36084845)
Presumably pilots know to do that?

I absolutely agree that psychological acceptability is key for building secure systems, and that the human factor must not be neglected. I also agree that process and culture around security are deeply broken. I just do not agree with the idea that if all are doing it, there must be some deep truth beneath. Yes, people habits must not be ignored, but to claim that an idea that goes against those habits is wrong, as the author claims, is inaccurate.

Re:That people produce HTML with string templates is telling... by JohnFen on Friday May 26, 2023 @11:11AM (#36085217)
> I just do not agree with the idea that if all are doing it, there must be some deep truth beneath.

I think it does say that there's a deep truth underneath. That deep truth is that the "correct" way is not good enough.

The way that it's not good enough may very well be that it doesn't mesh well with how people work or think. That aspect is as important as any other aspect of design.

Re:That people produce HTML with string templates is telling... by ngneer on Friday May 26, 2023 @11:34AM (#36085525)
Interesting viewpoint. I can see why it indicates the "correct" way is not easy or foolproof enough, but this is all it says. Ease of use is certainly an important aspect of design. I just think "not good enough" and "wrong" are two different things.
Re:That people produce HTML with string templates is telling... by JohnFen on Friday May 26, 2023 @01:48PM (#36087448)
Well, I think that if something is "not good enough" to the point where people actively avoid using it, that elevates it to "incorrect".
Re:That people produce HTML with string templates is telling... by ngneer on Friday May 26, 2023 @04:53PM (#36089384)
Like seatbelts once were?
Re:That people produce HTML with string templates is telling... by lelanthran on Friday May 26, 2023 @03:42PM (#36088675)
> I just do not agree with the idea that if all are doing it, there must be some deep truth beneath.

Hypothetically, lets say you design a system that, for every legitimate 1000 users accessing it, 999 fail to understand it enough to gain their legitimate access.

Would you still be comfortable telling the people that paid for the system that it's not the system that's wrong, but the users?

Re:That people produce HTML with string templates is telling... by ngneer on Friday May 26, 2023 @05:04PM (#36089489)
That is for sure a broken system. I would not feel comfortable telling users they are wrong, even if the numbers were 10 out of 1000 or less. But we might be talking about different things. I gave the example of developers building a hopefully secure system, not users using it. If your point is that developers are users of languages, and that 1 in 1000 succeeds in building a secure system, then indeed languages are broken. But are you really arguing against input sanitization?
Re:That people produce HTML with string templates is telling... by lelanthran on Friday May 26, 2023 @07:01PM (#36090460)
I'm not arguing against input sanitisation, I'm just arguing (rather poorly, it seems) that if the majority of folks are skipping some security feature, then the feature is not well enough designed.

I'm for input sanitisation, I'm against having it optional and left up the the developer.

Typing on a phone makes me unnecessarily brief, apologies.

Re:That people produce HTML with string templates is telling... by ngneer on Friday May 26, 2023 @07:10PM (#36090516)
Ah, that we agree on!
Re:That people produce HTML with string templates is telling... by Brian_K_White on Friday May 26, 2023 @10:30AM (#36084653)
Yes. Or rather it means that requiring people to remember to do it is wrong.

Maybe it's not possible to do any better (no magic language that can tell what a given string of bytes will eventually be used for) but that doesn't change the fact that the reason inputs don't get sanitized is because the system requires an unreliable component to be reliable.

It's also a bad example because it's not really a choice (no magic language).

Re:That people produce HTML with string templates is telling... by ngneer on Friday May 26, 2023 @10:51AM (#36084964)
I agree, it is akin to requiring people to come up with high entropy passwords, another "brilliant" idea. However, the fact that there is no other choice and no magic language is what makes it a good example. Input sanitization is an oft-cited requirement because machines cannot (yet) do it for us. While it is not a great fix and people often get it wrong, it can be likened to a pilot checklist, to piggyback on another comment. No one says checklists are bad ideas, we all know humans tend to be forgetful.
Re:That people produce HTML with string templates is telling... by Brian_K_White on Friday May 26, 2023 @05:36PM (#36089790)
I like the pilot checklist concept as an example of a way to address a problem when there can be no magic automatic way.

It's a different way to address the problem of the unreliable component than just requiring it to be magically reliable, or replacing it with something else that's reliable (automation, ie magic compiler or runtime), by adding procedure and redundancy and cross verification so that the final output is reliable even though all the individual worker parts are not. It's just ECC in human scope.

So I guess you're right that it is an example of the article's assertion that "If people always do something wrong, that is evidense that there is a system in place which results in people doing that thing wrong, and that system is wrong."

The system is the overall norms of software development, and the wrongness is that it doesn't include something equivalent to a pilot checklist culture around the important bits, even though everyone knows that those bits are important, and knows that humans are unable to be reliable.

Re:That people produce HTML with string templates is telling... by ngneer on Friday May 26, 2023 @06:56PM (#36090427)
I really like your analysis, spot on. Including the viewpoint that a checklist is a human scoped form of redundancy, allowing us to build reliable systems out of unreliable components. While there is nothing that can force the human to check the checklist, having it in place reduces the risk by an order of magnitude. And one can always seek extra assurance if called and budgeted for.

Definitely sucks that overall software development norms do not take more care to protect the important bits. Hard for the market to reward secure designs, because the effects are latent, because the competition is not any better and everyone claims their product is secure. If a market required data showing security and if the security industry came up with cheap effective solutions, things might be different.

I do not view the system that birthed the checklist concept as being flawed or wrong, though. I agree that if people always do something "wrong", then it requires close scrutiny. It is just that different systems have different requirements and levels of redundancy. The checklist came about when people realized that humans make costly mistakes without one. Same deal for input sanitization (which many on this thread are not liking). OWASP is of the opinion that input sanitization is worth mentioning, but they would probably agree the whole thing is broken...

https://owasp.org/Top10/A03_2021-Injection/

Re:That people produce HTML with string templates is telling... by Brian_K_White on Saturday May 27, 2023 @12:53PM (#36096196)
"While there is nothing that can force the human to check the checklist"

That's why there's also the buddy system, procedure aka habit aka ritual, and culture aka the pressure of norms.

No single thing guarantees much, they are all just pressures that some people are immune to, or some can't always be applied (buddy system requires buddies), but they do all have their statistical effect, and the more of those you pile on, the less likely it is for something to make it past all of them.

Say someone is a total lone wolf, not part of any teams or communities, utterly immune to shame from not conforming to everyone else's expectations, the system still works because everyone else shuns their work because it came from such an unhygenic source, or, they take on the job of doing what the author didn't, because one way or another they simply can't be seen using dirty software in their own work. They either don't use it or they launder it themselves.

At least, I assume it's diffucult for a total cowboy scofflaw unsafe pilot to get a job doing any piloting that matters anywhere. I bet even the military demands people be in control of their intentiinal crazy unsafe flying.

Not just because of any rules but the entire culture made of the entire rest of the population that you can't buck individually.

And we do actually have a little bit of this in some, maybe most companies, where developers generally don't push code directly to production but must pass through at least one other reviewer to merge. But the company as a whole gets to do whatever they want in private, and they don't do that same sort of auditing on all the stuff they use that came from elsewhere, and thst's only big companies which are still probably a minority of all developers and projects. Even if I'm part of such a culture at work, I'm still not the rest of the time unless I choose to be.

Re:That people produce HTML with string templates is telling... by Brian_K_White on Saturday May 27, 2023 @01:18PM (#36096427)
I wonder if it's really not possible to do some automation.

Could a compiler or static analyser not work backwards from execv() params?

I guess it's not as simple as that because really all functions matter not just the exec/system ones. Anything that merely reads or writes memory at all, could be used eventually to disclose a secret or alter behavior. Without ever doing something as obvious as executing a shell command, I could maybe change the address to a function, causing the function to behave differently, skip some bit of important logic that sometime later in some totally unrelated process allows me permission to access a file or interface I shouldn't etc. In the end, I guess there is no function anywhere that doesn't matter, and so the backtraking process would just end up including everything. Not useful.

You would need a "mark of the web" bit of metadata attached to every single variable and block of disk. That would need to be baked in to the hardware platform as an extra bit. Everything on the motherboard, ram, cpu, storage everything is 9 bits instead of 8, with 8 payload and the 9th is the tainted mark. Not just every byte of memory, but every part of everything. The disk bus has the extra bit for the data, all the disk access instructions include the extra bit, every cpu register, every address the address itself as well as the data at the address, etc... These could all be 65 bits for 64 instead of 9 for 8, but only if the platform was made incapable of operating on anything less than 64/65 bits. 64/65 would have to be the fundamental "char" for the platform. Even then, I bet it would all have to reslove out to every byte or word ends up having that bit set for one reason or another. Ultimately 100% of the data comes from outside and comes from people, or was somehow derived from data that did.

Though maybe we would simply artificially bless certain data even though it is software or firmware or data that humans wrote and loaded in, and use that to keep track of the rest in a more useful way.

Re:That people produce HTML with string templates is telling... by Brian_K_White on Tuesday May 30, 2023 @03:49PM (#36129693)
... then today https://www.bsdcan.org/events/bsdcan_2023/sessions/session/1...

Somewhat different plan, more like, ACL-in-hardware but similar idea having hardware that tracks extra metadata bits every step of the way and at the lowest levels.

Re:That people produce HTML with string templates is telling... by guns on Friday May 26, 2023 @10:25AM (#36084580)
> People keep forgetting to sanitize inputs, for example. Does that render input sanitization a broken idea?

Possibly. You could prevent careless use of unsanitized inputs with a type system. Fail-safe designs should be more common.

Re:That people produce HTML with string templates is telling... by praisewhitey on Friday May 26, 2023 @11:58AM (#36085866)
A system that requires users to sanitize inputs is indeed broken. System designers should make sure the system handles sanitation and not the end user.
Re:That people produce HTML with string templates is telling... by jandrese on Friday May 26, 2023 @02:27PM (#36087912)
This is a crucial failing in far too many security products. They see buggy instantiations of their API all over the place and start ranting about incompetent developers instead of asking themselves why otherwise smart people are struggling to use the API.

The developers aren't all idiots, they are following your incomplete documentation and using the buggy and incomplete example code you provided. Or they are using the buggy example code they found online because you didn't provide any. If your API isn't useful without first taking a college course on the problem domain then that is a problem with your API and probably documentation. The whole point of an API is to encapsulate the complexity and provide the user a tool they can use without having to first learn everything about it.

Re:That people produce HTML with string templates is telling... by ngneer on Friday May 26, 2023 @06:16PM (#36090147)
There are a lot of poor quality products out there, and security products are no different. They too follow a distribution. I am not sure why the parent comment uses the second person. I too find security products to be a liability sometimes, and, if an API does not deliver, will try to switch it out.
Re:That people produce HTML with string templates is telling... by lelanthran on Friday May 26, 2023 @03:39PM (#36088646)
> I am not sure under what circumstances this is true, but for security it is definitely false. People keep forgetting to sanitize inputs, for example. Does that render input sanitization a broken idea?

Well ... yes? If people are forgetting to do something that is required, then that something is explicitly needed.

Better to make that "something" implicitly added in the process no matter what the user does[1]. Or make the process break if the user "forgets"[2].

All difficult things to be sure, but easier than expecting the user to remember which of the 100 different NON-DEFAULT sanitation packages to install, configure and use, for output to HTML, SQL, JSON, Logs, and more.

If the language makes it easy to do, and there is very little blowback in terms of security[3], then users are gonna do it.

[1] Auto-sanitise strings, obviously. I dunno how you'd actually do this though.

[2] When running as a web-service, have Django/whatever-framework configure Python/whatever-language to emit warnings whenever string interpolation is used without any escape function.

[3] For HTML, the exploitation of string interpolation are few and far between; they're so rare as to be lost in the noise. Hence, users don't use it. For SQL, injection was a real problem, with the risk of getting pwned on string interpolation being close to 100% on a good day (and actually 100% on a bad day), and so users actually used the mitigations there were.

Re:That people produce HTML with string templates is telling... by ngneer on Friday May 26, 2023 @05:33PM (#36089755)
I agree with you that an automatic default implementation is far better than leaving it to a human. I also agree with your examples on where and when it could be done. Lamentably, security is not free. Input sanitization is required because programs exhibit data-dependent behavior (which is what makes them useful), that can cause them to do weird things when working with weird data. We mostly tend to "forget" to ensure our programs exhibit "correct" behavior for all data, but sadly no one else can do it for us.
Re:That people produce HTML with string templates is telling... by lelanthran on Friday May 26, 2023 @07:04PM (#36090474)
To be honest, I rarely forget about security, but I don't want to have to remember.

What I want is to have my runtime/framework/language drop me into the pit of success (a popular phrase, might even have it's own Wikipedia page)

Re:That people produce HTML with string templates is telling... by naet on Friday May 26, 2023 @08:02PM (#36090858)
It does actually render "making people remember to sanitize every input" a poor system, if everyone is forgetting to do so.

The input sanitization system could be improved by requiring sanitized inputs, reminding people that they need to sanitize inputs, automatically sanitizing inputs, etc. Clearly the current system is leading to a lot of insecurity.