Skip to content

fix: validate plugin names in tailwind config generator to prevent RCE#275

Open
TemaDeveloper wants to merge 1 commit intonextlevelbuilder:mainfrom
TemaDeveloper:fix/tailwind-config-code-injection
Open

fix: validate plugin names in tailwind config generator to prevent RCE#275
TemaDeveloper wants to merge 1 commit intonextlevelbuilder:mainfrom
TemaDeveloper:fix/tailwind-config-code-injection

Conversation

@TemaDeveloper
Copy link
Copy Markdown

Summary

Fixes the Code Injection → RCE vulnerability (CVSS 9.3, Critical) in tailwind_config_gen.py reported in #246.

The _format_plugins() method interpolated plugin names directly into JavaScript require('...') statements without any sanitization. A plugin name containing a single quote (e.g. fs').writeFileSync(...)) could break out of the require() call and inject arbitrary JavaScript that executes when Node.js loads the generated tailwind.config.js.

Fix

  • Add a strict regex allowlist (^(@[a-zA-Z0-9_-]+/)?[a-zA-Z0-9_-]+(/[a-zA-Z0-9_.-]+)*$) that matches valid npm package name patterns
  • Reject any plugin name that doesn't match before generating output, raising a ValueError with a descriptive message
  • This blocks all injection vectors: single quotes, parentheses, semicolons, backticks, etc.

Testing

Input Result
@tailwindcss/typography Accepted
tailwindcss-animate Accepted
some-plugin/sub-path Accepted
fs').writeFileSync('/tmp/rce','PWNED'),require('fs Rejected with ValueError
legit'); process.exit(1); // Rejected with ValueError

Normal config generation with valid plugins produces identical output — no regressions.

Closes #246

…de injection

The _format_plugins() method interpolated plugin names directly into
require() statements without sanitization. A plugin name containing
a single quote could break out of require() and inject arbitrary
JavaScript that executes when Node.js loads the generated config.

Add a strict regex allowlist matching valid npm package name patterns
(optional @scope, alphanumeric/hyphen/underscore, optional subpath).
Reject any plugin name that doesn't match before generating output.

Closes nextlevelbuilder#246
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.

Tailwind Config Generator Code Injection Leading to RCE

1 participant