Giter Club home page Giter Club logo

Comments (9)

yang avatar yang commented on July 26, 2024 1

First off - thanks for this library @hiddentao.

The point is that the auto-quoting is broken. Simply surrounding a string with single quotes is incorrect and a textbook injection example. I'd argue it's worse than no quoting at all as users may mistakenly assume that proper quoting is implemented.

from squel.

hiddentao avatar hiddentao commented on July 26, 2024

Squel auto-quotes string values. You can tell it to use a different quote character, or you can tell it to not auto-quote.

from squel.

acroca avatar acroca commented on July 26, 2024

#35

from squel.

hiddentao avatar hiddentao commented on July 26, 2024

@yang I don't know if this helps but #34 has been merged in now, which means that parameterized queries are much easier to do (ideally you should be running a parameterized query through your db engine's query escaping routine so ensure that the query is safe).

As for preventing query injection, #8 is the discussion around that.

from squel.

mayanklahiri avatar mayanklahiri commented on July 26, 2024

Hi there, this still seems to be broken at 3.1.1 on node 0.10.26.

squel.insert().into('test').set('q', '{"key":"aint"}').toString()
'INSERT INTO test (q) VALUES (\'{"key":"aint"}\')'

squel.insert().into('test').set('q', '{"key":"ain\'t"}').toString()
'INSERT INTO test (q) VALUES (\'{"key":"ain\'t"}\')'

from squel.

hiddentao avatar hiddentao commented on July 26, 2024

@mayanklahiri What is your expected output?

from squel.

mayanklahiri avatar mayanklahiri commented on July 26, 2024

Sorry, it's not immediately obvious because the node shell does some weird escaping if you don't use console.log(). Here's a more clear example, with expected output:

var q = squel.insert().into('test');

console.log(q.set("col", "something").toString())
INSERT INTO test (col) VALUES ('something')

console.log(q.set("col", "some'thing").toString())
INSERT INTO test (col) VALUES ('some'thing')

Clearly the second query has a syntax error (and injection). The expected output (for Postgres) should be (the change is to have two single quotes side by side):

INSERT INTO test (col) VALUES ('some''thing')

I do not know how to quote strings correctly for other databases, but I would imagine it's something like \'

from squel.

hiddentao avatar hiddentao commented on July 26, 2024

Ok, a change was merged into the postgres flavour (#35) which fixed this for that. I might merge that into the core Squel code. That would sort this problem out once and for all.

from squel.

hiddentao avatar hiddentao commented on July 26, 2024

The replaceSingleQuotes option is now available in Squel core, see http://hiddentao.github.io/squel/api.html#cls_defaultquerybuilderoptions

from squel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.