Skip to content

fix(scripts): fix escaping and shell commands - #560

Merged
uniqueg merged 2 commits into
devfrom
fix/script-commands
Nov 3, 2026
Merged

uniqueg merged 2 commits into
devfrom
fix/script-commands

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes the CodeQL findings in the build scripts (alerts 1 to 7). No component code changes: the generated styles stay byte-identical.

  • Escaping (js/double-escaping): escapeTemplateLiteral in scripts/utils.js escapes backslashes first, then backticks and ${. The old order turned a backtick into two backslashes and a bare backtick, which ended the template literal. scripts/tailwind/index.js now uses the helper in all three places.
  • Shell commands (js/shell-command-injection-from-environment): scripts/build.js, scripts/tailwind/index.js and scripts/make-metadata.js run their commands with execFileSync and an argument list. The tsc and make-metadata.js calls weren't flagged, but they are converted too, so that no shell string is left in the build.
  • CI: the Lint job's script test step also runs scripts/utils.test.js, and is now called "Test the scripts".

How it was verified

  • node --test scripts/release.test.js scripts/utils.test.js: 27 of 27 pass. The new tests failed before the fix.
  • npm run build -- --force: all 9 tasks pass.
  • All 28 generated tw-styles.ts files are byte-identical to a baseline build of dev.
  • Path with a space, reproduced before the fix: node "<dir with a space>/scripts/build.js" failed with Cannot find module '.../sp'. It now builds the package. scripts/tailwind/index.js also works in a package directory with a space, with the same output.
  • This was a manual check, as an automated one would need a full package build. It isn't part of the test suite.
  • Not run locally: the browser tests (WebKit isn't installed here). CI runs them.

Declined review findings

  • Windows: execFileSync without a shell can't start the .cmd shims of npx, tsc and custom-elements-manifest, so building on Windows would stop working. The repository doesn't document Windows support, CI runs only on Linux, the clean scripts use rm -rf, and the watch mode's spawn("npx", ...) already has this limit.
  • Extracting the triplicated Lit template wrapper: this already exists on dev and the three copies differ in whitespace, so merging them would change the output in watch mode. Out of scope here.
  • Template literal around commanderOpts.prefix: kept on purpose. It makes explicit that a missing prefix stays the literal string undefined, which make-react.js handles.
  • Test the wrapper at the call sites, for...of with messages, a test:scripts npm script, carriage returns in the helper's comment: minor. assert.strictEqual already shows the failing input, and the old code handled carriage returns the same way.

Closes #558

🤖 Generated with Claude Code

https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG

Summary by Sourcery

Harden build-time scripts against command injection and invalid template-literal escaping while preserving generated styles.

Bug Fixes:

  • Prevent shell command injection in build, metadata, and Tailwind script execution.
  • Correctly escape backslashes, backticks, and interpolation markers when generating Lit template literals.

Enhancements:

  • Centralize template-literal escaping and apply it consistently across Tailwind style generation.

CI:

  • Expand the CI script test step to cover utility-script tests.

Tests:

  • Add coverage for template-literal escaping, including backslashes, backticks, and interpolation sequences.

Escape backslashes before backticks when writing generated CSS into a
template literal, and also escape `${`. The old order turned a backtick
into two backslashes and a bare backtick, which ended the literal.

Run the build commands without a shell, so that a checkout path with a
space or a shell metacharacter no longer breaks the build or runs as a
command.

Closes #558

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
@sourcery-ai

sourcery-ai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Hardens the build scripts by using argument-safe process execution and fixes template-literal escaping through a shared, tested utility, while extending CI to run the new utility tests; generated styles are intended to remain byte-identical.

Sequence diagram for argument-safe build command execution

sequenceDiagram
    participant Build as scripts/build.js
    participant Node as process.execPath
    participant Metadata as make-metadata.js
    participant CEM as custom-elements-manifest
    participant TSC as tsc

    Build->>Node: execFileSync(make-CEMconfig.js)
    Build->>Node: execFileSync(make-metadata.js, --outdir, dir)
    Node->>Metadata: Run with argument list
    Metadata->>CEM: execFileSync(analyze, --litelement, --outdir, outdir)
    Build->>Node: execFileSync(make-react.js, -p, prefix)
    Build->>TSC: execFileSync(--project, --outdir, npmDir)
Loading

Sequence diagram for safe Tailwind style generation

sequenceDiagram
    participant Tailwind as scripts/tailwind/index.js
    participant Npx as npx
    participant CSS as Generated CSS file
    participant Utils as escapeTemplateLiteral
    participant TS as tw-styles.ts

    Tailwind->>Npx: execFileSync(@tailwindcss/cli, -i, configPath, -o, componentCssPath)
    Npx->>CSS: Write CSS
    Tailwind->>CSS: readFileSync(componentCssPath, utf8)
    Tailwind->>Utils: escapeTemplateLiteral(text)
    Utils-->>Tailwind: Escaped backslashes, backticks, and ${
    Tailwind->>TS: Write CSS inside Lit template
Loading

Flow diagram for script test coverage in CI

flowchart LR
    Lint[Lint job] --> Tests[node --test]
    Tests --> Release[release.test.js]
    Tests --> Utils[utils.test.js]
    Utils --> Escape[escapeTemplateLiteral]
    Escape --> Verify[Original text preserved]
Loading

File-Level Changes

Change Details Files
Correct template-literal escaping and centralize it for generated CSS content.
  • Added a utility that escapes backslashes before backticks and interpolation markers.
  • Replaced duplicated Tailwind escaping logic in watch, initial-read, and non-watch paths.
  • Added tests covering round-trip evaluation and escaping order.
scripts/utils.js
scripts/utils.test.js
scripts/tailwind/index.js
Replace shell-interpolated build commands with argument-based child-process execution.
  • Switched build orchestration and metadata generation from execSync to execFileSync.
  • Passed paths and options as separate arguments, including paths containing spaces.
  • Converted Node, TypeScript, Tailwind, and custom-elements-manifest invocations.
scripts/build.js
scripts/make-metadata.js
scripts/tailwind/index.js
Expand CI coverage to run all script tests.
  • Renamed the script test step and added the utility test file to its Node test command.
.github/workflows/ci.yml

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.89%. Comparing base (2ad5b3f) to head (9414293).
⚠️ Report is 1 commits behind head on dev.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev     #560   +/-   ##
=======================================
  Coverage   70.89%   70.89%           
=======================================
  Files          23       23           
  Lines        5638     5638           
  Branches      190      190           
=======================================
  Hits         3997     3997           
  Misses       1636     1636           
  Partials        5        5           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@uniqueg
uniqueg marked this pull request as ready for review November 3, 2026 03:34
@uniqueg
uniqueg requested a review from anuragxxd as a code owner November 3, 2026 03:34

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Fixed security issues:

  • Command injection from untrusted input passed to child_process commands (link) · Dashboard
Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="scripts/tailwind/index.js" line_range="168" />
<code_context>
-          execSync(
-            `npx @tailwindcss/cli -i ${configPath} -o ${componentCssPath}`,
+          execFileSync(
+            "npx",
+            ["@tailwindcss/cli", "-i", configPath, "-o", componentCssPath],
             {
</code_context>
<issue_to_address>
**Build exits on Windows**

When the build runs on Windows and these CLIs resolve to `.cmd` shims, `execFileSync` cannot launch the `npx`, `tsc`, or `custom-elements-manifest` shims without a shell, so the first affected command fails and aborts the build.

Run these commands in a way that supports Windows `.cmd` shims, such as enabling a shell.

Also at `scripts/make-metadata.js:12-15`, `scripts/build.js:105-111`.
</issue_to_address>

Linked issues

#558 fix(scripts): fix escaping and shell commands · 3 of 3 met

# Requirement Status Notes
1 Escape generated CSS correctly in a tested helper, including backticks and ${. ✅ Met The helper escapes backslashes first, then backticks and ${; tests check the escaped text evaluates to its original value.
2 Run build and Tailwind commands without a shell so paths with spaces or shell metacharacters are safe. ✅ Met The affected commands use execFileSync with separate arguments; the Tailwind watch path uses spawn with an argument array.
3 Keep generated styles byte-identical. ✅ Met The PR reports that all 28 generated tw-styles.ts files matched a baseline build of dev.

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: scripts/tailwind/index.js:168


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread scripts/tailwind/index.js Resolved
@uniqueg
uniqueg merged commit f921689 into dev Nov 3, 2026
19 checks passed
@uniqueg
uniqueg deleted the fix/script-commands branch November 3, 2026 03:45
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.

fix(scripts): fix escaping and shell commands

1 participant