Detec%ng Inconsistencies in JavaScript MVC Applica%ons - - PowerPoint PPT Presentation

detec ng inconsistencies in javascript mvc applica ons
SMART_READER_LITE
LIVE PREVIEW

Detec%ng Inconsistencies in JavaScript MVC Applica%ons - - PowerPoint PPT Presentation

Detec%ng Inconsistencies in JavaScript MVC Applica%ons Frolin S. Ocariza, Jr., Karthik PaAabiraman and Ali Mesbah University of British Columbia Most popular


slide-1
SLIDE 1

Detec%ng ¡Inconsistencies ¡ in ¡JavaScript ¡MVC ¡ Applica%ons ¡

Frolin ¡S. ¡Ocariza, ¡Jr., ¡ Karthik ¡PaAabiraman ¡and ¡Ali ¡Mesbah ¡

¡

¡

¡

University of British Columbia

slide-2
SLIDE 2

JavaScript ¡

Used ¡by ¡90% ¡of ¡all ¡ websites ¡

Most ¡popular ¡ language ¡on ¡GitHub ¡

(RedMonk ¡survey) ¡

4 ¡JavaScript ¡error ¡

messages ¡on ¡average ¡per ¡ website ¡ ¡ [ISSRE’11] ¡

68% ¡of ¡JavaScript ¡

faults ¡are ¡ ¡

DOM-­‑related ¡

[ESEM’13] ¡

slide-3
SLIDE 3

DOM-­‑Related ¡Faults ¡

3

div ¡ span ¡ id=“bar” ¡ p ¡

var elem = getElementById(“car”) elem.innerHTML = “Hello World!”

DOM JS CODE DOM API Method Erroneous parameter

DOM-Related Faults are…

Prevalent Impactful Non-Trivial to Fix

slide-4
SLIDE 4

MVC ¡Frameworks ¡to ¡the ¡Rescue! ¡

4

MODEL ¡ VIEW ¡ CONTROLLER ¡ MODEL VARIABLES CONTROLLER FUNCTIONS DEFINES USES DEFINES USES USES

MVC Frameworks use two-way data binding è No DOM method calls!

slide-5
SLIDE 5

MVC ¡Frameworks ¡to ¡the ¡Rescue! ¡

5

MODEL VIEW $scope.msg = “”; <input type=“text” ng- model=“msg” /> <div ng-bind=“msg”></div> No DOM method calls è

No DOM-Related Faults in MVC

Applications!

slide-6
SLIDE 6

MVC ¡Frameworks ¡to ¡the ¡Rescue? ¡

6

MODEL ¡ VIEW ¡ CONTROLLER ¡ MODEL VARIABLES (MV) CONTROLLER FUNCTIONS (CF) DEFINES USES DEFINES USES USES IDENTIFIER INCONSISTENCIES

slide-7
SLIDE 7

MVC ¡Frameworks ¡to ¡the ¡Rescue? ¡

7

MODEL ¡ VIEW ¡ CONTROLLER ¡ MODEL VARIABLES (MV) TYPES CONTROLLER FUNCTIONS (CF) TYPES DEFINES USES DEFINES USES USES IDENTIFIER INCONSISTENCIES TYPE INCONSISTENCIES

slide-8
SLIDE 8

MVC ¡Frameworks ¡to ¡the ¡Rescue? ¡

8

Identifier and type Inconsistencies happen in real life

“What’s wrong with AngularJS?” By

  • B. Kinoshita

:

“Why you should not use AngularJS” By

  • E. Koshelko

Inconsistencies are hard to find

: e.g., No error messages thrown!

slide-9
SLIDE 9

To design a way to automatically detect identifier and type inconsistencies in MVC applications

slide-10
SLIDE 10

10

The most popular JS

MVC framework in

GitHub, StackOverfow, and YouTube

300% increase in

AngularJS usage over the past year

slide-11
SLIDE 11

Our ¡Approach ¡

11

STATIC ANALYSIS

slide-12
SLIDE 12

Our ¡Approach ¡

12

MODEL ¡ VIEW ¡ CONTROLLER ¡ MODEL ¡ VIEW ¡ CONTROLLER ¡ VIEW ¡ CONTROLLER ¡ String: a Boolean: b Object: c String: d MODEL ¡ Boolean: e String: a Boolean: e String: foo() Object: c Number: foo() Boolean: e String: bar() String: bar() String: fun() String: d String: fun()

