Skip to content

Commit be8c574

Browse files
committed
JS: Add test and comment for access path termination criteria
1 parent 0247de7 commit be8c574

File tree

2 files changed

+10
-1
lines changed
  • javascript/ql
    • src/semmle/javascript/frameworks
    • test/library-tests/frameworks/Vuex

2 files changed

+10
-1
lines changed

javascript/ql/src/semmle/javascript/frameworks/Vuex.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ module Vuex {
5353
bindingset[base, prop]
5454
private string appendToNamespace(string base, string prop) {
5555
result = base + prop + "/" and
56-
// Allow at most two occurrences of a given property name in the path
56+
// To avoid constructing infinitely long access paths,
57+
// allow at most two occurrences of a given property name in the path
5758
// (one in the base, plus the one we're appending now).
5859
count(base.indexOf("/" + prop + "/")) <= 1
5960
}

javascript/ql/test/library-tests/frameworks/Vuex/vuex.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ const Component = new Vue({
107107
},
108108
...mapMutations({ sneakyTaint3: 'setTainted3' }),
109109
...mapActions({ emitTaint4: 'doTaint4' }),
110+
loopingState() {
111+
// Make sure we do not fail by trying to compute infinitely long access paths.
112+
// 'ref' can refer to state.foo, state.foo.foo, state.foo.foo.foo, and so on.
113+
let ref = this.$store.state;
114+
while (Math.random()) {
115+
ref = ref.foo;
116+
}
117+
}
110118
}
111119
});
112120

0 commit comments

Comments
 (0)