kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Modernise read_webpack_json.js to use execFileSync, bump kolibri-build

Open rtibbles opened this issue 6 months ago • 1 comments

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Overview

Modernise packages/kolibri-build/src/read_webpack_json.js to use child_process.execFileSync with an argv array instead of execSync with a concatenated shell command. The current pattern triggers CodeQL alerts for shell-command construction and PATH-resolved binary lookup, but the underlying use case (calling the local webpack_json.py helper at build time) has no need to go through a shell at all. While we're touching the file, bump the kolibri-build package version.

Complexity: Low Target branch: develop

Context

packages/kolibri-build/src/read_webpack_json.js runs during webpack configuration to gather plugin metadata from Python. It builds a shell command by string concatenation and runs it via execSync:

let command = `python ${webpack_json} --output_file ${webpack_json_tempfile} `;
if (pluginFile) {
  command += `--plugin_file ${pluginFile}`;
} else if (plugins.length) {
  const allPlugins = plugins.join(' ');
  command += `--plugins ${allPlugins}`;
  if (pluginPath) {
    command += ` --plugin_path ${pluginPath}`;
  }
}
execSync(command);

Inputs come from the webpack config builder (trusted developer/CI code, never user input), so there's no realistic attacker model — an attacker controlling these inputs already controls the build pipeline. But the shell parse is unnecessary and the string-concatenation style is fragile: any input containing spaces or shell metacharacters breaks the command silently.

The Change

Replace execSync(command) with execFileSync('python', args) using an argv array. Arguments are passed directly to the Python interpreter without going through a shell:

const args = [webpack_json, '--output_file', webpack_json_tempfile];
if (pluginFile) {
  args.push('--plugin_file', pluginFile);
} else if (plugins.length) {
  args.push('--plugins', ...plugins);
  if (pluginPath) {
    args.push('--plugin_path', pluginPath);
  }
}
execFileSync('python', args);

That clears the shell-command and PATH-resolution CodeQL alerts by construction. Also bump the kolibri-build package version in packages/kolibri-build/package.json.

Out of Scope

  • Other build helpers in packages/kolibri-build/ not flagged by the audit.
  • Switching from python to an absolute path or a virtualenv-aware lookup. The dev/CI environment is responsible for ensuring python resolves to the right interpreter.
  • The behaviour of webpack_json.py itself.

Acceptance Criteria

General

  • [ ] packages/kolibri-build/src/read_webpack_json.js uses child_process.execFileSync with an argv array instead of execSync with a concatenated string command.
  • [ ] No string concatenation of plugin paths/names into a shell command remains.
  • [ ] packages/kolibri-build/package.json version is bumped.

Testing

  • [ ] Local dev build (pnpm devserver) runs end-to-end with no plugin metadata regressions.
  • [ ] CI build pipeline runs cleanly against the change.

References

  • Node.js docs: child_process.execFileSync
  • packages/kolibri-build/src/read_webpack_json.js
  • packages/kolibri-build/src/webpack_json.py (the script being invoked)

AI usage

Drafted with Claude during a triage session. The argv-array approach is the standard mitigation for the CodeQL shell-command alerts; the kolibri-build version bump was a side note I added to keep the package metadata in step.

rtibbles avatar May 15 '26 04:05 rtibbles

Plan: Replace the shell-string execSync call in packages/kolibri-build/src/read_webpack_json.js with execFileSync using an argv array, and bump the kolibri-build package version.

  • [ ] Write the failing test
  • [ ] Implement the execFileSync change
  • [ ] Bump the kolibri-build package version
  • [ ] Smoke-test the dev build

status


@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly

How was this generated?
  • Implemented code following the pre-approved plan using test-driven development (red-green-refactor)
  • Ran the project's full test suite and linter before committing
  • For UI changes: captured live screenshots to verify rendering
  • For backend changes: verified with example API/CLI output

rtibblesbot avatar May 15 '26 04:05 rtibblesbot