Skip to content

Commit 2d907f8

Browse files
committed
have the aliasPropertyPresenceStep step over extend calls
1 parent e0b876d commit 2d907f8

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

javascript/ql/lib/semmle/javascript/security/dataflow/UnsafeJQueryPluginQuery.qll

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,19 @@ private predicate aliasPropertyPresenceStepHelper(
7676
) {
7777
exists(PropertyPresenceSanitizer sanitizer |
7878
src = sanitizer.getPropRead() and
79-
sink = AccessPath::getAnAliasedSourceNode(src) and
8079
srcBB = src.getBasicBlock() and
81-
sinkBB = sink.getBasicBlock()
80+
sinkBB = sink.getBasicBlock() and
81+
(
82+
sink = AccessPath::getAnAliasedSourceNode(src)
83+
or
84+
// step over extend calls
85+
exists(ExtendCall extendCall, string prop |
86+
src = extendCall.getASourceOperand().getALocalSource().getAPropertyReference(prop) and
87+
sink =
88+
[extendCall, extendCall.getDestinationOperand()]
89+
.(DataFlow::SourceNode)
90+
.getAPropertyReference(prop)
91+
)
92+
)
8293
)
8394
}

javascript/ql/test/query-tests/Security/CWE-079/UnsafeJQueryPlugin/UnsafeJQueryPlugin.expected

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
WARNING: Unused predicate sink (/home/erik/dev/code/ql/javascript/ql/src/Security/CWE-079/UnsafeJQueryPlugin.ql:30,6-10)
2+
WARNING: Unused predicate source (/home/erik/dev/code/ql/javascript/ql/src/Security/CWE-079/UnsafeJQueryPlugin.ql:28,10-16)
13
nodes
24
| unsafe-jquery-plugin.js:2:38:2:44 | options |
35
| unsafe-jquery-plugin.js:2:38:2:44 | options |
@@ -121,6 +123,12 @@ nodes
121123
| unsafe-jquery-plugin.js:179:5:179:11 | options |
122124
| unsafe-jquery-plugin.js:179:5:179:18 | options.target |
123125
| unsafe-jquery-plugin.js:179:5:179:18 | options.target |
126+
| unsafe-jquery-plugin.js:185:28:185:34 | options |
127+
| unsafe-jquery-plugin.js:185:28:185:34 | options |
128+
| unsafe-jquery-plugin.js:186:21:186:27 | options |
129+
| unsafe-jquery-plugin.js:186:21:186:30 | options.of |
130+
| unsafe-jquery-plugin.js:192:19:192:28 | options.of |
131+
| unsafe-jquery-plugin.js:192:19:192:28 | options.of |
124132
edges
125133
| unsafe-jquery-plugin.js:2:38:2:44 | options | unsafe-jquery-plugin.js:3:5:3:11 | options |
126134
| unsafe-jquery-plugin.js:2:38:2:44 | options | unsafe-jquery-plugin.js:3:5:3:11 | options |
@@ -245,6 +253,11 @@ edges
245253
| unsafe-jquery-plugin.js:178:27:178:33 | options | unsafe-jquery-plugin.js:179:5:179:11 | options |
246254
| unsafe-jquery-plugin.js:179:5:179:11 | options | unsafe-jquery-plugin.js:179:5:179:18 | options.target |
247255
| unsafe-jquery-plugin.js:179:5:179:11 | options | unsafe-jquery-plugin.js:179:5:179:18 | options.target |
256+
| unsafe-jquery-plugin.js:185:28:185:34 | options | unsafe-jquery-plugin.js:186:21:186:27 | options |
257+
| unsafe-jquery-plugin.js:185:28:185:34 | options | unsafe-jquery-plugin.js:186:21:186:27 | options |
258+
| unsafe-jquery-plugin.js:186:21:186:27 | options | unsafe-jquery-plugin.js:186:21:186:30 | options.of |
259+
| unsafe-jquery-plugin.js:186:21:186:30 | options.of | unsafe-jquery-plugin.js:192:19:192:28 | options.of |
260+
| unsafe-jquery-plugin.js:186:21:186:30 | options.of | unsafe-jquery-plugin.js:192:19:192:28 | options.of |
248261
#select
249262
| unsafe-jquery-plugin.js:3:5:3:11 | options | unsafe-jquery-plugin.js:2:38:2:44 | options | unsafe-jquery-plugin.js:3:5:3:11 | options | Potential XSS vulnerability in the $@. | unsafe-jquery-plugin.js:2:19:63:2 | functio ... \\t\\t}\\n\\n\\t} | '$.fn.my_plugin' plugin |
250263
| unsafe-jquery-plugin.js:5:5:5:18 | options.target | unsafe-jquery-plugin.js:2:38:2:44 | options | unsafe-jquery-plugin.js:5:5:5:18 | options.target | Potential XSS vulnerability in the $@. | unsafe-jquery-plugin.js:2:19:63:2 | functio ... \\t\\t}\\n\\n\\t} | '$.fn.my_plugin' plugin |
@@ -268,3 +281,4 @@ edges
268281
| unsafe-jquery-plugin.js:157:44:157:59 | options.target.a | unsafe-jquery-plugin.js:153:38:153:44 | options | unsafe-jquery-plugin.js:157:44:157:59 | options.target.a | Potential XSS vulnerability in the $@. | unsafe-jquery-plugin.js:153:19:158:2 | functio ... NCY]\\n\\t} | '$.fn.my_plugin' plugin |
269282
| unsafe-jquery-plugin.js:170:6:170:11 | target | unsafe-jquery-plugin.js:160:38:160:44 | options | unsafe-jquery-plugin.js:170:6:170:11 | target | Potential XSS vulnerability in the $@. | unsafe-jquery-plugin.js:160:19:173:2 | functio ... \\t\\t}\\n\\n\\t} | '$.fn.my_plugin' plugin |
270283
| unsafe-jquery-plugin.js:179:5:179:18 | options.target | unsafe-jquery-plugin.js:178:27:178:33 | options | unsafe-jquery-plugin.js:179:5:179:18 | options.target | Potential XSS vulnerability in the $@. | unsafe-jquery-plugin.js:178:18:180:2 | functio ... T OK\\n\\t} | '$.fn.my_plugin' plugin |
284+
| unsafe-jquery-plugin.js:192:19:192:28 | options.of | unsafe-jquery-plugin.js:185:28:185:34 | options | unsafe-jquery-plugin.js:192:19:192:28 | options.of | Potential XSS vulnerability in the $@. | unsafe-jquery-plugin.js:185:18:194:2 | functio ... et);\\n\\t} | '$.fn.position' plugin |

javascript/ql/test/query-tests/Security/CWE-079/UnsafeJQueryPlugin/unsafe-jquery-plugin.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,14 @@
182182
$(document).find(options.target); // OK
183183
}});
184184

185+
$.fn.position = function( options ) {
186+
if ( !options || !options.of ) {
187+
return doSomethingElse( this, arguments );
188+
}
189+
// extending options
190+
options = $.extend( {}, options );
191+
192+
var target = $( options.of ); // NOT OK
193+
console.log(target);
194+
};
185195
});

0 commit comments

Comments
 (0)