Skip to content

harden: sanitize child_process call in generate-release-notes.js - #26

Open
anupamme wants to merge 1 commit into
leodutra:masterfrom
anupamme:fix-repo-simpleflakes-command-injection-release-notes
Open

harden: sanitize child_process call in generate-release-notes.js#26
anupamme wants to merge 1 commit into
leodutra:masterfrom
anupamme:fix-repo-simpleflakes-command-injection-release-notes

Conversation

@anupamme

Copy link
Copy Markdown

Summary

Harden input handling in scripts/generate-release-notes.js (flagged by semgrep).

Vulnerability

Field Value
ID javascript.lang.security.detect-child-process.detect-child-process
Severity HIGH
Scanner semgrep
Rule javascript.lang.security.detect-child-process.detect-child-process
File scripts/generate-release-notes.js:18
Assessment Defensive hardening

Description: Detected calls to child_process from a function argument lastTag. This could lead to a command injection if the input is user controllable. Try to avoid calls to child_process, and if it is needed ensure user input is correctly sanitized or sandboxed.

Threat Model Context

This is a Node.js library - vulnerabilities affect downstream consumers who use this package.

Changes

  • scripts/generate-release-notes.js

Behavior Preservation

The change is scoped to 1 file on the vulnerable path.

Security Invariant

Property: Shell commands never include unsanitized user input

Regression test
const { execSync } = require('child_process');
const path = require('path');

describe("Shell commands never include unsanitized user input", () => {
  const payloads = [
    "; rm -rf /",
    "$(whoami)",
    "`id`",
    "valid-tag-name"
  ];

  test.each(payloads)("rejects or escapes adversarial input: %s", (payload) => {
    const scriptPath = path.resolve(__dirname, '../scripts/generate-release-notes.js');
    
    // Mock execSync to capture command before execution
    const originalExecSync = require('child_process').execSync;
    let capturedCommand = null;
    require('child_process').execSync = jest.fn((cmd) => {
      capturedCommand = cmd;
      return '';
    });

    try {
      process.argv = ['node', scriptPath, payload];
      require(scriptPath);
    } catch (e) {
      // Script may throw due to missing git/mocking - that's OK
    } finally {
      require('child_process').execSync = originalExecSync;
      delete require.cache[require.resolve(scriptPath)];
    }

    if (capturedCommand) {
      expect(capturedCommand).not.toContain(';');
      expect(capturedCommand).not.toContain('$(');
      expect(capturedCommand).not.toContain('`');
    }
  });
});)

This test guards against regressions — it's useful independent of the code change above.


This patch removes an exploit primitive — a code pattern that, while not independently exploitable today, could be chained with other weaknesses by automated exploit-development tooling. Proactive removal of such primitives raises the bar against increasingly capable automated attack tools.


Automated security fix by OrbisAI Security

…ss security vulnerability

Automated security fix generated by OrbisAI Security
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

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