-
Notifications
You must be signed in to change notification settings - Fork 4
Intentional vulnerable #32
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
Open
shwetarkadam
wants to merge
4
commits into
main
Choose a base branch
from
intentional-vulnerable
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,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 failureCode 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 failureCode 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 failureCode 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'); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Sensitive data read from GET request Medium