safe - college of engineering & applied science · safe formal specification and...

25
SAFE Formal Specification and Implementation of a Scalable Analysis Framework for ECMAscript PLRG@KAIST Hongki Lee, Sooncheol Won, Joonho Jin, Junhee Cho, and Sukyoung Ryu

Upload: others

Post on 22-May-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: SAFE - College of Engineering & Applied Science · SAFE Formal Specification and Implementation of a Scalable Analysis Framework for ECMAscript PLRG@KAIST Hongki Lee, Sooncheol Won,

SAFEFormal Specification and Implementation of

a Scalable Analysis Framework for ECMAscript

PLRG@KAISTHongki Lee, Sooncheol Won, Joonho Jin, Junhee Cho, and Sukyoung Ryu

Page 2: SAFE - College of Engineering & Applied Science · SAFE Formal Specification and Implementation of a Scalable Analysis Framework for ECMAscript PLRG@KAIST Hongki Lee, Sooncheol Won,

Contents

• Introduction

• Big Picture

• Formal Specification

• Implementation

• Active Research

• Conclusion

Page 3: SAFE - College of Engineering & Applied Science · SAFE Formal Specification and Implementation of a Scalable Analysis Framework for ECMAscript PLRG@KAIST Hongki Lee, Sooncheol Won,

Introduction

Page 4: SAFE - College of Engineering & Applied Science · SAFE Formal Specification and Implementation of a Scalable Analysis Framework for ECMAscript PLRG@KAIST Hongki Lee, Sooncheol Won,

JavaScript

• ECMAScript Language Specification

• Prototype-based inheritance

• Dynamic Features

- eval function,with statement

• Security Vulnerability Issues

- XSS

Page 5: SAFE - College of Engineering & Applied Science · SAFE Formal Specification and Implementation of a Scalable Analysis Framework for ECMAscript PLRG@KAIST Hongki Lee, Sooncheol Won,

Previous Work

• Under-documented

• Not open to the public

• Handwritten Parser & AST nodes

• ECMAScript3 or Subset of Language

• λJS, TAJS, FBJS, Caja, Rhino, ...

Page 6: SAFE - College of Engineering & Applied Science · SAFE Formal Specification and Implementation of a Scalable Analysis Framework for ECMAscript PLRG@KAIST Hongki Lee, Sooncheol Won,

SAFE

• Well-documented

• Open Source

• Auto-generated Parser & AST nodes

• Full ECMAScript5

• Formal Specification with ImplementationThe very first attempt!

Page 7: SAFE - College of Engineering & Applied Science · SAFE Formal Specification and Implementation of a Scalable Analysis Framework for ECMAscript PLRG@KAIST Hongki Lee, Sooncheol Won,

Big Picture

Page 8: SAFE - College of Engineering & Applied Science · SAFE Formal Specification and Implementation of a Scalable Analysis Framework for ECMAscript PLRG@KAIST Hongki Lee, Sooncheol Won,

JavaScript Parser AST

withRewriter

Disambiguator

Hoister

AST2IR IR IR2CFG CFG

Interpreter Result

CloneDetector CodeCoverage Analyzer

Page 9: SAFE - College of Engineering & Applied Science · SAFE Formal Specification and Implementation of a Scalable Analysis Framework for ECMAscript PLRG@KAIST Hongki Lee, Sooncheol Won,

JavaScript Parser AST

withRewriter

Disambiguator

Hoister

AST2IR IR IR2CFG CFG

Interpreter Result

CloneDetector CodeCoverage Analyzer

Page 10: SAFE - College of Engineering & Applied Science · SAFE Formal Specification and Implementation of a Scalable Analysis Framework for ECMAscript PLRG@KAIST Hongki Lee, Sooncheol Won,

Formal Specification

Page 11: SAFE - College of Engineering & Applied Science · SAFE Formal Specification and Implementation of a Scalable Analysis Framework for ECMAscript PLRG@KAIST Hongki Lee, Sooncheol Won,

Levels of Representations

• AST (Abstract Syntax Tree)

- To analyze at code level

• IR (Intermediate Representation)

- To evaluate code

• CFG (Control Flow Graph)

- To trace control flows

Page 12: SAFE - College of Engineering & Applied Science · SAFE Formal Specification and Implementation of a Scalable Analysis Framework for ECMAscript PLRG@KAIST Hongki Lee, Sooncheol Won,

IR Semantics

Page 13: SAFE - College of Engineering & Applied Science · SAFE Formal Specification and Implementation of a Scalable Analysis Framework for ECMAscript PLRG@KAIST Hongki Lee, Sooncheol Won,

Translation RuleAST to IR IR to CFG

Page 14: SAFE - College of Engineering & Applied Science · SAFE Formal Specification and Implementation of a Scalable Analysis Framework for ECMAscript PLRG@KAIST Hongki Lee, Sooncheol Won,

