News for hackers. Stuff that matters.
Re:Should random() be banned? by nicoburns on Thursday February 11, 2021 @01:09PM (#26105028)
React's dangerouslySetInnerHTML is indeed a good way of handling this kind of thing. Rust's `unsafe` is another example of the same approach.
Re:Should random() be banned? by andoriyu on Thursday February 11, 2021 @06:10PM (#26108749)
uhm no.

Rust's "unsafe" is a pretty bad name and completely different reasoning behind using it. It doesn't mark something as "dangerously unsafe, don't use", to a consumer it indicates "exercise caution" and to a compiler it just allows 5 things:

    Dereference a raw pointer
    Call an unsafe function or method
    Access or modify a mutable static variable
    Implement an unsafe trait
    Access fields of unions
The point of "unsafe" in rust is to highlight which area requires more human attention... not to discourage its usage.

`dangerouslySetInnerHTML` is literally dangerous and allows XSS if used with outside input.

It also is faster than the other variant. The same is true for `random()`. Both can be used when you know what are you doing to gain some performance.

Meanwhile, `unsafe` rust by itself is not different from safe rust in terms of speed. You have no choice, but to use it places it supposed to be used.

Re:Should random() be banned? by nicoburns on Friday February 12, 2021 @07:34AM (#26112960)
The point of `dangerouslySetInnerHTML` is also to highlight an area which requires more human attention. It's perfectly safe if you have otherwise handled escaping or validation of the content. It's just that you want to pay careful attention to that code to ensure that you're doing it correctly, whereas in normal React code you don't have to think about escaping at all because the runtime handles it for you.

Likewise `unsafe` marks areas where you need to be really careful that you upholding the safety invariants yourself, whereas in normal Rust code you don't need to think about that at all.

Re:Should random() be banned? by hyperman1 on Friday February 12, 2021 @06:04AM (#26112380)
Isn't this just part of the world view of Rust?

The word 'safe' in Rust has a very specific, technical meaning. 'unsafe' is simply code that is not automatically 'safe' in the Rust sense.

A non-Rust developer sees safe/unsafe and gets worked up, but that just means that he should put his rust-colored glasses [*] on.

This is not unusual in ICT, known for its colorful language. A non-ICTer hears 'black hat' and thinks about how cool and stylish the hat is. An ICTer hears 'hacker' and thinks about how cool and stylish the hack is.

[*] Thanks, Raymond!

Re:Should random() be banned? by setr on Thursday February 11, 2021 @06:06PM (#26108691)
I don't think rust's unsafe says anything about cryptographic security, beyond pointer-safety implications.
Re:Should random() be banned? by nicoburns on Thursday February 11, 2021 @06:37PM (#26109003)
Neither does React's dangerouslySetInnerHTML. What both of these do is mark a potentially dangerous operation with an in-your-face warning message that you have to go out of your way to ignore. Which in practice is very useful, as often the biggest problem with security issues is not know what you don't know. It's impractical to review the entire codebase on a regular basis, and it can be hard to know which bits to focus on.