148
1 Philipp Rümmer Uppsala University SAT/SMT/AR, July 6 th , 2018 SMT, Strings, Security

SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

1

Philipp Rümmer

Uppsala University

SAT/SMT/AR, July 6th, 2018

SMT, Strings, Security

Page 2: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

2

Plan

String constraints by example

A word equation primer

Decidable fragments of string constraints

Page 3: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

3

Strings in Verifcation

Page 4: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

4

String in verifiation

Page 5: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

5

String in verifiation

ASCII, Unicode

Page 6: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

6

String in verifiation

Regular expressionassertion:

Page 7: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

7

String in verifiation

Word/stringioniatenation

Page 8: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

8

String in verifiation

Loop invariant combiningword equations,regex constraints,length constraints

Page 9: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

9

String in verifiation

Substringconstraint

Page 10: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

10

String in verifiation

Or regex:

Page 11: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

11

String in verifiation

Presburgerlength constraint

Page 12: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

12

String in verifiation

→ Need a solver that supports all those operators!

Page 13: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

13

Alphabets

All constraints are formulated w.r.t. to some fxed fnite alphabet

(e.g., 8-bit ASCII) (e.g., UTF-32)

Page 14: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

14

Semantiis and notation

Finite sequences of letters: Empty word: Concatenation:

Equations: Language/regex membership: Word length:

Page 15: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

15

LARGE Alphabets

Naive use of fnite-state automata quickly becomes impossible

Conirete letters as transition guards →far too many transitions are needed to express interesting languages

Symbolii handling of letters is necessary

Sometimes complex string conversion functions necessary, e.g. UTF-8 ↔ UTF-32

Page 16: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

16

Injeition attaiks

xkcd.com

Page 17: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

17

What is happening here?

Possible SQL iommand in a program

database.execute( "INSERT INTO students (name) VALUES ('" + name + "');");

Page 18: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

18

What is happening here?

Possible SQL iommand in a program

database.execute( "INSERT INTO students (name) VALUES ('" + name + "');");

Command with input substituted

INSERT INTO students (name) VALUES ('Robert'); DROP TABLE students;--');

Page 19: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

19

What is happening here?

Possible SQL iommand in a program

database.execute( "INSERT INTO students (name) VALUES ('" + name + "');");

Command with input substituted

INSERT INTO students (name) VALUES ('Robert'); DROP TABLE students;--');

Problem:Input string

ends quotation!

Commandembedded in

user inputis executed

Page 20: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

20

What is happening here?

Possible SQL iommand in a program

database.execute( "INSERT INTO students (name) VALUES ('" + name + "');");

Since no sanitisation is applied, program is vulnerable to SQL injection attacks!

Page 21: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

21

How ian this be deteited?

Programcode

Input:User-controlled strings

Output:SQL commands

Page 22: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

22

How ian this be deteited?

Programcode

Input:User-controlled strings

Output:SQL commands

Page 23: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

23

How ian this be deteited?

Programcode

Input:User-controlled strings

Output:SQL commands

Regexor CFG

Page 24: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

24

What is happening here?

Possible SQL iommand in a program

database.execute( "INSERT INTO students (name) VALUES ('" + name + "');");

However, this case could more easily be found with techniques like taint traiking

But what if sanitisation were actually applied?

Page 25: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

25

A subtle XSS vulnerability

JavaSiript embedded in a web-page

var x = goog.string.htmlEscape(cat);var y = goog.string.escapeString(x);

catElem.innerHTML = '<button onclick="createCatList(\'' + y + '\')">' + x + '</button>';

Page 26: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

26

A subtle XSS vulnerability

JavaSiript embedded in a web-page

var x = goog.string.htmlEscape(cat);var y = goog.string.escapeString(x);

catElem.innerHTML = '<button onclick="createCatList(\'' + y + '\')">' + x + '</button>';

Input string

Page 27: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

27

A subtle XSS vulnerability

JavaSiript embedded in a web-page

var x = goog.string.htmlEscape(cat);var y = goog.string.escapeString(x);

catElem.innerHTML = '<button onclick="createCatList(\'' + y + '\')">' + x + '</button>';

Input stringHTML escape:& → &amp;

JavaScriptescape:

' → \'

Page 28: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

28

A subtle XSS vulnerability

JavaSiript embedded in a web-page

var x = goog.string.htmlEscape(cat);var y = goog.string.escapeString(x);

