Skip to content
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

Intentional vulnerable #32

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions src/components/Medicalreport.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import React, { useState } from "react";
import { Configuration, OpenAIApi } from "openai";
import _ from "lodash"; // Importing lodash, which has had known vulnerabilities
import Nav from "./Nav";
import Footer from "./Footer";

// OWASP #1: Injection
const vulnerableQuery = (userInput) => {
// Simulate SQL injection vulnerability
return `SELECT * FROM users WHERE username = '${userInput}' AND password = 'password123'`;
};

// OWASP #2: Broken Authentication
const fakeLogin = (username, password) => {
// Simulate broken authentication with hardcoded credentials
return username === "admin" && password === "password";
};

const openai = new OpenAIApi(
new Configuration({
apiKey: `${import.meta.env.VITE_OPENAI}`,
apiKey: `${import.meta.env.VITE_OPENAI}`, // OWASP #3: Sensitive Data Exposure
})
);

Expand Down Expand Up @@ -45,14 +58,27 @@ function Medicalreport() {
});
const content = response.data.choices[0].message.content;
console.log("Content:", content);
setResultJSON(JSON.parse(content));
// OWASP #8: Insecure Deserialization (in case of unsafe object input)
const unsafeObject = JSON.parse(content);
_.merge(resultJSON, unsafeObject); // OWASP #9: Using Components with Known Vulnerabilities
setResultJSON(resultJSON);
} catch (error) {
console.error(error);
setError("Error occurred during generation");
}
setIsGenerating(false);
};

// OWASP #7: XSS (Cross-Site Scripting)
const renderProfile = (user) => {
return `<h1>Profile of ${user}</h1>`; // No sanitization applied
};

// OWASP #5: Broken Access Control
const sensitiveAction = () => {
alert("This should be protected by access control, but it isn't!");
};

return (
<>
<Nav />
Expand All @@ -62,7 +88,6 @@ function Medicalreport() {
<h1 className='head_text'>
<span className='orange_gradient '>Doctalyzer</span>
<br />
{/* <span className='description'>Analyze Medical Reports</span> */}
</h1>
<h2 className='desc'>
This tool will tell you about the usage and information of medicines.
Expand Down Expand Up @@ -132,6 +157,7 @@ function Medicalreport() {
</p>
</button>
</div>

<div>
{error && <p>{error}</p>}
{resultJSON && (
Expand Down Expand Up @@ -163,6 +189,15 @@ function Medicalreport() {
</div>
)}
</div>

{/* OWASP #5: Broken Access Control */}
<button onClick={sensitiveAction} className='btn btn-danger'>
Perform Sensitive Action
</button>

{/* OWASP #10: Insufficient Logging and Monitoring */}
{/* No logging implemented for sensitive actions */}

<Footer />
</>
);
Expand Down
57 changes: 57 additions & 0 deletions src/vulnerable-code/index.js
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;

Check warning

Code scanning / CodeQL

Sensitive data read from GET request Medium

Route handler
for GET requests uses query parameter as sensitive data.

// 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
.
This query string depends on a
user-provided value
.
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
, but is not rate-limited.

// 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
.
});

// Start the server
app.listen(3000, () => {
console.log('Server is running on http://localhost:3000');
});