slide-13
SLIDE 13

Our ¡Approach ¡

13

MODEL ¡ String: a Boolean: b Object: c MODEL ¡ String: d MODEL ¡ Boolean: e VIEW ¡ String: a Boolean: e String: foo() CONTROLLER ¡ Object: c Number: foo() VIEW ¡ Boolean: e String: bar() CONTROLLER ¡ String: bar() VIEW ¡ String: d String: fun() CONTROLLER ¡ String: fun() “e” is not defined in model! Inconsistent types!

slide-14
SLIDE 14

Challenges ¡

14

Nested Objects

$scope.obj = { prop1: 2, prop2: { subprop1: “hello”, subprop2: true } prop3: “world” };

  • bj is a model variable,

but so is obj.prop1,

  • bj.prop2.subprop1,

etc.

Aliasing

$scope.arr = […]

<li ng-repeat=“temp in arr”> {{temp.val}} </li>

temp is an alias!

Groupings

M V ¡ C ¡ M V ¡ C ¡

slide-15
SLIDE 15

15

Running Example

Movie Search

Type Username

List User's Favourite Movies

Search Page Movie Search

Which User? Welcome User #1

  • Star Wars
  • 8 1/2

2 movies

Results Page Input text element Button List of movies Number of movies in list

slide-16
SLIDE 16

16

“Search” ¡Model ¡ “SearchCtrl” ¡Controller ¡ “search.html” ¡View ¡ “Results” ¡Model ¡ “ResultsCtrl” ¡Controller ¡ “results.html” ¡View ¡

“Search” Grouping “Results” Grouping

slide-17
SLIDE 17

17 $scope.userData = { movieList: … count: “two”, … };

“Results” ¡Model ¡

$scope.alertUserName = function() { alert(… + $scope.userName); }

“ResultsCtrl” ¡Controller ¡

… <li ng-repeat=“movie in userData”>{{movie.name}}</li> … <ng-pluralize count=“userData.count” /> …

“results.html” ¡View ¡ userName model variable not defined in model ng-repeat attribute used to loop through movies in the movie list… …but ng-repeat loops through userData instead of userData.movieList The view expects userData.count to be of type Number… …but userData.count is assigned a String in the model

slide-18
SLIDE 18

Finding ¡the ¡Models, ¡Views, ¡and ¡Controllers ¡

18

Model Controller View

slide-19
SLIDE 19

19

“Search” ¡Model ¡ “SearchCtrl” ¡Controller ¡ “search.html” ¡View ¡ “Results” ¡Model ¡ “ResultsCtrl” ¡Controller ¡ “results.html” ¡View ¡

slide-20
SLIDE 20

Inferring ¡IdenKfiers ¡

20

Model Variable and Controller Function

Definitions

Done via $scope identifier Model Variable and Controller Function

Usages

Embedded in HTML code

“Straw man” approach: Just take whatever identifiers you see in the above parts of the code

slide-21
SLIDE 21

21

“Search” ¡Model ¡ “SearchCtrl” ¡Controller ¡ “search.html” ¡View ¡ “Results” ¡Model ¡ “ResultsCtrl” ¡Controller ¡ “results.html” ¡View ¡ userData userName alertUserName() userData movie.name userData.count userName searchUser() userName userName alertUserName() This is a nested object This is an alias

slide-22
SLIDE 22

Inferring ¡IdenKfiers: ¡Nested ¡Objects ¡

22

Object Literal Tree, where each node is an object property identifier

$scope.userData = { movieList: { movie1: …, movie2: … }, count: “two”, intro: …, display: true };

userData ¡ count ¡ movieList ¡ intro ¡ display ¡ movie1 ¡ movie2 ¡

slide-23
SLIDE 23

Inferring ¡Types ¡

23

$scope.bar = “hello”

StringLiteral

bar is of type String

Insight: Parts of MVC applications typically written in “declarative” way

For assigned/returned types: Look at AST node!

slide-24
SLIDE 24

Inferring ¡Types ¡

24

For expected types: Examine HTML attribute <ng-pluralize count=“userData.count” /> userData.count is expected to be a Number <h3 ng-if=“userData.display”>…</h3> userData.display is expected to be a Boolean

slide-25
SLIDE 25

