Skip to content
This repository was archived by the owner on Jul 1, 2026. It is now read-only.
This repository was archived by the owner on Jul 1, 2026. It is now read-only.

Defending against SQL injection? #57

Closed

Description

@cmundi

I'm looking for some guidance on preventing SQL injection attacks, specifically with node-sqlite3.

For example, will using

Database#prepare(sql, [param, ...], [callback])

protect against SQL injection?

Thanks.

Activity

  1. kkaefer commented on Jan 21, 2012

    @kkaefer
    Contributor

    SQLite protects you against SQL injections if you specify user-supplied data as part of the params rather than stringing together an SQL query:

    BAD: db.prepare("INSERT INTO foo VALUES(" + variable + ")");

    GOOD: db.prepare("INSERT INTO foo VALUES (?)", variable);

    By using the placeholder ?, SQLite automatically treats the data as input data and it does not interfere with parsing the actual SQL statement.

  2. cmundi commented on Jan 21, 2012

    @cmundi
    Author

    Thanks. I hoped so. I did not want to assume that "prepare" in
    node-sqlite3 means thevsamw thing as sqlite3_prepare in the sqlite libs. I
    should stop being lazy and just look at the source. :) Thanks!
    On Jan 21, 2012 3:08 AM, "Konstantin Kfer" <
    reply@reply.github.com>
    wrote:

    SQLite protects you against SQL injections if you specify user-supplied
    data as part of the params rather than stringing together an SQL query:

    BAD: db.prepare("INSERT INTO foo VALUES(" + variable + ")");

    GOOD: `db.prepare("INSERT INTO foo VALUES (?)", variable);

    By using the placeholder ?, SQLite automatically treats the data as
    input data and it does not interfere with parsing the actual SQL statement.


    Reply to this email directly or view it on GitHub:

    #57 (comment)

  3. added a commit that references this issue on Jun 10, 2014
  4. added a commit that references this issue on Jan 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions