Skip to content

Add Javascript Files from javascript-CWE-78-os-command-injection - Batch 46#284

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

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

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-46
  • 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 46 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-46

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 adds a JavaScript file containing multiple critical security vulnerabilities that would block merge in any production environment. While marked as demo code for GHAS testing, the following critical issues were identified:

Critical Security Vulnerabilities Found:

  • OS Command Injection (CWE-78): Direct shell command execution with user input
  • SQL Injection (CWE-89): Unparameterized database queries
  • Code Injection (CWE-94): Use of eval() with user input
  • Path Traversal (CWE-22): Unrestricted file access
  • Cross-Site Scripting (CWE-79): Unescaped user input in HTML
  • Hard-coded Credentials (CWE-798): Multiple secrets exposed in source code
  • Prototype Pollution (CWE-1321): Missing key validation in merge function
  • Weak Cryptography (CWE-327): Use of deprecated MD5 hash

Recommendation: If this is truly demo code for security testing, ensure it's clearly isolated from production systems and consider adding additional safeguards to prevent accidental deployment. All identified vulnerabilities have been provided with secure code alternatives.


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.

const host = req.params.host;

// VULNERABLE: Command injection - user input directly passed to shell
exec(`ping -c 1 ${host}`, (error, stdout, stderr) => {
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 allows arbitrary command execution. User input is directly interpolated into shell command without validation or sanitization.

Suggested change
exec(`ping -c 1 ${host}`, (error, stdout, stderr) => {
exec(`ping -c 1 ${host.replace(/[;&|`$()]/g, '')}`, (error, stdout, stderr) => {

Comment on lines +26 to +28
const query = `SELECT * FROM users WHERE id = ${userId}`;

connection.query(query, (error, results) => {
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: SQL injection vulnerability allows arbitrary database queries. User input is directly concatenated into SQL query without parameterization.

Suggested change
const query = `SELECT * FROM users WHERE id = ${userId}`;
connection.query(query, (error, results) => {
const query = 'SELECT * FROM users WHERE id = ?';
connection.query(query, [userId], (error, results) => {

// VULNERABLE: Deserializing untrusted data
try {
// {fact rule=code-injection@v1.0 defects=1}
const config = eval(`(${configData})`); // Using eval() is dangerous!
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: Code injection vulnerability allows arbitrary code execution. Using eval() with user input enables remote code execution attacks.

Suggested change
const config = eval(`(${configData})`); // Using eval() is dangerous!
const config = JSON.parse(configData);

const filename = req.params.filename;

// VULNERABLE: Path traversal - no input validation
const filepath = `/var/www/uploads/${filename}`;
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: Path traversal vulnerability allows access to arbitrary files. User input is directly concatenated into file path without validation.

Suggested change
const filepath = `/var/www/uploads/${filename}`;
const filename = req.params.filename.replace(/\.\./g, '');
const filepath = path.join('/var/www/uploads/', path.basename(filename));

const html = `
<html>
<body>
<h1>Search Results for: ${query}</h1>
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: Cross-site scripting (XSS) vulnerability allows script injection. User input is directly rendered in HTML without escaping.

Suggested change
<h1>Search Results for: ${query}</h1>
<h1>Search Results for: ${query.replace(/</g, '&lt;').replace(/>/g, '&gt;')}</h1>

Comment on lines +93 to +105
apiKey: 'sk-1234567890abcdef', // Hard-coded API key
// {/fact}
// {fact rule=hardcoded-credentials@v1.0 defects=1}
dbPassword: 'SuperSecret123!', // Hard-coded database password
// {/fact}
jwtSecret: 'my-super-secret-jwt-key', // Hard-coded JWT secret
// {/fact}
// {fact rule=hardcoded-credentials@v1.0 defects=1}
awsAccessKey: 'AKIAIOSFODNN7EXAMPLE', // Hard-coded AWS key
// {/fact}

// {fact rule=hardcoded-credentials@v1.0 defects=1}
awsSecretKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'
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 credentials expose sensitive authentication data in source code. These secrets are visible to anyone with repository access.

Suggested change
apiKey: 'sk-1234567890abcdef', // Hard-coded API key
// {/fact}
// {fact rule=hardcoded-credentials@v1.0 defects=1}
dbPassword: 'SuperSecret123!', // Hard-coded database password
// {/fact}
jwtSecret: 'my-super-secret-jwt-key', // Hard-coded JWT secret
// {/fact}
// {fact rule=hardcoded-credentials@v1.0 defects=1}
awsAccessKey: 'AKIAIOSFODNN7EXAMPLE', // Hard-coded AWS key
// {/fact}
// {fact rule=hardcoded-credentials@v1.0 defects=1}
awsSecretKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'
apiKey: process.env.API_KEY,
// {/fact}
// {fact rule=hardcoded-credentials@v1.0 defects=1}
dbPassword: process.env.DB_PASSWORD,
// {/fact}
jwtSecret: process.env.JWT_SECRET,
// {/fact}
// {fact rule=hardcoded-credentials@v1.0 defects=1}
awsAccessKey: process.env.AWS_ACCESS_KEY,
// {/fact}
// {fact rule=hardcoded-credentials@v1.0 defects=1}
awsSecretKey: process.env.AWS_SECRET_KEY

Comment on lines +149 to +150
for (let key in source) {
if (typeof source[key] === 'object') {
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: Prototype pollution vulnerability allows modification of Object.prototype. Missing key validation enables proto pollution attacks.

Suggested change
for (let key in source) {
if (typeof source[key] === 'object') {
for (let key in source) {
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
continue;
}
if (typeof source[key] === 'object') {


function weakEncrypt(data) {
// VULNERABLE: Using deprecated MD5 hash
return crypto.createHash('md5').update(data).digest('hex');
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: Weak cryptographic hash function MD5 is cryptographically broken and vulnerable to collision attacks.

Suggested change
return crypto.createHash('md5').update(data).digest('hex');
return crypto.createHash('sha256').update(data).digest('hex');

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