Skip to content

Add Javascript Files from javascript-CWE-78-os-command-injection - Batch 29#267

Open
amazon-pratik wants to merge 1 commit into
mainfrom
feature/javascript-cwe-78-os-command-injection-javascript-batch-29
Open

Add Javascript Files from javascript-CWE-78-os-command-injection - Batch 29#267
amazon-pratik wants to merge 1 commit into
mainfrom
feature/javascript-cwe-78-os-command-injection-javascript-batch-29

Conversation

@amazon-pratik
Copy link
Copy Markdown
Owner

📝 Description

This PR adds a batch of Javascript files from the javascript-CWE-78-os-command-injection directory to the repository.

📁 Files Added

  • Source Folder: javascript-CWE-78-os-command-injection
  • Batch: javascript-cwe-78-os-command-injection-javascript-batch-29
  • Language: Javascript
  • Contains javascript files collected from the source directory

🔍 Changes

  • Added javascript files from javascript-CWE-78-os-command-injection maintaining original directory structure
  • Files organized in batch 29 for easier review
  • Ready for integration and testing

💾 Source

Original files sourced from: javascript-CWE-78-os-command-injection

@gemini-code-assist
Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@amazon-q-developer
Copy link
Copy Markdown

Code review in progress. Analyzing for code quality issues and best practices. You can monitor the review status in the checks section at the bottom of this pull request. Detailed findings will be posted upon completion.

Using Amazon Q Developer for GitHub

Amazon Q Developer1 is an AI-powered assistant that integrates directly into your GitHub workflow, enhancing your development process with intelligent features for code development, review, and transformation.

Slash Commands

Command Description
/q <message> Chat with the agent to ask questions or request revisions
/q review Requests an Amazon Q powered code review
/q help Displays usage information

Features

Agentic Chat
Enables interactive conversation with Amazon Q to ask questions about the pull request or request specific revisions. Use /q <message> in comment threads or the review body to engage with the agent directly.

Code Review
Analyzes pull requests for code quality, potential issues, and security concerns. Provides feedback and suggested fixes. Automatically triggered on new or reopened PRs (can be disabled for AWS registered installations), or manually with /q review slash command in a comment.

Customization

You can create project-specific rules for Amazon Q Developer to follow:

  1. Create a .amazonq/rules folder in your project root.
  2. Add Markdown files in this folder to define rules (e.g., cdk-rules.md).
  3. Write detailed prompts in these files, such as coding standards or best practices.
  4. Amazon Q Developer will automatically use these rules when generating code or providing assistance.

Example rule:

All Amazon S3 buckets must have encryption enabled, enforce SSL, and block public access.
All Amazon DynamoDB Streams tables must have encryption enabled.
All Amazon SNS topics must have encryption enabled and enforce SSL.
All Amazon SNS queues must enforce SSL.

Feedback

To provide feedback on Amazon Q Developer, create an issue in the Amazon Q Developer public repository.

For more detailed information, visit the Amazon Q for GitHub documentation.

Footnotes

  1. Amazon Q Developer uses generative AI. You may need to verify generated code before using it in your environment. See the AWS Responsible AI Policy.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Nov 6, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/javascript-cwe-78-os-command-injection-javascript-batch-29

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@amazon-q-developer amazon-q-developer Bot left a comment

Choose a reason for hiding this comment

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

Security Review Summary

This PR introduces a JavaScript file with multiple critical security vulnerabilities that must be addressed before merging:

🚨 Critical Security Issues:

  1. Hardcoded Credentials (CWE-798) - Password exposed in source code
  2. OS Command Injection (CWE-78) - Multiple instances where user input is passed to spawn() without sanitization
  3. Regular Expression Injection (CWE-1333) - User input used directly in new RegExp() calls across multiple functions

🔧 Additional Issues:

  • Potential null pointer exceptions in authorization checks
  • Logic errors in error handling that could bypass security checks

⚠️ Impact:

These vulnerabilities could allow attackers to:

  • Execute arbitrary system commands on the server
  • Cause denial of service through ReDoS attacks
  • Access sensitive credentials from the codebase
  • Bypass authentication and authorization controls

Recommendation: All security issues must be resolved before this code can be safely deployed to production. The suggested fixes include input sanitization, proper error handling, and moving credentials to environment variables.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

Comment thread 045_leads_L1348.js
country_code: lead.prefix || "1",
landingPage,
// {fact rule=hardcoded-credentials@v1.0 defects=1}
password: "TPvBwkO8",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛑 Security Vulnerability: Hardcoded password exposes sensitive credentials in source code. This creates a significant security risk as the password is visible to anyone with access to the codebase.

Suggested change
password: "TPvBwkO8",
password: process.env.DEFAULT_INJECTION_PASSWORD || "defaultPassword",

