Andi Scharfstein, Seminar on Functional Programming 2006 Why are we - - PowerPoint PPT Presentation

andi scharfstein seminar on functional programming 2006
SMART_READER_LITE
LIVE PREVIEW

Andi Scharfstein, Seminar on Functional Programming 2006 Why are we - - PowerPoint PPT Presentation

Andi Scharfstein, Seminar on Functional Programming 2006 Why are we here? [ Live Demo of the Orbitz Bug : 1. Visit orbitz.com in a web browser 2. Open multiple fl ights in multiple windows ] 3. T ry to book a fl ight. Regardless of which


slide-1
SLIDE 1

Andi Scharfstein, Seminar on Functional Programming 2006

slide-2
SLIDE 2

Why are we here?

slide-3
SLIDE 3

[Live Demo of the „Orbitz Bug“:

  • 1. Visit orbitz.com in a web browser
  • 2. Open multiple flights in multiple windows]
  • 3. T

ry to book a flight. Regardless of which flight was selected in your window, the flight that will be booked will always be the flight from the most recently opened window (even if it was closed in the meantime)]

slide-4
SLIDE 4

W e want to fix such bugs!

slide-5
SLIDE 5

Constructing the Model

Client W eb Server

slide-6
SLIDE 6

The W eb Server

Client W eb Server

slide-7
SLIDE 7

The W eb Server

Client W eb Server

  • Internal storage
  • Consists of key/value pairs
  • Represented by σ: Key → V

alue

  • Describes server state

flight 815

  • dest. SF

... ...

slide-8
SLIDE 8

The W eb Server

Client W eb Server

  • Internal storage
  • Consists of key/value pairs
  • Represented by σ: Key → V

alue

  • Describes server state

flight 815

  • dest. SF

... ...

  • Scripts (dynamic pages, forms)

Scripts

slide-9
SLIDE 9

The W eb Server

Client W eb Server

  • Internal storage
  • Consists of key/value pairs
  • Represented by σ: Key → V

alue

  • Describes server state

flight 815

  • dest. SF

... ...

Scripts

display- flights.htm

<?php for i in flights display(i) end>

... ...

slide-10
SLIDE 10
  • Scripts (dynamic pages, forms)
  • Lookup function P: URL → Form

The W eb Server

Client W eb Server

  • Internal storage
  • Consists of key/value pairs
  • Represented by σ: Key → V

alue

  • Describes server state

flight 815

  • dest. SF

... ...

Scripts

slide-11
SLIDE 11

The Client

Client W eb Server

flight 815

  • dest. SF

... ...

Scripts

slide-12
SLIDE 12

The Client

Client W eb Server

flight 815

  • dest. SF

... ...

Scripts Current form

  • Active page
slide-13
SLIDE 13

The Client

Client W eb Server

flight 815

  • dest. SF

... ...

Scripts Current form

  • Active page

... ... ...

  • Browser cache
  • All previously

seen forms

slide-14
SLIDE 14

<html> <form action=‘book-flight.html‘> <input name=‘flight‘ type=‘text‘ value=‘815‘> <input name=‘destination‘ type=‘text‘ value=‘San Francisco‘> <input name=‘submit‘ type=‘submit‘ value=‘Submit!‘> </form> </html>

Forms

slide-15
SLIDE 15

<html> <form action=‘book-flight.html‘> <input name=‘flight‘ type=‘text‘ value=‘815‘> <input name=‘destination‘ type=‘text‘ value=‘San Francisco‘> <input name=‘submit‘ type=‘submit‘ value=‘Submit!‘> </form> </html>

Forms

Representation: URL: book-flight.html

flight 815 destination San Francisco

slide-16
SLIDE 16

Supported Actions

  • Users may do any of the following at any time:
  • Enter data into the current form
  • Switch to a cached page

(e.g., click on the back button)

  • Submit a form
slide-17
SLIDE 17

What happens, when...

  • Users enter form data:
  • The key/value vector of the form is modified to

store the updated value URL: book-flight.html

flight 816 destination San Francisco

slide-18
SLIDE 18

What happens, when...

  • Users enter form data:
  • The key/value vector of the form is modified to

store the updated value

  • The updated form is added

to the browser cache URL: book-flight.html

flight 816 destination San Francisco

Current

... ... ...

slide-19
SLIDE 19

What happens, when...

  • Users switch to some form:
  • The new form is set as the

client‘s „current page“ (but

  • nly if it‘s found in the cache)

Current form ... ... ...

slide-20
SLIDE 20

What happens, when...

  • Users submit a form?
slide-21
SLIDE 21

flight 815

  • dest. SF

... ...

Form Submissions

Client W eb Server Scripts Current form ... ... ... Current form ...

slide-22
SLIDE 22

flight 815

  • dest. SF

... ...

Form Submissions

Client W eb Server Scripts Current form ... ... ...

  • Server computes the new form

Current form ...

slide-23
SLIDE 23

flight 815

  • dest. SF

... ...

Form Submissions

Client W eb Server Scripts Current form ... ... ...

  • Server state (storage) is updated

