-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const express = require('express'); | ||
const mysql = require('mysql'); | ||
|
||
const app = express(); | ||
const port = 3000; | ||
|
||
// Create a connection to the database | ||
const connection = mysql.createConnection({ | ||
host: 'localhost', | ||
user: 'root', | ||
Check failure Code scanning / CodeQL Hard-coded credentials Critical
The hard-coded value "root" is used as
user name Error loading related location Loading |
||
password: 'password', | ||
database: 'testdb' | ||
}); | ||
|
||
// Connect to the database | ||
connection.connect((err) => { | ||
if (err) { | ||
console.error('Error connecting to the database:', err); | ||
return; | ||
} | ||
console.log('Connected to the database'); | ||
}); | ||
|
||
// Route with a vulnerable SQL query (SQL Injection) | ||
app.get('/user/:id', (req, res) => { | ||
const userId = req.params.id; | ||
|
||
// Vulnerable SQL query: no input sanitization | ||
const query = `SELECT * FROM users WHERE id = ${userId}`; | ||
|
||
connection.query(query, (err, result) => { | ||
Check failure Code scanning / CodeQL Database query built from user-controlled sources High
This query string depends on a
user-provided value Error loading related location Loading |
||
if (err) { | ||
res.status(500).send('Database query error'); | ||
return; | ||
} | ||
res.json(result); | ||
}); | ||
}); | ||
Check failure Code scanning / CodeQL Missing rate limiting High
This route handler performs
a database access Error loading related location Loading |
||
|
||
app.listen(port, () => { | ||
console.log(`Server running on http://localhost:${port}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "node-sql-injection-demo", | ||
"version": "1.0.0", | ||
"description": "A simple Node.js app with SQL injection vulnerability demonstration.", | ||
"main": "app.js", | ||
"scripts": { | ||
"start": "node app.js" | ||
}, | ||
"author": "Your Name", | ||
"license": "ISC", | ||
"dependencies": { | ||
"express": "^4.18.2", | ||
"mysql": "^2.18.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
../scripts/run-codeql.sh default --path=$(pwd) --override --language=javascript | ||
|
||
#../scripts/run-codeql.sh security-and-quality --path=$(pwd) --override --language=javascript | ||
|
||
#../scripts/run-codeql.sh "security-extended" --path=$(pwd) --override --language=javascript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#!/bin/bash | ||
|
||
#../scripts/run-codeql.sh default --path=$(pwd) --override --language=javascript | ||
../scripts/run-codeql.sh default --path=$(pwd) --override --language=javascript | ||
|
||
#../scripts/run-codeql.sh security-and-quality --path=$(pwd) --override --language=javascript | ||
|
||
../scripts/run-codeql.sh "security-extended" --path=$(pwd) --override --language=javascript | ||
#../scripts/run-codeql.sh "security-extended" --path=$(pwd) --override --language=javascript |