Comment thread 045_leads_L1348.js
Comment on lines +1349 to +1352
const pythonProcess = spawn("python3", [
scriptPath,
JSON.stringify(leadData),
]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛑 Security Vulnerability: OS command injection vulnerability. The leadData object contains user-controlled data that is passed directly to JSON.stringify() and then to a Python process via spawn(). An attacker could inject malicious commands through lead data fields.

Suggested change
const pythonProcess = spawn("python3", [
scriptPath,
JSON.stringify(leadData),
]);
// Sanitize and validate leadData before passing to external process
const sanitizedLeadData = {
firstName: String(leadData.firstName || '').replace(/[^\w\s-]/g, ''),
lastName: String(leadData.lastName || '').replace(/[^\w\s-]/g, ''),
email: String(leadData.email || '').replace(/[^a-zA-Z0-9@._-]/g, ''),
phone: String(leadData.phone || '').replace(/[^\d+()-\s]/g, ''),
country: String(leadData.country || '').replace(/[^\w\s-]/g, ''),
country_code: String(leadData.country_code || '1').replace(/[^\d]/g, ''),
landingPage: String(leadData.landingPage || '').replace(/[^a-zA-Z0-9:/.?&=_-]/g, ''),
password: process.env.DEFAULT_INJECTION_PASSWORD || "defaultPassword",
};
const pythonProcess = spawn("python3", [
scriptPath,
JSON.stringify(sanitizedLeadData),
]);

Comment thread 045_leads_L1348.js
Comment on lines +2428 to +2435
const pythonProcess = spawn(
"python3",
[scriptPath, JSON.stringify(sessionDataForScript)],
{
detached: true,
stdio: "ignore",
}
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛑 Security Vulnerability: Another OS command injection vulnerability. The sessionDataForScript object contains user-controlled session data that is passed to spawn() without proper sanitization. This could allow attackers to execute arbitrary commands.

Suggested change
const pythonProcess = spawn(
"python3",
[scriptPath, JSON.stringify(sessionDataForScript)],
{
detached: true,
stdio: "ignore",
}
);
// Validate and sanitize session data before passing to external process
const sanitizedSessionData = {
leadId: String(sessionDataForScript.leadId || '').replace(/[^a-zA-Z0-9]/g, ''),
sessionId: String(sessionDataForScript.sessionId || '').replace(/[^a-zA-Z0-9-]/g, ''),
domain: String(sessionDataForScript.domain || '').replace(/[^a-zA-Z0-9:/.?&=_-]/g, ''),
leadInfo: {
firstName: String(sessionDataForScript.leadInfo?.firstName || '').replace(/[^\w\s-]/g, ''),
lastName: String(sessionDataForScript.leadInfo?.lastName || '').replace(/[^\w\s-]/g, ''),
email: String(sessionDataForScript.leadInfo?.email || '').replace(/[^a-zA-Z0-9@._-]/g, ''),
phone: String(sessionDataForScript.leadInfo?.phone || '').replace(/[^\d+()-\s]/g, ''),
country: String(sessionDataForScript.leadInfo?.country || '').replace(/[^\w\s-]/g, ''),
},
// Note: cookies, localStorage, sessionStorage should be validated separately
// as they may contain complex objects that need careful sanitization
};
const pythonProcess = spawn(
"python3",
[scriptPath, JSON.stringify(sanitizedSessionData)],
{
detached: true,
stdio: "ignore",
}
);

Comment thread 045_leads_L1348.js
Comment on lines +77 to +82
{ firstName: new RegExp(search, "i") },
{ lastName: new RegExp(search, "i") },
{ newEmail: new RegExp(search, "i") },
{ newPhone: new RegExp(search, "i") },
{ client: new RegExp(search, "i") },
];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛑 Security Vulnerability: Regular expression injection vulnerability. User input from search parameter is directly used in new RegExp() without sanitization, allowing attackers to inject malicious regex patterns that could cause ReDoS attacks or bypass security filters.

Suggested change
{ firstName: new RegExp(search, "i") },
{ lastName: new RegExp(search, "i") },
{ newEmail: new RegExp(search, "i") },
{ newPhone: new RegExp(search, "i") },
{ client: new RegExp(search, "i") },
];
// Escape special regex characters to prevent injection
const escapeRegex = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
filter.$or = [
{ firstName: new RegExp(escapeRegex(search), "i") },
{ lastName: new RegExp(escapeRegex(search), "i") },
{ newEmail: new RegExp(escapeRegex(search), "i") },
{ newPhone: new RegExp(escapeRegex(search), "i") },
{ client: new RegExp(escapeRegex(search), "i") },
];

