security: replace new Function() eval with direct ESM import#92
Open
xiaolai wants to merge 1 commit intopbakaus:mainfrom
Open
security: replace new Function() eval with direct ESM import#92xiaolai wants to merge 1 commit intopbakaus:mainfrom
xiaolai wants to merge 1 commit intopbakaus:mainfrom
Conversation
ANTIPATTERNS is already exported from src/detect-antipatterns.mjs, so the three build scripts that previously extracted it via regex and evaluated it with new Function() can simply import it directly. This eliminates an arbitrary code execution surface at build time and dev-server startup: a tampered detect-antipatterns.mjs could previously execute arbitrary code silently during the regex-to-eval path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
new Function()code evaluation with direct ESM imports of the already-exportedANTIPATTERNSarrayMotivation
Three build scripts (
scripts/build.js,scripts/build-extension.js,scripts/lib/sub-pages-data.js) extract theANTIPATTERNSarray fromsrc/detect-antipatterns.mjsvia regex, then evaluate it withnew Function(). SinceANTIPATTERNSis already exported from the module (line 3577), this indirection is unnecessary.The
new Function()pattern means any commit that modifies the matched regex region indetect-antipatterns.mjsgets arbitrary code execution at:bun run build(build.js + build-extension.js)bun run dev(sub-pages-data.js runs at server boot)With a direct ESM import, a malformed ANTIPATTERNS entry produces a parse error at import time rather than silent code execution.
Changes
scripts/build.jsnew Function()invalidateAntipatternRules()import { ANTIPATTERNS }from sourcescripts/build-extension.jsnew Function()to generateantipatterns.jsonimport { ANTIPATTERNS }from sourcescripts/lib/sub-pages-data.jsreadAntipatternRules()with regex +new Function()readAntipatternRules()returns importedANTIPATTERNSdirectlyTest plan
bun run buildcompletes without errorsbun run devstarts without errorsnode scripts/build-extension.jsgeneratesextension/detector/antipatterns.jsonwith correct rule count