25

“Search” ¡Model ¡ “SearchCtrl” ¡Controller ¡ “search.html” ¡View ¡ “Results” ¡Model ¡ “ResultsCtrl” ¡Controller ¡ “results.html” ¡View ¡ Object: userData String: userData.count Object: userData.movieList userName Void: alertUserName() Array/Object: userData userData.count.name userData.movieList.name Number: userData.count userName Void: searchUser() String: userName userName alertUserName()

slide-26
SLIDE 26

Discovering ¡MVC ¡Groupings ¡

Groupings can be inferred via

ng-controller

attribute Groupings can be inferred via

routers

slide-27
SLIDE 27

27

.when(‘/’, { controller: ‘SearchCtrl’, templateUrl: ‘search.html’ } .when(‘/’, { controller: ‘ResultsCtrl’, templateUrl: ‘results.html’ }

slide-28
SLIDE 28

28

“Search” ¡Model ¡ “SearchCtrl” ¡Controller ¡ “search.html” ¡View ¡ “Results” ¡Model ¡ “ResultsCtrl” ¡Controller ¡ “results.html” ¡View ¡ Grouping 1 Grouping 2

slide-29
SLIDE 29

DetecKng ¡Inconsistencies ¡

29

Controller Functions :

String comparison of identifiers and types

Model Variables:

userData.count

Traverse ¡

userData ¡ count ¡ movieList ¡ intro ¡ display ¡ movie1 ¡ movie2 ¡

slide-30
SLIDE 30

30

Message 1: userName is not defined in “Results” model Message 2: userData.count.name not defined in “Results” model Message 3: userData.count expected to be of type Number, but is of type String instead in “Results” model

slide-31
SLIDE 31

Aurebesh ¡

31

APP.JS

RESULTS.HTML

“count” is expected to be a Number!

http://www.ece.ubc.ca/~frolino/projects/aurebesh

slide-32
SLIDE 32

Research ¡QuesKons ¡

RQ1: ¡Can ¡Aurebesh ¡help ¡developers ¡find ¡real ¡ bugs ¡in ¡real-­‑world ¡web ¡applicaKons? ¡ ¡ RQ2: ¡How ¡accurate ¡is ¡Aurebesh ¡in ¡finding ¡ idenKfier ¡and ¡type ¡inconsistencies? ¡ ¡ RQ3: ¡How ¡quickly ¡can ¡Aurebesh ¡perform ¡the ¡ inconsistency ¡detecKon ¡analysis? ¡

32

slide-33
SLIDE 33

33

20 ¡open-­‑source ¡AngularJS ¡applicaKons ¡ 100+ ¡to ¡1000+ ¡lines ¡of ¡JS ¡code ¡

eval() ¡ dynamic ¡type ¡conversions ¡

✗ ✗

slide-34
SLIDE 34

RQ1: ¡Real ¡Bugs ¡

Aurebesh found 15 bugs previously undetected (5 were acknowledged by developers) Todo Application Can’t add todo items… Slide Maker Can’t change themes and transitions in slides…

slide-35
SLIDE 35

RQ2: ¡Accuracy ¡

Fault injection experiment

10 types of

mutations

200 injections per

application Recall

# of successful detections # of total injections

96%

  • verall

Precision

# of successful detections # of error messages displayed

Close to 100% (only one false positive)

slide-36
SLIDE 36

RQ3: ¡Performance ¡

Average Execution Time

121 ms

Worst-case Execution Time

849 ms (eTuneBook)

slide-37
SLIDE 37

$/0!,1)2'3415.!*4!*6'!&'.7-'8!

4 $#"9:! /;9<! 0#=>&#::9&! MODEL VARIABLES CONTROLLER FUNCTIONS DEFINES USES DEFINES USES USES

MVC Frameworks use two-way data binding ! No DOM method calls!

To design a way to automatically detect identifier and type inconsistencies in MVC applications

@-1'N'.6!

29 APP.JS RESULTS.HTML “count” is expected to be a Number!

http://www.ece.ubc.ca/~frolino/projects/aurebesh

P`_b(6$$L1.$F(

Fault injection experiment

10 types of

mutations

200 injections per

application Recall

# of successful detections # of total injections

96%

  • verall

Precision

# of successful detections # of error messages displayed

Close to 100% (only one false positive)