npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

knex-sql-injection-detector

v1.1.0

Published

A CLI tool to detect potential SQL injection risks in knex.js codebases by analyzing raw SQL query construction.

Downloads

24

Readme

knex-sql-injection-detector

A CLI tool to detect potential SQL injections in knex.js codebases.

Installation

npm install -g knex-sql-injection-detector

Usage

knex-sql-injection-detector <path> [options]
  • <path>: Path to a file or directory to scan for potential SQL injections in knex raw queries.

Note: Only .js files are currently supported. Files with other extensions (e.g., .ts, .jsx) are ignored.

Node modules scanning: By default, all files in node_modules are skipped. However, if the path you provide contains node_modules (e.g., ./node_modules/some-package), the tool will scan all node_modules folders in all inner paths as well.

What is considered safe?

A query is considered safe if the SQL string is constructed only from:

  • String literals (e.g., 'SELECT * FROM users')
  • Numeric literals (e.g., 42)
  • Boolean literals (true, false)
  • null
  • Template literals with only constant expressions (string, number, boolean, null, or ternary expressions that resolve to constants)
  • Concatenations (+) of only such constants

A query is considered unsafe if:

  • The SQL string contains any dynamic value (variable, function call, etc.)
  • A template literal contains any non-constant interpolation
  • A concatenation includes any non-constant part

Options

  • --only-errors
    Print only errors (potential SQL injections). Suppresses info output for potentially safe calls.
    Default: false

  • --code-quotes
    Print code and extra spacing in output. If disabled (--no-code-quotes), prints only a single line per finding (for easy parsing/clicking in editors).
    Default: true

  • --ignore <pattern ...>
    Glob patterns for files/folders to ignore. You can specify multiple patterns.
    Example: --ignore "**/migration**" "**/test**"

  • --include-node-modules
    Include node_modules in the scan. By default, all files in node_modules are skipped unless you explicitly provide a path inside node_modules or use this flag.
    Default: false

  • -h, --help
    Show help and usage information.

Output

  • [error] Potential SQL injection ...
    Indicates a likely SQL injection risk (e.g., template literals with non-constant interpolations, or any dynamic/non-constant query source).

  • [info] knex raw function call ...
    Indicates a likely safe usage: the query is constructed only from constants as described above.

  • [stats]
    At the end, prints total raw function calls and total potential SQL injections found.

Example

knex-sql-injection-detector ./src \
  --ignore "**/migrations/**" \
  --only-errors \
  --no-code-quotes

This will scan all .js files in ./src, print only errors in single-line format, and skip any files in migrations folders.