News for hackers. Stuff that matters.
Re:Compile Time Prevention of SQL-Injections in Rust by alexandernst on Tuesday May 22, 2018 @08:59AM (#17125550)
Is it me or the person that wrote that post has no idea what SQL inject actually is?
Re:Compile Time Prevention of SQL-Injections in Rust by kazinator on Tuesday May 22, 2018 @09:05AM (#17125584)
The idea seems to be that if a variable has a certain kind of Rust lifetime, then it contains only trusted data associated with the program itself, rather than some untrusted input.

Problem is, that is too limiting to satisfy the functional use cases in a lot of code that constructs SQL queries by substituting values into templates, where some of the pieces are necessarily dependent on inputs from logged-in users and such.

Re:Compile Time Prevention of SQL-Injections in Rust by empath75 on Tuesday May 22, 2018 @09:00AM (#17125553)
I don’t understand at all what the difference is between the two functions.
Re:Compile Time Prevention of SQL-Injections in Rust by borntyping on Tuesday May 22, 2018 @09:04AM (#17125577)
The second function only accepts strings defined at compile time, meaning it can't be called with strings created at runtime (i.e. any string containing user input).
Re:Compile Time Prevention of SQL-Injections in Rust by empath75 on Tuesday May 22, 2018 @09:05AM (#17125587)
So what to you do if you need to make a sql call based on user input?
Re:Compile Time Prevention of SQL-Injections in Rust by gnud on Tuesday May 22, 2018 @09:08AM (#17125620)
Use parameters, of course. Using SQL parameters for untrusted input is the only sane way to avoid SQL injections.
Re:Compile Time Prevention of SQL-Injections in Rust by EugeneOZ on Tuesday May 22, 2018 @09:59AM (#17125954)
just add "to_owned()" and problem solved. This function doesn't protect nothing, it's a bullshit. I love Rust, but author is far from the theme he is trying to describe. And theme is dangerous enough.
Re:Compile Time Prevention of SQL-Injections in Rust by C4K3 on Tuesday May 22, 2018 @10:27AM (#17126121)
to_owned() converts to a String, not to a &'static str. Those are not the same. You can't create a &'static str dynamically (though you can mutate one using unsafe.)
Re:Compile Time Prevention of SQL-Injections in Rust by derkha on Tuesday May 22, 2018 @10:40AM (#17126196)
You can convert a `String` into a `&'static str` using only safe stdlib functions via `Box::leak(s.into())`. This uses `unsafe` internally, of course... but so does almost any code.
Re:Compile Time Prevention of SQL-Injections in Rust by C4K3 on Tuesday May 22, 2018 @10:47AM (#17126242)
Ah cool, I hadn't heard about Box::leak until now. Coming to stable in 1.26 it seems.
Re:Compile Time Prevention of SQL-Injections in Rust by EugeneOZ on Tuesday May 22, 2018 @10:36AM (#17126168)
lol, so you call your SQL just with constants? "username" in his example just for one user forever? Still a bullshit.
Re:Compile Time Prevention of SQL-Injections in Rust by C4K3 on Tuesday May 22, 2018 @10:49AM (#17126261)
No, only the SQL statement has to be 'static. It's not bullshit.
Re:Compile Time Prevention of SQL-Injections in Rust by EugeneOZ on Tuesday May 22, 2018 @11:11AM (#17126437)
Can you provide real-world example please?
Re:Compile Time Prevention of SQL-Injections in Rust by Khoth on Tuesday May 22, 2018 @11:44AM (#17126775)
From TFA:

let _rows = sql_query("SELECT * FROM users WHERE username=?", &[username]);

The statement is static, but the [username] part is not, it's just a variable that can have whatever username you want.

Re:Compile Time Prevention of SQL-Injections in Rust by EugeneOZ on Tuesday May 22, 2018 @08:16PM (#17130553)
and I already told that this example has no meaning, it's just a bullshit - nobody will use it in real app. You want to fetch from db info about the only one user, who's name is a constant? Yeah, all apps do it every day.
Re:Compile Time Prevention of SQL-Injections in Rust by kpmah on Tuesday May 22, 2018 @09:05AM (#17125586)
Looks correct to me. What issue do you have with it?

They're saying injection attacks come from dynamically building strings, so if you prevent that you stop the vulnerabilities.

Re:Compile Time Prevention of SQL-Injections in Rust by alexandernst on Tuesday May 22, 2018 @09:08AM (#17125621)
SQL Inject is not only a ' character. SQL Inject could be a blind query, subselect attack, time attack and so on and so on. This completely fails to prevent pretty much anything except the very naive and silly attacks.
Re:Compile Time Prevention of SQL-Injections in Rust by CiPHPerCoder on Tuesday May 22, 2018 @09:39AM (#17125816)
No it doesn't.

The argument isn't "block ' characters to stop SQL injection" it's "force the developer to use prepared statements and no dynamically constructed queries".

Re:Compile Time Prevention of SQL-Injections in Rust by coldtea on Tuesday May 22, 2018 @09:44AM (#17125858)
First, no, it prevents much more attacks.

Second, the naive and silly attacks are the default definition of SQL injection -- and the most commonly found holes, so even if it just prevented those that would be still a huge help. Nothing statically ensures that at runtime except the programmer's due diligence.

Re:Compile Time Prevention of SQL-Injections in Rust by charriu on Tuesday May 22, 2018 @09:14AM (#17125656)
This prevents dynamically created queries using lifetimes. It does not search for ' characters.
Re:Compile Time Prevention of SQL-Injections in Rust by swirepe on Tuesday May 22, 2018 @09:17AM (#17125675)
Yup. But it does it at compile time for basically no work.