Skip to content

Add Javascript Files from javascript-CWE-78-os-command-injection - Batch 25#263

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

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

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-25
  • 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 25 for easier review
  • Ready for integration and testing

💾 Source

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

@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-25

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.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @amazon-pratik, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request expands the repository's collection of security vulnerability examples by adding a new set of Javascript files. The primary goal is to provide practical, runnable code that illustrates common web application weaknesses, facilitating educational purposes and security testing efforts. The changes introduce a single file that encapsulates multiple vulnerability types within a single API structure.

Highlights

  • New Vulnerability Examples: This pull request introduces a new batch of Javascript files, specifically 020_api_L36.js, which serves as a comprehensive example of various web application vulnerabilities.
  • Diverse Vulnerability Coverage: The added file demonstrates Server-Side Request Forgery (SSRF), Command Injection (CWE-78), Cryptographic Failures (information disclosure), SQL Injection, and Prototype Pollution within an Express.js API.
  • CTF-Ready Code: The code includes hints and flags embedded within comments and API responses, making it suitable for Capture The Flag (CTF) exercises or security testing scenarios.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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 containing multiple critical security vulnerabilities that must be addressed before merge. While this appears to be for a CTF/testing environment, the vulnerabilities present significant security risks:

Critical Issues Found:

  • OS Command Injection (CWE-78): Direct execution of unsanitized user input
  • Server-Side Request Forgery (CWE-918): Unrestricted URL fetching allowing internal resource access
  • SQL Injection (CWE-89): Direct string interpolation in database queries
  • Prototype Pollution (CWE-1321): Unsafe object merging allowing prototype modification
  • Information Disclosure (CWE-200): Direct exposure of configuration data
  • Cross-Site Scripting (CWE-79): Unescaped HTML output
  • Missing Input Validation: Multiple endpoints lack basic parameter validation

Recommendation:

BLOCK MERGE - These vulnerabilities create severe security risks including remote code execution, data exfiltration, and system compromise. All identified security issues must be remediated with the provided code suggestions before this can be safely merged.

If this is intentionally vulnerable code for educational/testing purposes, it should be clearly documented and isolated from production systems with appropriate security controls.


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 020_api_L36.js
const host = req.query.host;