var sum = 0;for(var i = 1; i <= 10; i++) sum+= i;_<>_print(sum);

var i;var sum;sum = 0;for(i = 1; i <= 10; i++) sum+= i;_<>_print(sum);

Entry

Exit ExitExc

JavaScript AST

IRCFGvar ivar sumsum = 0i = 1<>break<>1 : { while(i <= 10) { <>continue<>2 : sum = sum + i <>old<>3 = i <>new<>4 = <>Global<>toNumber(<>old<>3) i = <>new<>4 + 1 <>Global<>ignore = <>new<>4}} <>Global<>ignore = <>Global<>print(sum)

Page 15: SAFE - College of Engineering & Applied Science · SAFE Formal Specification and Implementation of a Scalable Analysis Framework for ECMAscript PLRG@KAIST Hongki Lee, Sooncheol Won,

Implementation

Page 16: SAFE - College of Engineering & Applied Science · SAFE Formal Specification and Implementation of a Scalable Analysis Framework for ECMAscript PLRG@KAIST Hongki Lee, Sooncheol Won,

Implementation

• Automated tools

• Java and Scala

- Java Libraries

- Scala Pattern Matching

• Pluggable

Page 17: SAFE - College of Engineering & Applied Science · SAFE Formal Specification and Implementation of a Scalable Analysis Framework for ECMAscript PLRG@KAIST Hongki Lee, Sooncheol Won,

AST Refinement

JavaScript Parser AST

withRewriter

Disambiguator

Hoister

AST2IR IR IR2CFG CFG

Interpreter Result

CloneDetector CodeCoverage Analyzer

Page 18: SAFE - College of Engineering & Applied Science · SAFE Formal Specification and Implementation of a Scalable Analysis Framework for ECMAscript PLRG@KAIST Hongki Lee, Sooncheol Won,

Hoister

f();function f() { x = 1 };var x;// x = 1

function f() { x = 1 };var x; f();// x = 1

With Hoister, functions and variables are defined before use

Page 19: SAFE - College of Engineering & Applied Science · SAFE Formal Specification and Implementation of a Scalable Analysis Framework for ECMAscript PLRG@KAIST Hongki Lee, Sooncheol Won,

Disambiguator

var x = 0;function g() { x; // x = ? var x = 1;}

var x_1 = 0;function g() { var x_2; x_2; // x = ? x_2 = 1;}

Distinguish two ‘x’ variables

Page 20: SAFE - College of Engineering & Applied Science · SAFE Formal Specification and Implementation of a Scalable Analysis Framework for ECMAscript PLRG@KAIST Hongki Lee, Sooncheol Won,

withRewriter

var o = {x:1, y:2, z:3};o.p = {x:4, y:5, z:6};

with(o) { with(o.p) { x; }}

var o = {x:1, y:2, z:3};o.p = {x:4, y:5, z:6};

var $f_1 = o;var $f_2 = ("o" in $f_1 ? $f_1.o : o).p;("x" in $f_2 ? $f_2.x : ("x" in $f_1 ? $f_1.x : x));

An Empirical Study on the Rewritabilityof the with Statement in JavaScript - FOOL2011

Page 21: SAFE - College of Engineering & Applied Science · SAFE Formal Specification and Implementation of a Scalable Analysis Framework for ECMAscript PLRG@KAIST Hongki Lee, Sooncheol Won,

Evaluating Code

JavaScript Parser AST

withRewriter

Disambiguator

Hoister

AST2IR IR IR2CFG CFG

Interpreter Result

CloneDetector CodeCoverage Analyzer

Page 22: SAFE - College of Engineering & Applied Science · SAFE Formal Specification and Implementation of a Scalable Analysis Framework for ECMAscript PLRG@KAIST Hongki Lee, Sooncheol Won,

Active Research

Page 23: SAFE - College of Engineering & Applied Science · SAFE Formal Specification and Implementation of a Scalable Analysis Framework for ECMAscript PLRG@KAIST Hongki Lee, Sooncheol Won,

Calculate the ratio of tested codePerform type-based analysisDetect clone code in AST level

JavaScript Parser AST

withRewriter

Disambiguator

Hoister

AST2IR IR IR2CFG CFG

Interpreter Result

CloneDetector CodeCoverage Analyzer

Page 24: SAFE - College of Engineering & Applied Science · SAFE Formal Specification and Implementation of a Scalable Analysis Framework for ECMAscript PLRG@KAIST Hongki Lee, Sooncheol Won,

• The very first attempt to provide both formal specification and implementation

• Pluggable framework

• ECMAScript 5

• Open Source Projectavailable at http://plrg.kaist.ac.kr/research/safe

Conclusion

Page 25: SAFE - College of Engineering & Applied Science · SAFE Formal Specification and Implementation of a Scalable Analysis Framework for ECMAscript PLRG@KAIST Hongki Lee, Sooncheol Won,

Thank You!