catElem.innerHTML = '<button onclick="createCatList(\'' + y + '\')">' + x + '</button>';

Input stringHTML escape:& → &amp;

JavaScriptescape:

' → \'

Impliiit HTMLunescape

of the onclickattribute:

&amp; → &

Page 29: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

29

An XSS vulnerability (2)

JavaSiript embedded in a web-page

var x = goog.string.htmlEscape(cat);var y = goog.string.escapeString(x);

catElem.innerHTML = '<button onclick="createCatList(\'' + y + '\')">' + x + '</button>';

One possible attaikChoose cat to be ');alert(1);//

Generated HTML string is then:<button onclick="createCatList('&#39;);alert(1);//')">&#39;);alert(1);//</button>

Page 30: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

30

An XSS vulnerability (2)

JavaSiript embedded in a web-page

var x = goog.string.htmlEscape(cat);var y = goog.string.escapeString(x);

catElem.innerHTML = '<button onclick="createCatList(\'' + y + '\')">' + x + '</button>';

One possible attaikChoose cat to be ');alert(1);//

Generated HTML string is then:<button onclick="createCatList('&#39;);alert(1);//')">&#39;);alert(1);//</button>

This will be unesiaped tocreateCatList('');alert(1);//')

Page 31: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

31

An XSS vulnerability (2)

JavaSiript embedded in a web-page

var x = goog.string.htmlEscape(cat);var y = goog.string.escapeString(x);

catElem.innerHTML = '<button onclick="createCatList(\'' + y + '\')">' + x + '</button>';

One possible attaikChoose cat to be ');alert(1);//

Generated HTML string is then:<button onclick="createCatList('&#39;);alert(1);//')">&#39;);alert(1);//</button>

This will be unesiaped tocreateCatList('');alert(1);//')

Vulnerability since escapefunctions are applied in

wrong order

Page 32: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

32

Cross-site siripting

http://blog.aboutme.vn/choi-xss-tai-knock-xss-moe/

Page 33: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

33

Solvers for esiape ops?

Page 34: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

34

Solvers for esiape ops?

We need transducers!→ Automata with multiple tracks

Page 35: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

35

Solvers for esiape ops?

toUpperCase

a/Ab/Bc/C...

We need transducers!→ Automata with multiple tracks

Page 36: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

36

Solvers for esiape ops?

toUpperCase

a/Ab/Bc/C...

We need transducers!→ Automata with multiple tracks

htmlEsiape

</&lt;>/&gt;&/&amp;...

replaieAll

...

Page 37: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

37

Solvers for esiape ops?

toUpperCase

a/Ab/Bc/C...

We need transducers!→ Automata with multiple tracks

htmlEsiape

</&lt;>/&gt;&/&amp;...

replaieAll

...

Do not preserve length ...

Page 38: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

38

Other operations

String reversal Context-free grammars String-to-number conversions Replace-all with symbolic arguments ...

Page 39: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

39

SolvingString

Constraints

Page 40: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

40

Bit of Solver History

Bounded-length solvers Bit-vector-based: Hampi, Kaluza CP-based: Gecode

Automata-based tools Stranger, TRAU

SMT/DPLL/CDCL-based methods Z3-str/2/3, CVC4, S3/p, Norn, Sloth

(+ much theoretic work)

Page 41: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

41

Solving Word Equations

What are the solutions those equations?

Page 42: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

42

Nielsen's transformation