Comment thread 045_leads_L1348.js
Comment on lines +1420 to +1436
if (country) filter.country = new RegExp(country, "i");
if (gender) filter.gender = gender;
if (status) filter.status = status;
if (documentStatus) filter["documents.status"] = documentStatus;
if (isAssigned !== undefined && isAssigned !== "") {
filter.isAssigned = isAssigned === "true" || isAssigned === true;
}
if (search) {
filter.$or = [
{ firstName: new RegExp(search, "i") },
{ lastName: new RegExp(search, "i") },
{ newEmail: new RegExp(search, "i") },
{ oldEmail: new RegExp(search, "i") },
{ newPhone: new RegExp(search, "i") },
{ oldPhone: new RegExp(search, "i") },
];
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛑 Security Vulnerability: Multiple regex injection vulnerabilities in bulk delete function. User-controlled input is used directly in new RegExp() calls without sanitization, creating the same security risks as the search functionality.

Suggested change
if (country) filter.country = new RegExp(country, "i");
if (gender) filter.gender = gender;
if (status) filter.status = status;
if (documentStatus) filter["documents.status"] = documentStatus;
if (isAssigned !== undefined && isAssigned !== "") {
filter.isAssigned = isAssigned === "true" || isAssigned === true;
}
if (search) {
filter.$or = [
{ firstName: new RegExp(search, "i") },
{ lastName: new RegExp(search, "i") },
{ newEmail: new RegExp(search, "i") },
{ oldEmail: new RegExp(search, "i") },
{ newPhone: new RegExp(search, "i") },
{ oldPhone: new RegExp(search, "i") },
];
}
const escapeRegex = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const filter = {};
if (leadType) filter.leadType = leadType;
if (country) filter.country = new RegExp(escapeRegex(country), "i");
if (gender) filter.gender = gender;
if (status) filter.status = status;
if (documentStatus) filter["documents.status"] = documentStatus;
if (isAssigned !== undefined && isAssigned !== "") {
filter.isAssigned = isAssigned === "true" || isAssigned === true;
}
if (search) {
filter.$or = [
{ firstName: new RegExp(escapeRegex(search), "i") },
{ lastName: new RegExp(escapeRegex(search), "i") },
{ newEmail: new RegExp(escapeRegex(search), "i") },
{ oldEmail: new RegExp(escapeRegex(search), "i") },
{ newPhone: new RegExp(escapeRegex(search), "i") },
{ oldPhone: new RegExp(escapeRegex(search), "i") },
];
}

Comment thread 045_leads_L1348.js
if (leadType) filter.leadType = leadType;
if (isAssigned !== undefined && isAssigned !== "")
filter.isAssigned = isAssigned === "true";
if (country) filter.country = new RegExp(country, "i");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛑 Security Vulnerability: Regex injection vulnerability in country filter. User input is directly used in new RegExp() without sanitization.

Suggested change
if (country) filter.country = new RegExp(country, "i");
if (country) {
const escapeRegex = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
filter.country = new RegExp(escapeRegex(country), "i");
}

Comment thread 045_leads_L1348.js
});
}
if (req.user.role !== "admin" && req.user.role !== "affiliate_manager") {
if (!lead.isAssigned || lead.assignedTo._id.toString() !== req.user.id) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Potential null pointer exception. The code assumes lead.assignedTo is populated, but if the populate operation fails or returns null, accessing lead.assignedTo._id will throw an error.

Suggested change
if (!lead.isAssigned || lead.assignedTo._id.toString() !== req.user.id) {
if (!lead.isAssigned || !lead.assignedTo || lead.assignedTo._id.toString() !== req.user.id) {

Comment thread 045_leads_L1348.js
Comment on lines +1336 to +1348
const pythonCheck = spawn("python3", ["--version"]);
pythonCheck.on("error", (error) => {
console.error("Python not found:", error);
return res.status(500).json({
success: false,
message: "Python not installed or not in PATH",
error: error.message,
});
});
// {fact rule=os-command-injection@v1.0 defects=1}
} catch (error) {
console.error("Failed to check Python:", error);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Logic error in error handling. The return statement inside the error handler will never execute because it's inside an event handler callback. This could lead to the function continuing execution even when Python is not available.

Suggested change
const pythonCheck = spawn("python3", ["--version"]);
pythonCheck.on("error", (error) => {
console.error("Python not found:", error);
return res.status(500).json({
success: false,
message: "Python not installed or not in PATH",
error: error.message,
});
});
// {fact rule=os-command-injection@v1.0 defects=1}
} catch (error) {
console.error("Failed to check Python:", error);
}
try {
const pythonCheck = spawn("python3", ["--version"]);
let pythonAvailable = false;
pythonCheck.on("close", (code) => {
pythonAvailable = (code === 0);
});
pythonCheck.on("error", (error) => {
console.error("Python not found:", error);
pythonAvailable = false;
});
// Wait for python check to complete
await new Promise((resolve) => {
pythonCheck.on("close", resolve);
pythonCheck.on("error", resolve);
});
if (!pythonAvailable) {
return res.status(500).json({
success: false,
message: "Python not installed or not in PATH",
});
}
} catch (error) {
console.error("Failed to check Python:", error);
return res.status(500).json({
success: false,
message: "Failed to verify Python installation",
error: error.message,
});
}

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.

1 participant