sanitize-sql

1.0.7ย โ€ขย Publicย โ€ขย Published

Sanitize-SQL

A simple SQL sanitizer library to help prevent SQL injection attacks. Sanitize-SQL is designed to be used in conjunction with other security measures, such as prepared statements.

npm version npm downloads GitHub release GitHub issues GitHub pull requests GitHub stars

Installation

Using npm:

npm install sanitize-sql

Usage

const { SQL } = require("sanitize-sql");

const sql = new SQL();

const unsafeQuery = "SELECT * FROM users WHERE username='admin' AND password='password';";
const sanitizedQuery = sql.sanitize(unsafeQuery);

console.log(sanitizedQuery);

API

sanitize(query) Sanitize the values within an SQL query to prevent SQL injection.

  • query (string) - The SQL query to sanitize. Returns the sanitized SQL query as a string.

addRestrictedKeyword(keyword)

Add a restricted keyword to the list of keywords that should be removed from queries.

  • keyword (string) - The restricted keyword to add. removeRestrictedKeyword(keyword)

Remove a restricted keyword from the list of keywords that should be removed from queries.

  • keyword (string) - The restricted keyword to remove. isValidKeyword(keyword)

Check if the provided keyword is valid.

keyword (string) - The keyword to validate.

Returns true if the keyword is valid, false otherwise.

Contributing

  • Fork the repository on GitHub: https://github.com/aaronmansfield5/sanitize-sql
  • Clone your forked repository locally
  • Create a new branch for your changes
  • Make your changes and commit them
  • Push your changes to your forked repository on GitHub
  • Create a Pull Request targeting the main branch

Credits

Created by aaronmansfield5.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.77latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.77
1.0.60
1.0.50
1.0.40
1.0.30
1.0.21
1.0.10
1.0.00

Package Sidebar

Install

npm i sanitize-sql

Weekly Downloads

8

Version

1.0.7

License

ISC

Unpacked Size

5.58 kB

Total Files

3

Last publish

Collaborators

  • aaronmansfield5