Skip to content

Commit 0a98679

Browse files
committed
JS: Rename Vue::Instance to Vue::Component
1 parent 4a1fb5d commit 0a98679

File tree

5 files changed

+28
-24
lines changed

5 files changed

+28
-24
lines changed

javascript/ql/src/Vue/ArrowMethodOnVueInstance.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import javascript
1313

14-
from Vue::Instance instance, DataFlow::Node def, DataFlow::FunctionNode arrow, ThisExpr dis
14+
from Vue::Component instance, DataFlow::Node def, DataFlow::FunctionNode arrow, ThisExpr dis
1515
where
1616
instance.getABoundFunction() = def and
1717
arrow.flowsTo(def) and

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

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module Vue {
2121
VueExtend() { this = vue().getAMemberCall("extend") }
2222
}
2323

24-
private newtype TInstance =
24+
private newtype TComponent =
2525
MkVueInstance(DataFlow::NewNode def) { def = vue().getAnInstantiation() } or
2626
MkExtendedVue(VueExtend extend) or
2727
MkExtendedInstance(VueExtend extend, DataFlow::NewNode sub) {
@@ -82,20 +82,24 @@ module Vue {
8282
}
8383

8484
/**
85-
* A Vue instance definition.
85+
* A Vue component, such as a `new Vue({ ... })` call or a `.vue` file.
8686
*
87-
* This includes both explicit instantiations of Vue objects, and
88-
* implicit instantiations in the form of components or Vue
89-
* extensions that have not yet been instantiated to a Vue instance.
87+
* Generally speaking, a component is always created by calling `Vue.extend()` or
88+
* calling `extend` on another component.
89+
* Often the `Vue.extend()` call is performed by the Vue
90+
* framework, however, so the call is not always visible in the user code.
91+
* For instance, `new Vue(obj)` is shorthand for `new (Vue.extend(obj))`.
9092
*
91-
* The following instances are recognized:
93+
* This class covers both the explicit `Vue.extend()` calls an those implicit in the framework.
94+
*
95+
* The following types of components are recognized:
9296
* - `new Vue({...})`
9397
* - `Vue.extend({...})`
9498
* - `new ExtendedVue({...})`
9599
* - `Vue.component("my-component", {...})`
96100
* - single file components in .vue files
97101
*/
98-
class Instance extends TInstance {
102+
class Component extends TComponent {
99103
/** Gets a textual representation of this element. */
100104
string toString() { none() } // overridden in subclasses
101105

@@ -332,7 +336,7 @@ module Vue {
332336
/**
333337
* A Vue instance from `new Vue({...})`.
334338
*/
335-
class VueInstance extends Instance, MkVueInstance {
339+
class VueInstance extends Component, MkVueInstance {
336340
DataFlow::NewNode def;
337341

338342
VueInstance() { this = MkVueInstance(def) }
@@ -353,7 +357,7 @@ module Vue {
353357
/**
354358
* An extended Vue from `Vue.extend({...})`.
355359
*/
356-
class ExtendedVue extends Instance, MkExtendedVue {
360+
class ExtendedVue extends Component, MkExtendedVue {
357361
VueExtend extend;
358362

359363
ExtendedVue() { this = MkExtendedVue(extend) }
@@ -374,7 +378,7 @@ module Vue {
374378
/**
375379
* An instance of an extended Vue, for example `instance` of `var Ext = Vue.extend({...}); var instance = new Ext({...})`.
376380
*/
377-
class ExtendedInstance extends Instance, MkExtendedInstance {
381+
class ExtendedInstance extends Component, MkExtendedInstance {
378382
VueExtend extend;
379383
DataFlow::NewNode sub;
380384

@@ -391,7 +395,7 @@ module Vue {
391395
override DataFlow::Node getOwnOptionsObject() { result = sub.getArgument(0) }
392396

393397
override DataFlow::Node getOption(string name) {
394-
result = Instance.super.getOption(name)
398+
result = Component.super.getOption(name)
395399
or
396400
result = MkExtendedVue(extend).(ExtendedVue).getOption(name)
397401
}
@@ -402,7 +406,7 @@ module Vue {
402406
/**
403407
* A Vue component from `Vue.component("my-component", { ... })`.
404408
*/
405-
class ComponentRegistration extends Instance, MkComponentRegistration {
409+
class ComponentRegistration extends Component, MkComponentRegistration {
406410
DataFlow::CallNode def;
407411

408412
ComponentRegistration() { this = MkComponentRegistration(def) }
@@ -423,7 +427,7 @@ module Vue {
423427
/**
424428
* A single file Vue component in a `.vue` file.
425429
*/
426-
class SingleFileComponent extends Instance, MkSingleFileComponent {
430+
class SingleFileComponent extends Component, MkSingleFileComponent {
427431
VueFile file;
428432

429433
SingleFileComponent() { this = MkSingleFileComponent(file) }
@@ -496,7 +500,7 @@ module Vue {
496500
*/
497501
class InstanceHeapStep extends TaintTracking::SharedTaintStep {
498502
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
499-
exists(Instance i, string name, DataFlow::FunctionNode bound |
503+
exists(Component i, string name, DataFlow::FunctionNode bound |
500504
bound.flowsTo(i.getABoundFunction()) and
501505
not bound.getFunction() instanceof ArrowFunctionExpr and
502506
succ = bound.getReceiver().getAPropertyRead(name) and
@@ -531,7 +535,7 @@ module Vue {
531535
*/
532536
class VHtmlSourceWrite extends TaintTracking::SharedTaintStep {
533537
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
534-
exists(Vue::Instance instance, string expr, VHtmlAttribute attr |
538+
exists(Vue::Component instance, string expr, VHtmlAttribute attr |
535539
attr.getAttr().getRoot() =
536540
instance.getTemplateElement().(Vue::Template::HtmlElement).getElement() and
537541
expr = attr.getAttr().getValue() and
@@ -638,7 +642,7 @@ module Vue {
638642
or
639643
result = routeConfig().getMember("beforeEnter").getParameter([0, 1]).getAnImmediateUse()
640644
or
641-
exists(Instance i |
645+
exists(Component i |
642646
result = i.getABoundFunction().getAFunctionValue().getReceiver().getAPropertyRead("$route")
643647
or
644648
result =
@@ -664,7 +668,7 @@ module Vue {
664668
this = routeObject().getAPropertyRead(name)
665669
or
666670
exists(string prop |
667-
this = any(Instance i).getWatchHandler(prop).getParameter([0, 1]) and
671+
this = any(Component i).getWatchHandler(prop).getParameter([0, 1]) and
668672
name = prop.regexpCapture("\\$route\\.(params|query|hash|path|fullPath)\\b.*", 1)
669673
)
670674
|

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private module VueAPI {
2626
* or equivalent.
2727
*/
2828
class VueConfigObject extends API::Node {
29-
VueConfigObject() { this.getARhs() = any(Vue::Instance i).getOwnOptionsObject() }
29+
VueConfigObject() { this.getARhs() = any(Vue::Component i).getOwnOptionsObject() }
3030

3131
/** Gets an API node representing `this` in the Vue component. */
3232
API::Node getAnInstanceRef() {

javascript/ql/src/semmle/javascript/security/dataflow/Xss.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ module DomBasedXss {
347347
class VueTemplateSink extends DomBasedXss::Sink {
348348
VueTemplateSink() {
349349
// Note: don't use Vue::Instance#getTemplate as it includes an unwanted getALocalSource() step
350-
this = any(Vue::Instance i).getOption("template")
350+
this = any(Vue::Component i).getOption("template")
351351
}
352352
}
353353

@@ -357,7 +357,7 @@ module DomBasedXss {
357357
*/
358358
class VueCreateElementSink extends DomBasedXss::Sink {
359359
VueCreateElementSink() {
360-
exists(Vue::Instance i, DataFlow::FunctionNode f |
360+
exists(Vue::Component i, DataFlow::FunctionNode f |
361361
f.flowsTo(i.getRender()) and
362362
this = f.getParameter(0).getACall().getArgument(0)
363363
)

javascript/ql/test/library-tests/frameworks/Vue/tests.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import javascript
22
import semmle.javascript.security.dataflow.Xss
33

4-
query predicate instance_getAPropertyValue(Vue::Instance i, string name, DataFlow::Node prop) {
4+
query predicate instance_getAPropertyValue(Vue::Component i, string name, DataFlow::Node prop) {
55
i.getAPropertyValue(name) = prop
66
}
77

8-
query predicate instance_getOption(Vue::Instance i, string name, DataFlow::Node prop) {
8+
query predicate instance_getOption(Vue::Component i, string name, DataFlow::Node prop) {
99
i.getOption(name) = prop
1010
}
1111

12-
query predicate instance(Vue::Instance i) { any() }
12+
query predicate instance(Vue::Component i) { any() }
1313

1414
query predicate instance_heapStep(
1515
Vue::InstanceHeapStep step, DataFlow::Node pred, DataFlow::Node succ

0 commit comments

Comments
 (0)