Current form ...

slide-24
SLIDE 24

flight 815

  • dest. SF

... ...

Form Submissions

Client W eb Server Scripts Current form ... ... ...

  • Client‘s „current page“ is set to the new form

...

slide-25
SLIDE 25

flight 815

  • dest. SF

... ...

Form Submissions

  • New form is added to client‘s browser cache

Client W eb Server Scripts Current form ... ... ...

slide-26
SLIDE 26

Attention, Mini-Test!

How does switching work again? Explain. Current form ... ... ...

slide-27
SLIDE 27

Attention, Mini-Test!

How does switching work again? Explain. Current form ... ... ... „Rewriting“ describes the transition directly and precisely: <s, <f , f >>

➝ ➞

¹

<s, <f , f >> ➝ where ¹ f ➝ f ∈

slide-28
SLIDE 28
  • Use identifiers, variables
  • Create functions
  • Apply functions
  • Create new forms
  • Extract values from forms (via keys)
  • Basic I/O (Server storage read/write)

Scripting Language

slide-29
SLIDE 29
  • Use identifiers, variables
  • Create functions
  • Apply functions
  • Create new forms
  • Extract values from forms (via keys)
  • Basic I/O (Server storage read/write)

Scripting Language

slide-30
SLIDE 30

flight dest. ... ...

Modelling the Bug

Scripts

  • Show

Flights

  • W

eb Server W eb Pages

slide-31
SLIDE 31

flight dest. ... ...

Modelling the Bug

Scripts

  • Flight 1

Details Show Flights

  • W

eb Server W eb Pages

slide-32
SLIDE 32

flight dest. ... ...

Modelling the Bug

Scripts

815

Flight 1 Details Show Flights

SF

W eb Server W eb Pages

slide-33
SLIDE 33

flight dest. ... ...

Modelling the Bug

Scripts

815

Flight 1 Details Show Flights Flight 2 Details

SF

W eb Server W eb Pages

slide-34
SLIDE 34

flight dest. ... ...

Modelling the Bug

Scripts

1632

Flight 1 Details Show Flights Flight 2 Details

SF

W eb Server W eb Pages

slide-35
SLIDE 35

flight dest. ... ...

Modelling the Bug

Scripts

1632

Flight 1 Details Show Flights Flight 2 Details

SF

Book Flight W eb Server W eb Pages

slide-36
SLIDE 36

flight dest. ... ...

Modelling the Bug

Scripts

1632

Flight 1 Details Show Flights Flight 2 Details

SF

Book Flight W eb Server W eb Pages

slide-37
SLIDE 37

Explaining the Bug

  • Obviously, submitting „outdated“ forms causes

undesired behaviour

  • The HTTP Observer Problem: Server cannot „push“

updates to the client (as in MVC)

➡ At least produce warnings when detecting outdated

requests

slide-38
SLIDE 38

Detecting outdated requests

  • Server needs a notion of time:

➡ Model as number of

submits

  • Storage records time of last

write for each field Scripts

time 4 flight 815 3 dest. SF 1 ... ...

slide-39
SLIDE 39

Detecting outdated requests

  • Introduce „carrier sets“ into forms:

All locations accessed by this script

  • Each form stores its creation time

URL: book-flight.html

flight 815 destination San Francisco

time 4 carriers ...

Scripts

time 4 flight 815 3

  • dest. SF 1

... ...

slide-40
SLIDE 40

Detecting outdated requests

  • Whenever a form is submitted, check its carrier set

against current storage state and compare time stamps

  • The carrier set represents the assumptions the script

made while working

  • If any location from this set was overwritten, script

assumptions may have been violated

slide-41
SLIDE 41

Thank you!

  • W

e have built a comprehensive, yet simple model of web interactions

  • Three basic semantic rules suffice to describe all

possible user actions:

  • „switch“
  • „fill-out“
  • „submit“
  • Any questions?
slide-42
SLIDE 42

References

  • Shriram Krishnamurti, Robert Bruce Findler, Paul

Graunke, Matthias Felleisen: „Modeling W eb Interactions and Errors“ (2004)

  • Daniel R. Licata, Shriram Krishnamurthi:

„V erifying Interactive W eb Programs“ (2005)

slide-43
SLIDE 43

Addendum: Fun with Types

  • Make forms typed!
  • Enables static checks for common bugs, like trying

to access form data that never got submitted

  • Also enables us to give some other safety guarantees
  • But: How to keep track of types in a dynamic

setting?

slide-44
SLIDE 44

Incremental Type Checking

  • Uses constraints along with regular type judgements
  • Constraints are introduced by creating forms:
  • The successor url of any form must contain a

program that takes as input exactly the data (type)

  • f that form
  • Otherwise, forms behave essentially like records
slide-45
SLIDE 45

Consistency

  • Consistency is achieved by checking that all types

registered for some form at a particular URL are equivalent

  • Since type constraints can be introduced by the

regular type system as well as by additional constraints, this is not always the case

  • If the types are not consistent, refuse to execute the

script