(also called Levi's lemma)

Theorem

Page 43: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

43

Nielsen's transformation

(also called Levi's lemma)

Theorem

Page 44: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

44

Nielsen's transformation

As a tableau rule

Page 45: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

45

Nielsen's transformation

As a tableau rule

Page 46: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

46

In the example

Page 47: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

47

How about this one?

Page 48: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

48

How about this one?

Page 49: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

49

How about this one?

Cyile!

Page 50: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

50

What ian be done?

Ignore cycles and hope for the best!

Identify fragments for which NT is guaranteed to terminate

Acyclic; straight-line

Improve NT and add termination criteria Makanin's method Simpler algorithms for quadratii equations

Page 51: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

51

Quadratii word equations

E.g.

Consider satisfability of asingle quadratii equation

DefnitionA word equation is quadratii if each variable occurs at most twice in the equation.

Page 52: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

52

Nielsen's transformation

Quadratii = simpler?

Page 53: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

53

Nielsen's transformation

Quadratii = simpler?

Number ofvariable

occurrencescannot increase!

Page 54: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

54

A deiision proiedure

Modifed Nielsen rule

Page 55: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

55

A deiision proiedure

Modifed Nielsen rule

Further rules

Page 56: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

56

Example

Page 57: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

57

Even more rules

One-sided Nielsen rule

Page 58: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

58

Deiision proiedure?

Soundness● If root is satisfable, at least one branch cannot

be closed

Completeness● If root is unsat, a closed proof exists● Follows from termination● Open branches → satisfying assignments

Termination● # of variable occurrences does not increase● Up to renaming of variables, only fnitely many

diferent equations exist

Page 59: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

59

Soundness argument

Label equations in the proof with: if equation is unsat if equation is sat, has variable

occurrences, and is length of for the shortest solution

Order pairs lexicographically

LemmaIn each application of the Nielsen rule, if the parent is labelled with , then at least one child has label .

Page 60: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

60

Soundness argument

Label equations in the proof with: if equation is unsat if equation is sat, has variable

occurrences, and is length of for the shortest solution

Order pairs lexicographically

LemmaIn each application of the Nielsen rule, if the parent is labelled with , then at least one child has label .

Decreasing labels→ Branch cannot

be closed!

Page 61: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

61

Combinations ...

Equations

Quadratii

Page 62: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

62

Combinations ...

Equations

Quadratii

RegexConstraints

Page 63: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

63

Combinations ...

Equations

Quadratii

RegexConstraints

Page 64: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

64

Combinations ...

Equations

Quadratii

RegexConstraints

✓Length

Constraints

Page 65: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

65

Combinations ...

Equations

Quadratii

RegexConstraints

✓Length

Constraints

?

Page 66: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

66

Combinations ...

Equations

Quadratii

RegexConstraints

✓Length

Constraints

??

Page 67: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

67

Transduition

Combinations ...

Equations

Quadratii

RegexConstraints

✓Length

Constraints

??

Page 68: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

68

Transduition

Combinations ...

Equations

Quadratii

RegexConstraints

✓Length

Constraints

??

Undeiidable

Page 69: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

69

Transduition

Combinations ...

Equations

Quadratii

RegexConstraints

✓Length

Constraints

??

Undeiidable

Page 70: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

70

Transduition

Combinations ...

Equations

Quadratii

RegexConstraints

✓Length

Constraints

??

Undeiidable

Page 71: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

71

Transduition

Combinations ...

Equations

Quadratii

RegexConstraints

✓Length

Constraints

??

Undeiidable

Page 72: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

72

The Norn fragment

1. Boolean structure

2. Acyclic (linear) word equations

3. Regex memberships

4. Length constraints

Parosh Aziz Abdulla, Mohamed Faouzi Atig, Yu-Fang Chen, Lukás Holík, Ahmed Rezine, Philipp Rümmer, Jari Stenman: String Constraints for Verifcation. CAV 2014

Page 73: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

73

The Norn fragment

1. Boolean structure

2. Acyclic (linear) word equations

3. Regex memberships

4. Length constraints

Parosh Aziz Abdulla, Mohamed Faouzi Atig, Yu-Fang Chen, Lukás Holík, Ahmed Rezine, Philipp Rümmer, Jari Stenman: String Constraints for Verifcation. CAV 2014

(a decidable fragment)

Page 74: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

74

The Norn fragment

1. Boolean structure

2. Acyclic (linear) word equations

3. Regex memberships

4. Length constraints

Parosh Aziz Abdulla, Mohamed Faouzi Atig, Yu-Fang Chen, Lukás Holík, Ahmed Rezine, Philipp Rümmer, Jari Stenman: String Constraints for Verifcation. CAV 2014

(a decidable fragment)

Order inwhichprocedurehandlesoperators

Page 75: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

75

Examples

Page 76: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

76

1. Boolean struiture

Use standard DPLL/CDCL → Easy Just consider conjunctions of literals

But we need to handle negation! Negated word equations Negated regex constraints Negated length constraints

Page 77: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

77

1. Boolean struiture

Use standard DPLL/CDCL → Easy Just consider conjunctions of literals

But we need to handle negation! Negated word equations Negated regex constraints Negated length constraints

✓✓

?

Page 78: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

78

1b. Negative word eqs.

Lemma

Can be reduced to positive equations:

Page 79: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

79

1b. Negative word eqs.

Lemma

Large alphabets→ a, b need to be

handled symbolicallyin practice

Can be reduced to positive equations:

Page 80: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

80

1b. Negative word eqs.

Lemma

Can be reduced to positive equations:

TheoremAny Boolean combination of word equations canbe reduced to a single word equation with thesame set of solutions (when projected to theoriginal set of variables).

Page 81: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

81

2. Aiyilii word equations

Reduce to solved form by systematic application of Nielsen’s transformation:

( do not occur in )

After that, eliminate equations by inlining!

Page 82: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

82

3. Regular expressions

Membership tests with ioniatenation can be split:

Tests with same left-hand side can be merged:

Page 83: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

83

3. Regular expressions

Membership tests with ioniatenation can be split:

Tests with same left-hand side can be merged:

Disjunction overstates of

automatonrepresenting

Page 84: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

84

4. Length ionstraints

Compute the length abstraition of each regex constraint:

Conjoin length abstractions with other length constraints and check satisfability

Page 85: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

85

4. Length ionstraints

Compute the length abstraition of each regex constraint:

Conjoin length abstractions with other length constraints and check satisfability

A Presburgerformula that canbe extracted in

linear time from

Page 86: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

86

5. Optimisations ...

E.g., exploit length information when splitting equations or regexes

(still too slow ...)

Page 87: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

87

Adding Transducers .

Page 88: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

88

3. Regular expressions

Membership tests with ioniatenation can be split:

Tests with same left-hand side can be merged:

Page 89: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

89

3. Regular expressions

Membership tests with ioniatenation can be split:

Tests with same left-hand side can be merged:

Does not workany more withtransducers!

Page 90: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

90

The Sloth fragments

1. Boolean structure (no negation)

2. Straight-line word equations

3. n-track transducer constraints

Lukás Holík, Petr Janku, Anthony W. Lin, Philipp Rümmer, Tomás Vojnar: String constraints with concatenation and transducers solved efciently. PACMPL 2(POPL): 4:1-4:32 (2018)

Page 91: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

91

The Sloth fragments

1. Boolean structure (no negation)

2. Straight-line word equations

3. n-track transducer constraints

Lukás Holík, Petr Janku, Anthony W. Lin, Philipp Rümmer, Tomás Vojnar: String constraints with concatenation and transducers solved efciently. PACMPL 2(POPL): 4:1-4:32 (2018)

→ also decidable!

Page 92: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

92

Transduiers

DefnitionAn n-traik transduier is a fnite-stateautomaton over the alphabetAn n-track transducer defnes an n-aryrational relation.

Page 93: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

93

Transduiers

DefnitionAn n-traik transduier is a fnite-stateautomaton over the alphabetAn n-track transducer defnes an n-aryrational relation.

Page 94: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

94

Transduiers

DefnitionAn n-traik transduier is a fnite-stateautomaton over the alphabetAn n-track transducer defnes an n-aryrational relation.

Page 95: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

95

HTML Esiaping

Page 96: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

96

Undeiidability

Proposition/FolkloreString constraints with rational relations areundeiidable.

Post correspondence problem:Given word pairs

is there an index sequence with

Page 97: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

97

Undeiidability

Proposition/FolkloreString constraints with rational relations areundeiidable.

Post correspondence problem:Given word pairs

is there an index sequence with

Undeiidable

Page 98: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

98

Fragments: aiyilii formulas

Positive Boolean comb. of rational relations applied to distinct variables

In every , and share at most one variable

PSPACE-complete[Barcelo, Figuiera, and Libkin’13]

Page 99: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

99

Straight-line fragment SL

Conjunction of equations sorted by dependency:

All pairwise distinct Each may only occur in Each is concatenation, or

(interpreted as ) Regex constraints

Page 100: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

100

SL example

JavaSiript embedded in a web-page

var x = goog.string.htmlEscape(cat);var y = goog.string.escapeString(x);

catElem.innerHTML = '<button onclick="createCatList(\'' + y + '\')">' + x + '</button>';

Page 101: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

101

SL example

JavaSiript embedded in a web-page

var x = goog.string.htmlEscape(cat);var y = goog.string.escapeString(x);

catElem.innerHTML = '<button onclick="createCatList(\'' + y + '\')">' + x + '</button>';

Page 102: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

102

SL example

JavaSiript embedded in a web-page

var x = goog.string.htmlEscape(cat);var y = goog.string.escapeString(x);

catElem.innerHTML = '<button onclick="createCatList(\'' + y + '\')">' + x + '</button>';

Page 103: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

103

SL example

JavaSiript embedded in a web-page

var x = goog.string.htmlEscape(cat);var y = goog.string.escapeString(x);

catElem.innerHTML = '<button onclick="createCatList(\'' + y + '\')">' + x + '</button>';

Page 104: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

104

SL example

JavaSiript embedded in a web-page

var x = goog.string.htmlEscape(cat);var y = goog.string.escapeString(x);

catElem.innerHTML = '<button onclick="createCatList(\'' + y + '\')">' + x + '</button>';

Page 105: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

105

SL example

JavaSiript embedded in a web-page

var x = goog.string.htmlEscape(cat);var y = goog.string.escapeString(x);

catElem.innerHTML = '<button onclick="createCatList(\'' + y + '\')">' + x + '</button>';

Page 106: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

106

Deiision proiedure for SL

SL Acyclic

Splittingconcat

Page 107: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

107

Deiision proiedure for SL

SL Acyclic

Splittingconcat

Linear blow-upfor each split

Page 108: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

108

Deiision proiedure for SL

SL Acyclic

Splittingconcat

Linear blow-upfor each split

BooleanTrans.System

Page 109: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

109

Deiision proiedure for SL

SL Acyclic

Splittingconcat

Linear blow-upfor each split

BooleanTrans.System

Hardware ModelCheiker

(PSPACE!)

Page 110: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

110

Deiidability for aiyilii f.

Page 111: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

111

Deiidability for aiyilii f.

Page 112: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

112

Deiidability for aiyilii f.

(Product automaton)

Page 113: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

113

Deiidability for aiyilii f.

(Product automaton)

Consistency=

Non-emptiness

Page 114: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

114

Deiidability for aiyilii f.

(Product automaton)

Consistency=

Non-emptiness

But how to dothis in PSPACE?

Page 115: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

Alternating Finite Automata

q1

q2

a

q3

a

q4

q5

a

q6

a

AFA P AFA P has

Q – a set of states,∆ – a set of transitions

, for example,I ∆(q4) = a ∧ (q5 ∨ q6),I ∆(q1) = a ∧ q2 ∧ q3,

I – a positive Boolean formula overstates,F – a negative Boolean formula overstates,

The main advantage compared to NFA is that AFA/AFT can easilyencode concatenation and all Boolean operations on formulae.

P. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 11 / 22

Page 116: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

Alternating Finite Automata

q1

q2

a

q3

a

q4

q5

a

q6

a

AFA P AFA P hasQ – a set of states,∆ – a set of transitions

, for example,I ∆(q4) = a ∧ (q5 ∨ q6),I ∆(q1) = a ∧ q2 ∧ q3,

I – a positive Boolean formula overstates,F – a negative Boolean formula overstates,

The main advantage compared to NFA is that AFA/AFT can easilyencode concatenation and all Boolean operations on formulae.

P. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 11 / 22

Page 117: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

Alternating Finite Automata

q1

q2

a

q3

a

q4

q5

a

q6

a

AFA P AFA P hasQ – a set of states,∆ – a set of transitions, for example,

I ∆(q4) = a ∧ (q5 ∨ q6),

I ∆(q1) = a ∧ q2 ∧ q3,

I – a positive Boolean formula overstates,F – a negative Boolean formula overstates,

The main advantage compared to NFA is that AFA/AFT can easilyencode concatenation and all Boolean operations on formulae.

P. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 11 / 22

Page 118: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

Alternating Finite Automata

q1

q2

a

q3

aq4

q5

a

q6

a

AFA P AFA P hasQ – a set of states,∆ – a set of transitions, for example,

I ∆(q4) = a ∧ (q5 ∨ q6),I ∆(q1) = a ∧ q2 ∧ q3,

I – a positive Boolean formula overstates,F – a negative Boolean formula overstates,

The main advantage compared to NFA is that AFA/AFT can easilyencode concatenation and all Boolean operations on formulae.

P. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 11 / 22

Page 119: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

Alternating Finite Automata

q1

q2

a

q3

a

q4

q5

a

q6

a

AFA P AFA P hasQ – a set of states,∆ – a set of transitions, for example,

I ∆(q4) = a ∧ (q5 ∨ q6),I ∆(q1) = a ∧ q2 ∧ q3,

I – a positive Boolean formula overstates,F – a negative Boolean formula overstates,

The main advantage compared to NFA is that AFA/AFT can easilyencode concatenation and all Boolean operations on formulae.

P. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 11 / 22

Page 120: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

Alternating Finite Automata

q1

q2

a

q3

a

q4

q5

a

q6

a

AFA P AFA P hasQ – a set of states,∆ – a set of transitions, for example,

I ∆(q4) = a ∧ (q5 ∨ q6),I ∆(q1) = a ∧ q2 ∧ q3,

I – a positive Boolean formula overstates,F – a negative Boolean formula overstates,

The main advantage compared to NFA is that AFA/AFT can easilyencode concatenation and all Boolean operations on formulae.

P. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 11 / 22

Page 121: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

AND between Two AFTs

c/a a/d

c/a/? ?/a/d

a/b b/c

a/b/? ?/b/c

d/c c/b

d/c/? ?/c/b

R1(name, x) R2(x , y)

R12(name, x , y)

P. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 14 / 22

Page 122: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

AND between Two AFTs

c/a a/d

c/a/? ?/a/d

a/b b/c

a/b/? ?/b/c

d/c c/b

d/c/? ?/c/b

R1(name, x) R2(x , y)

R12(name, x , y)

QR12 = QR1 ∪QR2

IR12 = IR1 ∧ IR2

FR12 = FR1 ∧ FR2

∆R12 = ∆R1 ∪∆R2

P. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 14 / 22

Page 123: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

SL→ AFT

The translation into an AFT will be carried out in the following steps:1 A translation of conjunctions to AFTs.

2 A translation of concatenations to AFTs:1 Eliminating equations by substitutions.

ϕ ::= R12(name, x , y) ∧ z = w1 ◦ y ◦ w2 ◦ x ◦ w3 ∧R3(z, innerHtml) ∧ P(innerHtml)

AFT R12 AFT R3 AFT PP. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 15 / 22

Page 124: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

AFT→ BTS

Variables of the Boolean transition system (BTS) =states of the automaton (AFT):

I q1,q2,q3.

The initial and final formulae of the BTS =initial and final formulae of the AFT:

I I = q1,I F = q2 ∧ q3.

The transition function of the BTS = conjunction of formulaederived from individual transitions of the AFT:

I Trans = ∃ symb : q1 → symb = a ∧ q′2 ∧ q′

3.

q1

q2 q3a

P. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 20 / 22

Page 125: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

AFT→ BTS

Variables of the Boolean transition system (BTS) =states of the automaton (AFT):

I q1,q2,q3.The initial and final formulae of the BTS =initial and final formulae of the AFT:

I I = q1,I F = q2 ∧ q3.

The transition function of the BTS = conjunction of formulaederived from individual transitions of the AFT:

I Trans = ∃ symb : q1 → symb = a ∧ q′2 ∧ q′

3.

q1

q2 q3a

P. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 20 / 22

Page 126: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

AFT→ BTS

Variables of the Boolean transition system (BTS) =states of the automaton (AFT):

I q1,q2,q3.The initial and final formulae of the BTS =initial and final formulae of the AFT:

I I = q1,I F = q2 ∧ q3.

The transition function of the BTS = conjunction of formulaederived from individual transitions of the AFT:

I Trans = ∃ symb : q1 → symb = a ∧ q′2 ∧ q′

3.

q1

q2 q3a

P. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 20 / 22

Page 127: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

SL→ AFT

The translation into an AFT will be carried out in the following steps:1 A translation of conjunctions to AFTs.2 A translation of concatenations to AFTs:

1 Eliminating equations by substitutions.

ϕ ::= R12(name, x , y) ∧ z = w1 ◦ y ◦w2 ◦ x ◦w3 ∧R3(z, innerHtml) ∧ P(innerHtml)

AFT R12 AFT R3 AFT PP. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 15 / 22

Page 128: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

Eliminating Equations by Substitutions

ϕ ::= R12(name, x , y) ∧ z = w1 ◦ y ◦w2 ◦ x ◦w3 ∧R3(z, innerHtml) ∧ P(innerHtml)

ϕ ::= R12(name, x , y) ∧ R3(w1 ◦ y ◦w2 ◦ x ◦w3, innerHtml) ∧P(innerHtml)

P. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 16 / 22

Page 129: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

Eliminating Equations by Substitutions

ϕ ::= R12(name, x , y) ∧ z = w1 ◦ y ◦w2 ◦ x ◦w3 ∧R3(z, innerHtml) ∧ P(innerHtml)

ϕ ::= R12(name, x , y) ∧ R3(w1 ◦ y ◦w2 ◦ x ◦w3, innerHtml) ∧P(innerHtml)

P. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 16 / 22

Page 130: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

Eliminating Equations by Substitutions

ϕ ::= R12(name, x , y) ∧ z = w1 ◦ y ◦w2 ◦ x ◦w3 ∧R3(z, innerHtml) ∧ P(innerHtml)

ϕ ::= R12(name, x , y) ∧ R3(w1 ◦ y ◦w2 ◦ x ◦w3, innerHtml) ∧P(innerHtml)

P. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 16 / 22

Page 131: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

SL→ AFT

The translation into an AFT will be carried out in the following steps:1 A translation of conjunctions to AFTs.2 A translation of concatenations to AFTs:

1 Eliminating equations by substitutions.

2 Handling rational relations with concatenations in arguments.

ϕ ::= R12(name, x , y) ∧ R3(w1 ◦ y ◦ w2 ◦ x ◦ w3, innerHtml) ∧P(innerHtml)

AFT R12 AFT R3AFT PP. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 17 / 22

Page 132: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

SL→ AFT

The translation into an AFT will be carried out in the following steps:1 A translation of conjunctions to AFTs.2 A translation of concatenations to AFTs:

1 Eliminating equations by substitutions.2 Handling rational relations with concatenations in arguments.

ϕ ::= R12(name, x , y) ∧ R3(w1 ◦ y ◦w2 ◦ x ◦w3, innerHtml) ∧P(innerHtml)

AFT R12 AFT R3AFT PP. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 17 / 22

Page 133: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

Splitting of Arguments

Run of the AFT R

z

x

y

Consider ϕ ::= R(x ◦ y , z) ∧ ψ.

We need to split z into two parts.z = z1 ◦ z2 where z1 and z2 are freshvariables.ϕ ::= RCF (x , z1) ∧ RCI(y , z2) ∧ψ[z/z1 ◦ z2].A simple variant:

I One conjuction for everyconfiguration (set of states) C wherea run may be split.

I Exponentional (2Q) for generalAFTs.

P. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 18 / 22

Page 134: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

Splitting of Arguments

Run of the AFT R

z

x

y

Consider ϕ ::= R(x ◦ y , z) ∧ ψ.We need to split z into two parts.

z = z1 ◦ z2 where z1 and z2 are freshvariables.ϕ ::= RCF (x , z1) ∧ RCI(y , z2) ∧ψ[z/z1 ◦ z2].A simple variant:

I One conjuction for everyconfiguration (set of states) C wherea run may be split.

I Exponentional (2Q) for generalAFTs.

P. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 18 / 22

Page 135: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

Splitting of Arguments

Run of the AFT R

z1

z2

x

y

Consider ϕ ::= R(x ◦ y , z) ∧ ψ.We need to split z into two parts.z = z1 ◦ z2 where z1 and z2 are freshvariables.

ϕ ::= RCF (x , z1) ∧ RCI(y , z2) ∧ψ[z/z1 ◦ z2].A simple variant:

I One conjuction for everyconfiguration (set of states) C wherea run may be split.

I Exponentional (2Q) for generalAFTs.

P. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 18 / 22

Page 136: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

Splitting of Arguments

Run of the AFT R

z1

z2

C

x

y

Consider ϕ ::= R(x ◦ y , z) ∧ ψ.We need to split z into two parts.z = z1 ◦ z2 where z1 and z2 are freshvariables.ϕ ::= RCF (x , z1) ∧ RCI(y , z2) ∧ψ[z/z1 ◦ z2].

A simple variant:I One conjuction for every

configuration (set of states) C wherea run may be split.

I Exponentional (2Q) for generalAFTs.

P. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 18 / 22

Page 137: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

Splitting of Arguments

Run of the AFT R

z1

z2

C

x

y

Consider ϕ ::= R(x ◦ y , z) ∧ ψ.We need to split z into two parts.z = z1 ◦ z2 where z1 and z2 are freshvariables.ϕ ::= RCF (x , z1) ∧ RCI(y , z2) ∧ψ[z/z1 ◦ z2].A simple variant:

I One conjuction for everyconfiguration (set of states) C wherea run may be split.

I Exponentional (2Q) for generalAFTs.

P. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 18 / 22

Page 138: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

Splitting of Arguments

Given a formula ϕ ::= R(x ◦ y , z) ∧ ψ.

R is split to two AFTs: R(x , z1) and R(y , z2).Guess the initial configuration R(y , z2) nondeterministically.

I Remember the configuration by using additional states.

Check whether the final states of R(x , z1) correspond tothe initial states of R(y , z2).

R(y , z2)

R′(x , y , z1, z2)

P. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 19 / 22

Page 139: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

Splitting of Arguments

Given a formula ϕ ::= R(x ◦ y , z) ∧ ψ.R is split to two AFTs: R(x , z1) and R(y , z2).

Guess the initial configuration R(y , z2) nondeterministically.

I Remember the configuration by using additional states.

Check whether the final states of R(x , z1) correspond tothe initial states of R(y , z2).

R(x , z1) R(y , z2)

R′(x , y , z1, z2)

P. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 19 / 22

Page 140: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

Splitting of Arguments

Given a formula ϕ ::= R(x ◦ y , z) ∧ ψ.R is split to two AFTs: R(x , z1) and R(y , z2).Guess the initial configuration R(y , z2) nondeterministically.

I Remember the configuration by using additional states.Check whether the final states of R(x , z1) correspond tothe initial states of R(y , z2).

R(x , z1)

R(y , z2)

R′(x , y , z1, z2)

P. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 19 / 22

Page 141: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

Splitting of Arguments

Given a formula ϕ ::= R(x ◦ y , z) ∧ ψ.R is split to two AFTs: R(x , z1) and R(y , z2).Guess the initial configuration R(y , z2) nondeterministically.

I Remember the configuration by using additional states.

Check whether the final states of R(x , z1) correspond tothe initial states of R(y , z2).

R(x , z1) R(y , z2)

R′(x , y , z1, z2)

P. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 19 / 22

Page 142: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

Splitting of Arguments

Given a formula ϕ ::= R(x ◦ y , z) ∧ ψ.R is split to two AFTs: R(x , z1) and R(y , z2).Guess the initial configuration R(y , z2) nondeterministically.

I Remember the configuration by using additional states.Check whether the final states of R(x , z1) correspond tothe initial states of R(y , z2).

R(x , z1) R(y , z2)

R′(x , y , z1, z2)

P. Janku, et.al. String Constraints with Concatenation and Transducers Solved Efficiently 19 / 22

Page 143: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

115

Deiision proiedure for SL

SL Acyclic

Splittingconcat

Linear blow-upfor each split

BooleanTrans.System

Model Cheiker(nuXmv, ABC)

Page 144: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

116

The TRAU fragment

1. General word-equations

2. General transducers

3. Context-free grammars

4. Length constraints

Parosh Aziz Abdulla, Mohamed Faouzi Atig, Yu-Fang Chen, Bui Phi Diep, Lukas Holik, Ahmed Rezine, Philipp Rümmer: Flatten and conquer, a framework for efcient analysis of string constraints. PLDI 2017: 602-617

Page 145: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

117

The TRAU fragment

1. General word-equations

2. General transducers

3. Context-free grammars

4. Length constraints

Parosh Aziz Abdulla, Mohamed Faouzi Atig, Yu-Fang Chen, Bui Phi Diep, Lukas Holik, Ahmed Rezine, Philipp Rümmer: Flatten and conquer, a framework for efcient analysis of string constraints. PLDI 2017: 602-617

→ undecidable!

Page 146: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

118

Overview of TRAU ...

Page 147: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

119

Are we there yet?

Expressiveness

Efciency Precision/guarantees

Page 148: SMT, Strings, Securityregerg/ssa/string-slides.pdf · 31 An XSS vulnerability (2) JavaSiript embedded in a web-page var x = goog.string.htmlEscape(cat); var y = goog.string.escapeString(x);

120

Joint work with ...

Parosh Aziz Abdulla Mohamed Faouzi

Atig Yu-Fang Chen Bui Phi Diep Lukás Holík

Petr Janků Anthony W. Lin Ahmed Rezine Jari Stenman Tomás Vojnar

and others