diff options
author | Adam Chlipala <adamc@hcoop.net> | 2009-05-03 15:38:49 -0400 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2009-05-03 15:38:49 -0400 |
commit | e57a588744ec72e443d69d2e47b4a9a199613745 (patch) | |
tree | 09387818d6f755a3b5eec66ad560cbe707f348dd /demo | |
parent | 92df298250032469bab59565aa4e23a86b4a6e9a (diff) |
cookieSec demo
Diffstat (limited to 'demo')
-rw-r--r-- | demo/cookieSec.ur | 39 | ||||
-rw-r--r-- | demo/cookieSec.urp | 4 | ||||
-rw-r--r-- | demo/cookieSec.urs | 1 | ||||
-rw-r--r-- | demo/prose | 6 |
4 files changed, 50 insertions, 0 deletions
diff --git a/demo/cookieSec.ur b/demo/cookieSec.ur new file mode 100644 index 00000000..447d38ad --- /dev/null +++ b/demo/cookieSec.ur @@ -0,0 +1,39 @@ +cookie username : string + +table lastVisit : { User : string, When : time } + PRIMARY KEY User + +fun main () = + userO <- getCookie username; + + list <- queryX (SELECT * FROM lastVisit) + (fn r => <xml><tr><td>{[r.LastVisit.User]}</td> <td>{[r.LastVisit.When]}</td></tr></xml>); + + return <xml><body> + Cookie: {[userO]}<br/> + + <table> + <tr><th>User</th> <th>Last Visit</th></tr> + {list} + </table> + + <h2>Set cookie value</h2> + <form><textbox{#User}/> <submit action={set}/></form> + + <h2>Record your visit</h2> + <form><submit action={imHere}/></form> + </body></xml> + +and set r = + setCookie username r.User; + main () + +and imHere () = + userO <- getCookie username; + case userO of + None => return <xml>You don't have a cookie set!</xml> + | Some user => + dml (DELETE FROM lastVisit WHERE User = {[user]}); + dml (INSERT INTO lastVisit (User, When) VALUES ({[user]}, CURRENT_TIMESTAMP)); + main () + diff --git a/demo/cookieSec.urp b/demo/cookieSec.urp new file mode 100644 index 00000000..74755510 --- /dev/null +++ b/demo/cookieSec.urp @@ -0,0 +1,4 @@ +database dbname=test +sql cookieSec.sql + +cookieSec diff --git a/demo/cookieSec.urs b/demo/cookieSec.urs new file mode 100644 index 00000000..6ac44e0b --- /dev/null +++ b/demo/cookieSec.urs @@ -0,0 +1 @@ +val main : unit -> transaction page @@ -143,6 +143,12 @@ view.urp <p>SQL views are also supported with a special declaration form, analogous to <tt>table</tt>. A multi-parameter type class <tt>fieldsOf</tt> is used to characterize places where both tables and views are allowed. For instance, the polymorphic function <tt>list</tt> shown here lists the contents of any table or view containing just a single <tt>int</tt> column named <tt>A</tt>.</p> +cookieSec.urp + +<p>Ur/Web guarantees that compiled applications are immune to certain kinds of <a href="http://www.owasp.org/index.php/Top_10_2007-A5">cross site request forgery</a>. For instance, a "phisher" might send many e-mails linking to a form that he has set up to look like your web site. The form is connected to your web site, where it might, say, transfer money from your bank account to the phisher's account. The phisher doesn't know your username, but, if that username is stored in a cookie, it will be sent automatically by your browser. Ur/Web automatically signs cookie values cryptographically, with the signature included as a POST parameter and not part of a cookie, to prevent such attacks.</p> + +<p>This demo shows a simple mock-up of a situation where such an attack is often possible with traditional web frameworks. You can set an arbitrary username for yourself in a cookie, and you can modify the database in a way that depends on the current cookie value. Try getting the latter action to succeed without first setting your desired username in the cookie. This should be roughly as impossible as cracking the particular cryptographic hash function that is used.</p> + sum.urp <p>Metaprogramming is one of the most important facilities of Ur. This example shows how to write a function that is able to sum up the fields of records of integers, no matter which set of fields the particular record has.</p> |