-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Demo branch #33
base: main
Are you sure you want to change the base?
Demo branch #33
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const express = require('express'); | ||
const sqlite3 = require('sqlite3').verbose(); | ||
const bcrypt = require('bcrypt'); | ||
const app = express(); | ||
|
||
app.use(express.urlencoded({ extended: true })); | ||
|
||
// Create an in-memory SQLite database | ||
const db = new sqlite3.Database(':memory:'); | ||
|
||
db.serialize(() => { | ||
// Create a table for users | ||
db.run("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, username TEXT, password TEXT)"); | ||
|
||
// Insert a test user with an insecurely hashed password | ||
const insecurePassword = 'password123'; // Plaintext password | ||
const saltRounds = 2; | ||
const hashedPassword = bcrypt.hashSync(insecurePassword, saltRounds); // Weak hashing | ||
db.run("INSERT INTO users (username, password) VALUES (?, ?)", ['testuser', hashedPassword]); | ||
}); | ||
|
||
// Slightly obfuscated SQL Injection vulnerability | ||
app.get('/login', (req, res) => { | ||
const user = req.query.username; | ||
const pass = req.query.password; | ||
|
||
// Concatenation using a different pattern to obscure SQL injection vulnerability | ||
const query = ['SELECT * FROM users WHERE username = "', user, '" AND password = "', pass, '"'].join(''); | ||
|
||
db.get(query, (err, row) => { | ||
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 This query string depends on a user-provided value Error loading related location Loading |
||
if (err) { | ||
res.status(500).send('Internal Server Error'); | ||
} else if (row) { | ||
res.send('Login successful!'); | ||
} else { | ||
res.send('Invalid credentials'); | ||
} | ||
}); | ||
}); | ||
Comment on lines
+23
to
+39
Check failure Code scanning / CodeQL Missing rate limiting High
This route handler performs
a database access Error loading related location Loading |
||
|
||
// XSS vulnerability with slightly hidden logic | ||
app.get('/profile', (req, res) => { | ||
const username = req.query.username; | ||
|
||
// Adding unnecessary function to obscure XSS vulnerability | ||
const renderProfile = (user) => { | ||
return `<h1>Profile of ${user}</h1>`; | ||
}; | ||
|
||
// Render profile with potential XSS | ||
res.send(renderProfile(username)); | ||
Check failure Code scanning / CodeQL Reflected cross-site scripting High
Cross-site scripting vulnerability due to a
user-provided value Error loading related location Loading |
||
}); | ||
|
||
// Start the server | ||
app.listen(3000, () => { | ||
console.log('Server is running on http://localhost:3000'); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const express = require('express'); | ||
const crypto = require('crypto'); | ||
const mysql = require('mysql'); | ||
const { exec } = require('child_process'); | ||
const protobuf = require('protobufjs'); | ||
|
||
const app = express(); | ||
const db = 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' | ||
}); | ||
|
||
app.use(express.json()); | ||
|
||
// Vulnerable SQL Injection Endpoint | ||
app.get('/user/:id', (req, res) => { | ||
const userId = req.params.id; | ||
db.query(`SELECT * FROM users WHERE id = ${userId}`, (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) throw err; | ||
res.send(result); | ||
}); | ||
}); | ||
Comment on lines
+18
to
+24
Check failure Code scanning / CodeQL Missing rate limiting High
This route handler performs
a database access Error loading related location Loading |
||
|
||
// Vulnerable Command Injection Endpoint | ||
app.post('/execute', (req, res) => { | ||
const command = req.body.command; | ||
exec(command, (err, stdout, stderr) => { | ||
Check failure Code scanning / CodeQL Uncontrolled command line Critical
This command line depends on a
user-provided value Error loading related location Loading |
||
if (err) { | ||
res.status(500).send('Command execution failed'); | ||
return; | ||
} | ||
res.send(`Command output: ${stdout}`); | ||
}); | ||
}); | ||
Comment on lines
+27
to
+36
Check failure Code scanning / CodeQL Missing rate limiting High
This route handler performs
a system command Error loading related location Loading |
||
|
||
// Vulnerable Hashing (Use of Outdated Cryptographic Practices) | ||
app.post('/hash', (req, res) => { | ||
const password = req.body.password; | ||
const hash = crypto.createHash('md5').update(password).digest('hex'); | ||
Check failure Code scanning / CodeQL Use of password hash with insufficient computational effort High
Password from
an access to password Error loading related location Loading Password from an access to password Error loading related location Loading |
||
res.send(`Hashed password: ${hash}`); | ||
}); | ||
|
||
// Vulnerable Proto Buffing (Prototype Pollution) | ||
app.post('/protobuf', async (req, res) => { | ||
const root = await protobuf.load("example.proto"); | ||
const Message = root.lookupType("examplepackage.Message"); | ||
|
||
const payload = req.body; | ||
const errMsg = Message.verify(payload); | ||
if (errMsg) { | ||
res.status(400).send(`Invalid message: ${errMsg}`); | ||
return; | ||
} | ||
|
||
const message = Message.create(payload); | ||
res.send(`Received message: ${JSON.stringify(message)}`); | ||
}); | ||
Comment on lines
+46
to
+59
Check failure Code scanning / CodeQL Missing rate limiting High
This route handler performs
authorization Error loading related location Loading |
||
|
||
app.listen(3000, () => { | ||
console.log('Server is running on port 3000'); | ||
}); |
Check warning
Code scanning / CodeQL
Sensitive data read from GET request Medium