Sadly, I have reached a stage at which there are very few languages I trust anymore to actually not explode in unpredictable manners when push comes to shove. Rust is one of them.
Meanwhile, safety in a web application is domain-specific, and there isn't much a language can do to protect you. There aren't really Rust features that directly prevent SSRF attacks, or HTTP desync. In fact, my experience assessing Rust (and Go) web applications is that they intend to reincarnate web vulnerabilities that went mostly extinct in Django applications years ago; for instance, I'm virtually never going to find SQLI in a Django application, but Rust web applications are somewhat likely to build their own SQL queries. This will shock and upset some Rust developers to hear (all the popular Rust SQL interfaces force parameterized queries! they're thinking), but it's true.
I like Rust, and write more Rust than any other language lately. I'd say the same thing about practically any modern language compared to boring old Django, which is the Volvo of web frameworks.
I have nothing much to say about reliability and do recognize that writing in Python or Ruby means that you're also writing ridiculous batteries of unit tests to verify basic things like whether your setters and getters work properly, because the language essentially makes you check your own typos. I'm only talking about security.
> Meanwhile, safety in a web application is domain-specific, and there isn't much a language can do to protect you.
There absolutely is. Rust's expressive type system is a more important feature than the memory-safety guarantees for general purpose programming. This has significant impact on the ability to express security constructs directly in the code. Witness, for instance, the widespread use of typing to distinguish unvalidated and validated user inputs, such as Rocket's RawStr type [0].
Applying that technique can mitigate SSRF attacks without even knowing the details. You can worry all you like about SQLI in Rust, but in the code I've seen it's no more a concern than any web app, and likewise it can be enforced in the type system in a way that sure seems superior to "hope the dev only writes boring Python".
I'd agree with the general premise that, all things being equal, the security of something that looks exactly like everything else is higher than some novel construct. But I strongly disagree that there's nothing a language can do to help developers write secure applications, and I'd suggest it starts with an expressive type system.
[0]: https://api.rocket.rs/v0.4/rocket/http/struct.RawStr.html
Similarly: it's not at all my claim that Rust is somehow more susceptible as a language to SQLI attacks! The opposite thing is true: Rust, as a language, is far better situated to deal with them, because of expressive typing. But that's what could be, not what is. In practice, ironic or not, if you implement the same CRUD application in circa-2020 Rust and in Django, the Rust application is more likely to have SQLI.
The point is that unlike kernel code or browser components, where memory safety is most of the ballgame and Rust is a real game-changer, web application security is domain-specific. The language and its runtime are much less important to web security than what gets built on top of the language. And right now, even though Python is an objectively inferior language, more of the domain of web security is built more carefully on Django than what's available on Rust.
As to your points about what patterns are more likely in actual practice, I can't speak to that; I've only seen a handful of Rust web apps. But the ones I've seen absolutely do use type-foo to keep things straight.
> The language and its runtime are much less important to web security than what gets built on top of the language.
That's a great point. I would highlight, though, that what gets built (and how likely it is to have bugs, which is also pertinent!) is directly impacted by the language and runtime, so the two questions can't be neatly separated.
In the long run, will most users be writing the guts of, say, a session manager to support their CRUD app? No, of course not, they'll just reach for some shared resource. Is it easier to be confident that the Rust implementation of that library has a lower incidence of bugs? Today, no, because for the Django version you can rely on the major real-world use as evidence of reliability, but in the long run, almost certainly. Is it easier to be confident that the usage of the Rust version of the library is correct? Absolutely, since the invariants can be enforced by the compiler.
I think we're mostly on the same page here.
Note that I'm not claiming that Rust is the solution to every problem under the sun. It just happens to be pretty much the sweet spot for problems I need to solve, which typically involve concurrency and/or distribution and/or new protocols and/or sophisticated graph algorithms and/or actual OS access.
I fully realize that some people love these languages. I've written pretty sophisticated applications in these languages myself (including video games), and they're definitely great for exploring ideas. But at this stage of my career, for applications that matter to me, I value the time spent maintaining code more than the time spent writing it, and I find that the balance that works best for me is to use a strongly, statically-typed language such as Rust.
YMMV
Now, Haskell or (modern) Java or C# are good languages, too, and they're by far not the only ones.
If you wish examples of the kind of features I need:
1. I pretty systematically need to juggle with many threads; 2. I very often need to juggle with many processes, with non-trivial interactions (i.e. actual protocols); 3. I very often need to access the OS; 4. I pretty systematically need to juggle with sophisticated data structures and algorithms (think graph matching algorithms, or dynamic trees of dependencies between ongoing tasks); 5. I regularly need to handle distributed applications in which pieces interact through non-trivial protocols; 6. I pretty systematically need to ensure that the event loop remains responsive. 7. Whenever I interact with the rest of the world (either the OS or as a web client or server), I want to be sure of which piece of data is sanitized and which isn't.
Of course, every single of these task can be achieved in any language. It just happens so that:
1. Rust has the best support for threads that I know in an industrial language. 2. and 5. Rust's type system is the best I know to express protocols among industrial languages. I hear that Ada's type system is just as good, but I don't know Ada, so I cannot compare. I hear that Haskell's type system is currently being extended with linear types, so I'll need to test-drive that, too. 3. While there are other languages that are at similar level as Rust for such things, I don't know anyone that is strictly better. 4. and 7. Any language with a strong, static type system is good here, including Rust and all your examples. 6. Great support for coroutines is really useful. Many languages have it these days, including Rust.
Once again, to clarify, I'm not trying to convince everyone to switch to Rust. I'm just answering the assertion that the only reason to use Rust is performance. That's certainly not the case for me.
https://devblogs.microsoft.com/dotnet/embracing-nullable-ref...
It's much more a safety that you do not crash, due to input, side effects, parallelism (locking) errors, mapping wrong types, derefercencing null in some edge case by accident, ...
Rust gives you a lot of guarantees here, that it is extremely fast is just the cherry on top.
So if you actually care about these things, rust might be really poor, because you are spending time fighting the borrow checker instead of thinking about the security surface area of your system, and the language is optimizing for speed in a domain where the bottleneck is usually the network.
Any GC language (Java e.g.) will give you that if you don't use C extensions.
And if you do use them Rust wont fair any better (or if you use libraries that use unsafe).
Yes, but that's the main allure of Rust. As for the rest (e.g. resource releasing, avoiding concurency issues, avoding not-exhastive mathces, injection, etc.), other languages have their own ways as well, including Java.
If those are your main concerns (and not also top-speed) I don't think Rust is worth the extra cost (learning slope, slow compilation times, single implementation, fewer libs and developer tools, etc).
Not really. That's often touted as the banner feature, but it's the expressive type system that really makes Rust a better candidate than, for instance, Java.
My main point in this particular discussion is that Rust has way fewer gotchas than most other languages used in the industry, including Python and JavaScript. Whether these gotchas are problems for your use cases, only you know. I know that such sleepless nights tracking such gotchas have killed my will to write and maintain large codebases in Python or JavaScript (or C++), at least for a few years.
Although I should make a point that those kind of remarks don't come from the core team.
Well, that's totally fine. To each his own. I push Ruby production code for 8 years now and I trust it.
Whoever pays the electricity bill?