by mrweasel · 13y ago · 0 comments
ORMs makes things alot simpler, in some cases, and get in your way more often than not. I don't do much .Net anymore, mostly Django stuff, but in both cases the ORMs just forces me to learn a new query syntax. In the end prepared statements and SQL would have been quicker, more flexible... and perhaps safer. I get the concept of the ORM, but I don't really plan to switch database anytime soon and I have needed for the flexibility of having "no ORM". ( Could that be a thing, like No-SQL, No-ORM? )
The funniest SQL injection attacks I've seen have been against our search pages. Attackers assume that search is done as dynamic MySQL queries, that fact that you are actually using Sphinx or Solr seems to escape most wanna be hackers.
not sure if you get the concept of ORM, because switching databases is not what ORMs are primarily designed for, it's more of a common feature / side effect that may get invalidated when you use unsupported dbms features.
> and I have needed for the flexibility of having "no ORM".
http://docs.sqlalchemy.org/en/latest/core/index.html
http://docs.sqlalchemy.org/en/rel_0_8/core/tutorial.html
or a clojure example http://sqlkorma.com/ you can probably find something similar for python, there are a few lightweight sql generation libs.
> The funniest SQL injection attacks I've seen have been against our search pages. Attackers assume that search is done as dynamic MySQL queries, that fact that you are actually using Sphinx or Solr seems to escape most wanna be hackers.
bots. they see a form, they submit crap to it.
There is no reason for your standard app user to have access to the core database object tables to do DDL lookups or mess around with the internals. Further, most queries should only run through the RO user. Finally, no user for your app should have DROP or SUPER privileges. You also should disable multi-query requests out the gate.
Of course the dev's will need to remember to use the proper set of creds from their favorite SQL IDE, and there will be a few hiccups for 10min until you've got the proper creds set for the app user, but then you can limit the worries from an attack.
If you use an ORM then SQLi should be impossible, unless there's a bug in your ORM.
objects = orm.rawQueryForObjects("select * from people where name = '" + name + "')
objects = People.query.filter_by(name=name).all()
When I said 'build the sql query' I meant using SQLAlchemy core, which is also safe:
objects = select([People]).where(People.name == name)
session.query(Object).from_statement("SELECT * ...")
http://docs.sqlalchemy.org/en/rel_0_8/orm/query.html#sqlalch...
An example would be you would have your binding take care of something like :foo: as a sort of preprocessing before the db takes care of the others like :foo