// Command injection vulnerability
exec(`ping -c 4 ${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: Direct command execution with unsanitized user input creates critical OS command injection vulnerability1. The host parameter is directly interpolated into the exec command without validation or sanitization.

Suggested change
exec(`ping -c 4 ${host}`, (error, stdout, stderr) => {
exec(`ping -c 4 ${require('child_process').execSync('echo').toString().includes(host) ? '' : host.replace(/[;&|`$()]/g, '')}`, (error, stdout, stderr) => {

Footnotes

  1. CWE-78: OS Command Injection - https://cwe.mitre.org/data/definitions/78.html

Comment thread 020_api_L36.js
const ssrfFlag = 'Try accessing internal resources with file:///etc/passwd or http://localhost';

// No validation on URL - SSRF vulnerability
fetch(url)
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: Server-Side Request Forgery (SSRF) vulnerability allows attackers to access internal resources1. The URL parameter is used directly without validation, enabling access to localhost, internal networks, and file system.

Suggested change
fetch(url)
// Validate URL to prevent SSRF
if (!url || !url.match(/^https?:\/\/[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(\/.*)?$/)) {
return res.status(400).json({ error: 'Invalid URL format' });
}
// Block internal/private IP ranges
const blockedPatterns = [
/localhost/i, /127\.0\.0\.1/, /0\.0\.0\.0/, /10\./, /172\.(1[6-9]|2[0-9]|3[01])\./, /192\.168\./
];
if (blockedPatterns.some(pattern => pattern.test(url))) {
return res.status(403).json({ error: 'Access to internal resources is forbidden' });
}
fetch(url)

Footnotes

  1. CWE-918: Server-Side Request Forgery (SSRF) - https://cwe.mitre.org/data/definitions/918.html

Comment thread 020_api_L36.js
Comment on lines +69 to +70
query(`SELECT id, username, email, role FROM users WHERE username LIKE '%${filter}%'`,
null,
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 through direct string interpolation in database query1. The filter parameter is directly concatenated into the SQL query without parameterization.

Suggested change
query(`SELECT id, username, email, role FROM users WHERE username LIKE '%${filter}%'`,
null,
query(`SELECT id, username, email, role FROM users WHERE username LIKE ?`,
[`%${filter}%`],

Footnotes

  1. CWE-89: SQL Injection - https://cwe.mitre.org/data/definitions/89.html

Comment thread 020_api_L36.js
Comment on lines +86 to +96
function merge(target, source) {
for (let key in source) {
if (typeof source[key] === 'object' && source[key] !== null) {
if (!target[key]) target[key] = {};
merge(target[key], source[key]);
} else {
target[key] = source[key];
}
}
return target;
}
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 in recursive merge function1. The function allows modification of Object.prototype through malicious payloads like {"__proto__": {"polluted": true}}.

Suggested change
function merge(target, source) {
for (let key in source) {
if (typeof source[key] === 'object' && source[key] !== null) {
if (!target[key]) target[key] = {};
merge(target[key], source[key]);
} else {
target[key] = source[key];
}
}
return target;
}
function merge(target, source) {
for (let key in source) {
// Prevent prototype pollution
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
continue;
}
if (typeof source[key] === 'object' && source[key] !== null) {
if (!target[key]) target[key] = {};
merge(target[key], source[key]);
} else {
target[key] = source[key];
}
}
return target;
}

Footnotes

  1. CWE-1321: Prototype Pollution - https://cwe.mitre.org/data/definitions/1321.html

Comment thread 020_api_L36.js
// A2: Cryptographic Failures - Exposing sensitive information in API
router.get('/config', (req, res) => {
// Leaking sensitive configuration
res.json(config);
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: Information disclosure through direct config exposure1. This endpoint exposes the entire configuration object which may contain sensitive data like database credentials, API keys, or internal system information.

Suggested change
res.json(config);
// Return only safe configuration values
const safeConfig = {
appName: config.appName || 'API',
version: config.version || '1.0.0',
environment: config.environment || 'production'
};
res.json(safeConfig);

Footnotes

  1. CWE-200: Information Exposure - https://cwe.mitre.org/data/definitions/200.html

Comment thread 020_api_L36.js
Comment on lines +49 to +52
const output = `<pre>${stdout}</pre>
<!-- Try command injection with semicolons: 127.0.0.1; cat /etc/passwd -->
<!-- For Windows: 127.0.0.1 & type c:\\flag.txt -->
<!-- CTF{command_injection_vulnerability} -->`;
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 through unescaped HTML output1. The stdout content is directly embedded in HTML without sanitization, allowing script injection if command output contains malicious content.

Suggested change
const output = `<pre>${stdout}</pre>
<!-- Try command injection with semicolons: 127.0.0.1; cat /etc/passwd -->
<!-- For Windows: 127.0.0.1 & type c:\\flag.txt -->
<!-- CTF{command_injection_vulnerability} -->`;
const output = `<pre>${stdout.replace(/</g, '&lt;').replace(/>/g, '&gt;')}</pre>`;

Footnotes

  1. CWE-79: Cross-site Scripting (XSS) - https://cwe.mitre.org/data/definitions/79.html

Comment thread 020_api_L36.js
// {fact rule=os-command-injection@v1.0 defects=1}
// A3: Injection - Command Injection
router.get('/ping', (req, res) => {
const host = req.query.host;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing input validation allows undefined or null values to be passed to the exec command, potentially causing application crashes or unexpected behavior.

Suggested change
const host = req.query.host;
const host = req.query.host;
if (!host || typeof host !== 'string' || host.trim() === '') {
return res.status(400).json({ error: 'Host parameter is required and must be a valid string' });
}

Comment thread 020_api_L36.js

// A10: Server-Side Request Forgery (SSRF)
router.get('/fetch-data', (req, res) => {
const url = req.query.url;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing input validation for URL parameter allows undefined or malformed URLs to cause fetch errors and potential application crashes.

Suggested change
const url = req.query.url;
const url = req.query.url;
if (!url || typeof url !== 'string') {
return res.status(400).json({ error: 'URL parameter is required and must be a string' });
}

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