News for hackers. Stuff that matters.
Re:Bobby Tables by paulddraper on Sunday December 03, 2017 @02:52PM (#15839175)
Proper SQL parameterization is a great example of where library/language design has a lot to offer.

For example, in Java

    // IMPROPER
    PreparedStatement statement = connection.prepareStatement(
      "SELECT * FROM users where email = '" + email + '"'
    );
    statement.execute();
vs

    // PROPER
    PreparedStatement statement = connection.prepareStatement(
        "SELECT * FROM users WHERE email = ?"
    );
    statement.setString(1, email);
    statement.execute();
The first code is easier and simpler than the second code -- especially if have lots of parameters, or if your queries start mixing arbitrary data and variable parts of the SQL. So people are sometimes going to write the first code.

---

In contrast, Scala has more sophisticated facilities than Java. I contribute to https://github.com/lucidsoftware/relate where the example would simply be

    // GOOD
    sql"SELECT * FROM users WHERE email = $email".asSeq[User]()
It's just so easy that no one is ever even _tempted_ to do the wrong thing. Use developers' laziness to your advantage, not your detriment :)

You can keep the full power of SQL (index hints, hand-tuned locking, DBMS-specific features), without constantly fighting the propensity towards SQL injection.

Re:Bobby Tables by rhizome31 on Sunday December 03, 2017 @03:20PM (#15839342)
Django ORM is also less error-prone than the Rails example shown:

    User.objects.get(email=email_input)
Raw Python DB-API, on the other hand, can easily be misused, as I've see on several occasions.