1 / 53

Compiling Web Scripts for Apache

Compiling Web Scripts for Apache. Jacob Matthews Luke Hoban Robby Findler Rice University. The Goal (Version 1). Write a CGI program like this: (let ((n (read-from-web “Type a number: ”)) (m (read-from-web “and another: ”))) (display-to-web “The sum is: ” (+ n m))).

aglaia
Download Presentation

Compiling Web Scripts for Apache

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Compiling Web Scripts for Apache Jacob Matthews Luke Hoban Robby Findler Rice University

  2. The Goal (Version 1) Write a CGI program like this: (let ((n (read-from-web “Type a number: ”)) (m (read-from-web “and another: ”))) (display-to-web “The sum is: ” (+ n m)))

  3. (let ((n(read-from-web “Type a number: ”)) (m (read-from-web “And another: ”))) (display-to-web “The sum is: ” (+ n m)))

  4. (let ((n(read-from-web “Type a number: ”)) (m (read-from-web “And another: ”))) (display-to-web “The sum is: ” (+ n m)))

  5. (let ((n(read-from-web “Type a number: ”)) (m (read-from-web “And another: ”))) (display-to-web “The sum is: ” (+ n m)))

  6. (let ((n(read-from-web “Type a number: ”)) (m (read-from-web “And another: ”))) (display-to-web “The sum is: ” (+ n m)))

  7. (let ((n(read-from-web “Type a number: ”)) (m (read-from-web “And another: ”))) (display-to-web “The sum is: ” (+ n m)))

  8. (let ((n(read-from-web “Type a number: ”)) (m (read-from-web “And another: ”))) (display-to-web “The sum is: ” (+ n m)))

  9. (let ((n(read-from-web “Type a number: ”)) (m (read-from-web “And another: ”))) (display-to-web “The sum is: ” (+ n m)))

  10. An Observation (let ((n (read-from-web “Type a number: ”)) (m (read-from-web “and another: ”))) (display-to-web “The sum is: ” (+ n m)))

  11. n = 4 An Observation (let ((n (read-from-web “Type a number: ”)) (m (read-from-web “and another: ”))) (display-to-web “The sum is: ” (+ n m))) If we have the red and the blue box, we can resume the program at that point as many times as we want.

  12. CPS Form There’s already a standard transformation that does what we want! CPS conversion, lambda-lifting, and closure conversion give us red boxes at every point and arrows connecting them (let ((n (read-from-web “Type a number: ”)) (m (read-from-web “and another: ”))) (display-to-web “The sum is: ” (+ n m)))

  13. n = 4 <INPUT TYPE=“hidden” NAME=“What’s Left?” VALUE=“A B C”> <INPUT TYPE=“hidden” NAME=“environment” VALUE=“n=4”> Read-from-web (let ((n (read-from-web “Type a number: ”)) (m (read-from-web “and another: ”))) (display-to-web “The sum is: ” (+ n m)))

  14. So what can we handle? • Creating, invoking, and passing closures • Creating and passing other basic values (cons, vector, string, etc) • Basic control constructs (if, let, cond, etc.) • call/cc

  15. What can’t we handle? • variable assignment • mutable values • generative structures • exception handling • dynamic evaluation • input/output ports • threads • integration with native code • …

  16. Plus … • … we have to be efficient! • … we have to be secure!

  17. Variable Assignment (let ((sum 0)) (let loop () (let ((i (read-from-web "Type a number"))) (set! sum (+ sum i)) (loop))))

  18. sum = 9 Variable Assignment (let ((sum 0)) (let loop () (let ((i (read-from-web "Type a number"))) (set! sum (+ sum i)) (loop))))

  19. Variable Assignment (let ((sum 0)) (let loop () (let ((i (read-from-web "Type a number"))) (set! sum (+ sum i)) (loop))))

  20. Variable Assignment (let ((sum 0)) (let loop () (let ((i (read-from-web "Type a number"))) (set! sum (+ sum i)) (loop))))

  21. Variable Assignment (let ((sum 0)) (let loop () (let ((i (read-from-web "Type a number"))) (set! sum (+ sum i)) (loop))))

  22. Variable Assignment (let ((sum 0)) (let loop () (let ((i (read-from-web "Type a number"))) (set! sum (+ sum i)) (loop))))

  23. sum = 12 Variable Assignment (let ((sum 0)) (let loop () (let ((i (read-from-web "Type a number"))) (set! sum (+ sum i)) (loop)))) But then, the user hits the ‘Back’ button ...

  24. sum = 9 Variable Assignment (let ((sum 0)) (let loop () (let ((i (read-from-web "Type a number"))) (set! sum (+ sum i)) (loop)))) sum = 9, not 12!

  25. sum = 9 Variable Assignment (let ((sum 0)) (let loop () (let ((i (read-from-web "Type a number"))) (set! sum (+ sum i)) (loop))))

  26. sum = [a] a = 9 Variable Assignment (let ((sum (box 0))) (let loop () (let ((i (read-from-web "Type a number"))) (set-box! sum (+ sum i)) (loop))))

  27. a = 9 Variable Assignment (let ((sum (box 0))) (let loop () (let ((i (read-from-web "Type a number"))) (set-box! sum (+ sum i)) (loop))))

  28. a = 12 Variable Assignment (let ((sum (box 0))) (let loop () (let ((i (read-from-web "Type a number"))) (set-box! sum (+ sum i)) (loop))))

  29. a = 12 Variable Assignment (let ((sum (box 0))) (let loop () (let ((i (read-from-web "Type a number"))) (set-box! sum (+ sum i)) (loop))))

  30. a = 12 Variable Assignment (let ((sum (box 0))) (let loop () (let ((i (read-from-web "Type a number"))) (set-box! sum (+ sum i)) (loop))))

  31. sum = [a] a = 12 Variable Assignment (let ((sum 0)) (let loop () (let ((i (read-from-web "Type a number"))) (set! sum (+ sum i)) (loop)))) If the user hits the back button now, everything still works!

  32. So where does the purple box go? • We need some place that’s associated with a particular user, but not a particular web page • Browser cookies might work

  33. Mutable Values H do we handle other mutable values like cons cells, hash tables, and vectors?

  34. Mutable Values (let ([lst '(#f)]) (let loop () (let ((r (read-from-web "Type a value"))) (append! lst (list r)) (loop))))

  35. Mutable Values (let ([lst '(#f)]) (let loop () (let ((r (read-from-web "Type a value"))) (append! lst (list r)) (loop)))) lst = (cons #f ‘()) Same problem, different primitive

  36. a = #f b = ‘() Mutable Values (let ([lst '(#f)]) (let loop () (let ((r (read-from-web "Type a value"))) (append! lst (list r)) (loop)))) lst = (cons [a][b])

  37. Mutable Values But if we add to the purple box every time we make a list, we’ll have problems: • Even lists that never need to be saved get added • The purple box is never garbage-collected • There are too many constructors anyway!

  38. Mutable Values • So instead, we get lazy! • Only add or update the purple box when we actually call read-from-web

  39. Mutable Values (let ([lst '(#f)]) (let loop () (let ((r (read-from-web "Type a value"))) (append! lst (list r)) (loop)))) lst = (cons #f ‘())

  40. a = #f b = ‘() Mutable Values (let ([lst '(#f)]) (let loop () (let ((r (read-from-web "Type a value"))) (append! lst (list r)) (loop)))) lst = (cons [a][b]) In fact, we add all new mutable values reachable from the environment

  41. But Won’t the Store Still Be Too Big? • Yes! • Even worse: the store never shrinks! • Cookies aren’t feasible • For now, put (some of) the store on the server

  42. Security As it stands, attackers can make up anything as the blue and purple information!

  43. Security (if (valid? (read-from-web "Password:”)) (display-secret-page) (display-error-page))

  44. Security (if (valid? (read-from-web "Password:”)) (display-secret-page) (display-error-page)) The attacker can’t choose the red boxes, but can choose where the arrows point …

  45. Security (if (valid? (read-from-web "Password:”)) (display-secret-page) (display-error-page)) … And that’s bad enough!

  46. Security A solution: • Encrypt the contents of the hidden fields and the cookies • Keep a secret key only on the server

  47. Efficiency • We’ve got too many red boxes! • They make the program larger • More arrows means larger values in the hidden fields and longer page download times

  48. A Solution • “Full” CPS is too much - we don’t need all the red boxes!

  49. Efficiency (let ((n (read-from-web “Type a number: ”)) (m (read-from-web “and another: ”))) (display-to-web “The sum is: ” (+ n m))) The program never reaches (+ n m) without going directly on to display-to-web…

  50. Efficiency (let ((n (read-from-web “Type a number: ”)) (m (read-from-web “and another: ”))) (display-to-web “The sum is: ” (+ n m))) … so we can combine the two boxes!

More Related