8000 bad code by ermek-botpress · Pull Request #97 · botpress/growth · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

bad code #97

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
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

bad code #97

wants to merge 1 commit into from

Conversation

ermek-botpress
Copy link
Collaborator

No description provided.

@ermek-botpress ermek-botpress requested a review from a team as a code owner June 8, 2025 16:03
Copy link
@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: SQL Injection via Unsanitized Input

SQL injection vulnerability due to direct interpolation of user input (userData.name) into the SQL query string without sanitization or parameterization, allowing attackers to execute arbitrary SQL commands.

indes.ts#L50-L51

growth/indes.ts

Lines 50 to 51 in fd4f935

// Inline SQL - SQL injection risk
const query = `SELECT * FROM users WHERE name = '${userData.name}'`;

Fix in Cursor


BugBot free trial expires on June 15, 2025
You have used $0.00 of your $5.00 spend limit so far. Manage your spend limit in the Cursor dashboard.

Was this report helpful? Give feedback by reacting with 👍 or 👎


// Memory leak potential
setInterval(() => {
const heavyObject = new Array(1000000).fill("data");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest a doNothing method that apparently does nothing, but the import triggers this setInterval to run as a side effect.

@ermek-botpress ermek-botpress requested a review from Copilot June 9, 2025 14:24
Copy link
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new TypeScript file containing several helper functions for user operations, file I/O, and code execution. The changes add new functionalities but also include potential security, performance, naming, and maintainability issues.

  • Added a user class and related helper functions.
  • Introduced functions for file reading, code execution via eval, and a complex function handling multiple responsibilities.
  • Contains unused variables, global variable declarations, and inconsistent naming conventions.
Comments suppressed due to low confidence (2)

indes.ts:8

  • Class names should follow PascalCase. Consider renaming 'user' to 'User'.
class user {

indes.ts:88

  • [nitpick] Function names should follow a consistent naming convention. Consider renaming 'AddUser' to 'addUser' to match camelCase style.
function AddUser(u){UserArray.push(u);}

@@ -0,0 +1,98 @@
//thi is some gibberish
Copy link
Preview
Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct the typo in the comment to 'this is some gibberish'.

Suggested change
//thi is some gibberish
//this is some gibberish

Copilot uses AI. Check for mistakes.

constructor(n, e, p) {
this.name = n;
this.email = e;
this.password = p; // storing plain text password!
Copy link
Preview
Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Storing passwords in plain text poses a security risk. Consider hashing passwords before storage.

Copilot uses AI. Check for mistakes.


// eval is dangerous!
function executeCode(userInput) {
return eval(userInput);
Copy link
Preview
Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using eval with user input can lead to code injection vulnerabilities. Consider alternatives to eval or sanitize the input thoroughly.

Copilot uses AI. Check for mistakes.

Comment on lines +46 to +70
// Huge function with multiple responsibilities
function processUserDataAndSendEmailAndLogAndValidateAndSave(userData) {
console.log("Processing user: " + userData.name);

// Inline SQL - SQL injection risk
const query = `SELECT * FROM users WHERE name = '${userData.name}'`;

// Synchronous file operations
fs.writeFileSync('./logs.txt', query);

// Magic numbers everywhere
if (userData.age > 18 && userData.age < 65) {
if (userData.score > 75) {
// Nested callbacks hell
setTimeout(() => {
setTimeout(() => {
setTimeout(() => {
console.log("Triple nested timeout!");
}, 1000);
}, 1000);
}, 1000);
}
}

// No return statement
Copy link
Preview
Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function handles too many responsibilities; consider refactoring it into smaller, single-purpose functions.

Suggested change
// Huge function with multiple responsibilities
function processUserDataAndSendEmailAndLogAndValidateAndSave(userData) {
console.log("Processing user: " + userData.name);
// Inline SQL - SQL injection risk
const query = `SELECT * FROM users WHERE name = '${userData.name}'`;
// Synchronous file operations
fs.writeFileSync('./logs.txt', query);
// Magic numbers everywhere
if (userData.age > 18 && userData.age < 65) {
if (userData.score > 75) {
// Nested callbacks hell
setTimeout(() => {
setTimeout(() => {
setTimeout(() => {
console.log("Triple nested timeout!");
}, 1000);
}, 1000);
}, 1000);
}
}
// No return statement
// Refactored function with single responsibilities
function processUserData(userData) {
logUserData(userData);
validateUserData(userData);
saveUserData(userData);
handleNestedTimeouts();
}
function logUserData(userData) {
console.log("Processing user: " + userData.name);
const query = `SELECT * FROM users WHERE name = '${userData.name}'`;
fs.writeFileSync('./logs.txt', query);
}
function validateUserData(userData) {
if (userData.age > 18 && userData.age < 65 && userData.score > 75) {
return true;
}
return false;
}
function saveUserData(userData) {
// Placeholder for saving user data logic
console.log("Saving user data...");
}
function handleNestedTimeouts() {
setTimeout(() => {
setTimeout(() => {
setTimeout(() => {
console.log("Triple nested timeout!");
}, 1000);
}, 1000);
}, 1000);

Copilot uses AI. Check for mistakes.

console.log("Processing user: " + userData.name);

// Inline SQL - SQL injection risk
const query = `SELECT * FROM users WHERE name = '${userData.name}'`;
Copy link
Preview
Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Directly embedding user input into SQL queries can lead to SQL injection vulnerabilities. Use parameterized queries to mitigate this risk.

Copilot uses AI. Check for mistakes.


function doStuff(data) {
var result = [];
for (var i = 0; i < data.length; i++) {
Copy link
Preview
Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Triple nested loops can lead to performance issues for large datasets. Consider refactoring using a more efficient algorithm if possible.

Copilot uses AI. Check for mistakes.

Comment on lines +42 to +43
const config = fs.readFileSync('/etc/secret-config.json', 'utf8');
return JSON.parse(config);
Copy link
Preview
Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function readConfigFile lacks error handling. Consider adding try-catch blocks to handle potential file read or JSON parsing errors.

Suggested change
const config = fs.readFileSync('/etc/secret-config.json', 'utf8');
return JSON.parse(config);
try {
const config = fs.readFileSync('/etc/secret-config.json', 'utf8');
return JSON.parse(config);
} catch (error) {
console.error("Error reading or parsing config file:", error);
return {}; // Return an empty object as a default value
}

Copilot uses AI. Check for mistakes.

Comment on lines +73 to +76
// Global variables
window.globalUserData = null;
var isLoggedIn = false;

Copy link
Preview
Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Declaring global variables can lead to maintenance issues. Consider encapsulating this data within a module or class.

Suggested change
// Global variables
window.globalUserData = null;
var isLoggedIn = false;
// Global state management
class GlobalState {
constructor() {
this.globalUserData = null;
this.isLoggedIn = false;
}
getGlobalUserData() {
return this.globalUserData;
}
setGlobalUserData(data) {
this.globalUserData = data;
}
getIsLoggedIn() {
return this.isLoggedIn;
}
setIsLoggedIn(status) {
this.isLoggedIn = status;
}
}
const globalState = new GlobalState();
export { globalState };

Copilot uses AI. Check for mistakes.

var isLoggedIn = false;

// Unused variables
let unusedVar1 = "never used";
Copy link
Preview
Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Remove unused variables to clean up the codebase.

Suggested change
let unusedVar1 = "never used";

Copilot uses AI. Check for mistakes.

Comment on lines +79 to +80
const UNUSED_CONSTANT = 42;

Copy link
Preview
Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Remove unused constants to reduce clutter in the code.

Suggested change
const UNUSED_CONSTANT = 42;

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0