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

test/vulns-outside-30_08_24_18_24 #12

Open
wants to merge 2 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
23 changes: 23 additions & 0 deletions app_1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// app.js

const buildQuery = require('./queryBuilder');

// Simulating a database connection and query execution
function executeQuery(query) {
console.log("Executing Query:", query);

// Here you would normally execute the query against your database
// db.execute(query);
}

// User input from a hypothetical form
let userInput = "1 OR 1=1"; // Malicious input that can cause SQL Injection

// Columns to retrieve from the database
let columns = ['id', 'name', 'email'];

// Using the function from File A
let query = buildQuery('users', columns, `id=${userInput}`);

// Execute the query
executeQuery(query);
13 changes: 13 additions & 0 deletions queryBuilder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// queryBuilder.js

function buildQuery(tableName, columns, condition) {
// This is a safe way to build queries
// Using parameterized queries is always recommended to avoid SQL Injection

// Initially, let's assume we're being safe
let query = `SELECT ${columns.join(', ')} FROM ${tableName} WHERE ${condition}`;

return query;
}

module.exports = buildQuery;