Skip to content

Commit 1c2fdc8

Browse files
committed
JS: Ignore more webpack modules
1 parent 09502c6 commit 1c2fdc8

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

javascript/ql/lib/semmle/javascript/frameworks/Bundling.qll

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ private predicate isBrowserifyDependencyMap(ObjectExpr deps) {
106106
* or their name must contain the substring "webpack_require"
107107
* or "webpack_module_template_argument".
108108
*/
109-
private predicate isWebpackModule(FunctionExpr m) {
109+
private predicate isWebpackModule(Function m) {
110110
forex(Parameter parm | parm = m.getAParameter() |
111111
exists(string name | name = parm.getName() |
112-
name.regexpMatch("module|exports|.*webpack_require.*|.*webpack_module_template_argument.*")
112+
name.regexpMatch("module|exports|.*webpack_require.*|.*webpack_module_template_argument.*|.*unused_webpack_module.*")
113113
)
114114
)
115115
}
@@ -161,6 +161,23 @@ predicate isWebpackBundle(ArrayExpr ae) {
161161
)
162162
}
163163

164+
/**
165+
* Holds if `object` looks like a Webpack bundle of form:
166+
* ```javascript
167+
* var __webpack_modules__ = ({
168+
* "file1": ((module, __webpack__exports__, __webpack_require__) => ...)
169+
* ...
170+
* })
171+
* ```
172+
*/
173+
predicate isWebpackNamedBundle(ObjectExpr object) {
174+
isWebpackModule(object.getAProperty().getInit().getUnderlyingValue()) and
175+
exists(VarDef def |
176+
def.getSource().(Expr).getUnderlyingValue() = object and
177+
def.getTarget().(VarRef).getName() = "__webpack_modules__"
178+
)
179+
}
180+
164181
/**
165182
* Holds if `tl` is a collection of concatenated files by [atpackager](https://github.com/ariatemplates/atpackager).
166183
*/
@@ -233,7 +250,8 @@ predicate isDirectiveBundle(TopLevel tl) { exists(BundleDirective d | d.getTopLe
233250
predicate isBundle(TopLevel tl) {
234251
exists(Expr e | e.getTopLevel() = tl |
235252
isBrowserifyBundle(e) or
236-
isWebpackBundle(e)
253+
isWebpackBundle(e) or
254+
isWebpackNamedBundle(e)
237255
)
238256
or
239257
isMultiPartBundle(tl)

javascript/ql/lib/semmle/javascript/security/regexp/RegExpTreeView.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
private import codeql.regex.nfa.NfaUtils as NfaUtils
66
private import codeql.regex.RegexTreeView
7+
private import semmle.javascript.frameworks.Bundling
78

89
/** An implementation that parses a regular expression into a tree of `RegExpTerm`s. */
910
module RegExpTreeView implements RegexTreeViewSig {
@@ -42,7 +43,11 @@ module RegExpTreeView implements RegexTreeViewSig {
4243
*
4344
* For javascript we make the pragmatic performance optimization to ignore minified files.
4445
*/
45-
predicate isExcluded(RegExpParent parent) { parent.(Expr).getTopLevel().isMinified() }
46+
predicate isExcluded(RegExpParent parent) {
47+
parent.(Expr).getTopLevel().isMinified()
48+
or
49+
isBundle(parent.(Expr).getTopLevel())
50+
}
4651

4752
/**
4853
* Holds if `root` has the `i` flag for case-insensitive matching.

0 commit comments

Comments
 (0)