@@ -30,7 +30,11 @@ private DataFlow::Node getAValueExportedByPackage() {
30
30
getAnExportFromModule ( any ( PackageJSON pack | exists ( pack .getPackageName ( ) ) ) .getMainModule ( ) )
31
31
or
32
32
// module.exports.bar.baz = result;
33
- result = getAValueExportedByPackage ( ) .( DataFlow:: PropWrite ) .getRhs ( )
33
+ exists ( DataFlow:: PropWrite write |
34
+ write = getAValueExportedByPackage ( ) and
35
+ write .getPropertyName ( ) = publicPropertyName ( ) and
36
+ result = write .getRhs ( )
37
+ )
34
38
or
35
39
// class Foo {
36
40
// bar() {} // <- result
@@ -39,15 +43,15 @@ private DataFlow::Node getAValueExportedByPackage() {
39
43
exists ( DataFlow:: SourceNode callee |
40
44
callee = getAValueExportedByPackage ( ) .( DataFlow:: NewNode ) .getCalleeNode ( ) .getALocalSource ( )
41
45
|
42
- result = callee .getAPropertyRead ( "prototype" ) .getAPropertyWrite ( ) .getRhs ( )
46
+ result = callee .getAPropertyRead ( "prototype" ) .getAPropertyWrite ( publicPropertyName ( ) ) .getRhs ( )
43
47
or
44
- result = callee .( DataFlow:: ClassNode ) .getAnInstanceMethod ( )
48
+ result = callee .( DataFlow:: ClassNode ) .getInstanceMethod ( publicPropertyName ( ) )
45
49
)
46
50
or
47
51
result = getAValueExportedByPackage ( ) .getALocalSource ( )
48
52
or
49
53
// Nested property reads.
50
- result = getAValueExportedByPackage ( ) .( DataFlow:: SourceNode ) .getAPropertyReference ( )
54
+ result = getAValueExportedByPackage ( ) .( DataFlow:: SourceNode ) .getAPropertyReference ( publicPropertyName ( ) )
51
55
or
52
56
// module.exports.foo = require("./other-module.js");
53
57
exists ( Module mod |
@@ -62,8 +66,8 @@ private DataFlow::Node getAValueExportedByPackage() {
62
66
// constructor() {} // <- result
63
67
// };
64
68
exists ( DataFlow:: ClassNode cla | cla = getAValueExportedByPackage ( ) |
65
- result = cla .getAnInstanceMethod ( ) or
66
- result = cla .getAStaticMethod ( ) or
69
+ result = cla .getInstanceMethod ( publicPropertyName ( ) ) or
70
+ result = cla .getStaticMethod ( publicPropertyName ( ) ) or
67
71
result = cla .getConstructor ( )
68
72
)
69
73
or
@@ -120,7 +124,8 @@ private DataFlow::Node getAValueExportedByPackage() {
120
124
or
121
125
// Object.defineProperty
122
126
exists ( CallToObjectDefineProperty call |
123
- [ call , call .getBaseObject ( ) ] = getAValueExportedByPackage ( )
127
+ [ call , call .getBaseObject ( ) ] = getAValueExportedByPackage ( ) and
128
+ call .getPropertyName ( ) = publicPropertyName ( )
124
129
|
125
130
result = call .getPropertyDescriptor ( ) .getALocalSource ( ) .getAPropertyReference ( "value" )
126
131
or
@@ -164,9 +169,19 @@ private DataFlow::Node getAValueExportedByPackage() {
164
169
* Gets an exported node from the module `mod`.
165
170
*/
166
171
private DataFlow:: Node getAnExportFromModule ( Module mod ) {
167
- result = mod .getAnExportedValue ( _ )
172
+ result = mod .getAnExportedValue ( publicPropertyName ( ) )
168
173
or
169
174
result = mod .getABulkExportedNode ( )
170
175
or
171
176
result .analyze ( ) .getAValue ( ) = TAbstractModuleObject ( mod )
172
177
}
178
+
179
+ /**
180
+ * Gets a property name that we consider to be public.
181
+ *
182
+ * This only allows properties whose first character is a letter or number.
183
+ */
184
+ bindingset [ result ]
185
+ private string publicPropertyName ( ) {
186
+ result .regexpMatch ( "[a-zA-Z0-9].*" )
187
+ }
0 commit comments