Good afternoon, everyone. My name is Ming Chao, and I'm a lecturer at Tufts University in Medford, Massachusetts. And I am here to talk about HTML5, breaking, abusing, and hacking HTML5. Just for my curiosity here, raise your hand if you have worked with HTML5 in some capacity already. Okay, so there's a good number of hands, okay? There's a good number of hands up, and it shouldn't be a surprise why, I mean, right now there's such a big push for websites and web applications to go down the road of HTML5. And that's because a lot of devices, you know, well, we don't have a lot of those new devices, tablets, iPhones, iPads, they don't have Flash. And the other thing is, of course, the browser has gotten really, really, really powerful. The other thing is, how many people here know JavaScript? Because I'm going to do a lot of demonstrations. Okay, a lot of code examples. Great, great, excellent. Okay, so just a little intro background material. What is HTML5? Well, it's very much like HTML5. It's going to be the next standard, the next revision of HTML, the mock-up language. But one of the things that you've got to understand about HTML5 is just not the mock-up language. It's really a stack of technology. HTML5 is really dependent on not only dependent on the HTML5. The mock-up language, but also presentation by way of CSS, and also a lot of JavaScript, you know, interaction with content. The cool thing is, I'm not going to talk particularly much on server-side stuff, it makes no sense anyway. But you're close enough using HTML5 as a full-fledged development environment. There is one caveat that you've got to know about HTML5. It's still working target. It's still work-in-progress. It's that some of the stuff today that I'm going to talk about may change tomorrow. That's, you know, just watch out. Who knows when the standard will be finalized? And, of course, there's backing from Google. Microsoft is going to get pushed very heavily with Office and with the next version of IE. Now, not only is HTML5 a mock-up language, it's a mock-up language. And that's because we need to have HTML5 work in progress. Different browsers have different standards. And right now the companies are like Google, Microsoft, they're everyone doing their own thing. So one of the most, you know, one of the drawbacks of using HTML5 right now, there's so many incompatibilities. Case in point, it's going to be video, which I'll show you in a few moments, all right? But to check what your browser can support and do, you really want to go check. Go to http. Go to html5.com. test.com, and it will render a score on your browser, see how compatible, like, what features your browser, the HTML5 features your browser can use, okay? The other thing to also keep in mind is there's still going to be people who are going to be using IE6, IE7, you know, older versions of Firefox, you know, that's not going to change, but a lot of the HTML5 syntax, when it is going to be rendered on the browser, it's going to ‑‑ it's still going to render, but all the real cool stuff, they're not going to be ‑‑ you know, they're just not going to be rendered, okay? So here's just a quick summary on what's in and what's out in HTML5. Whole bunch of ‑‑ okay, what's in? A bunch of new tags, video, audio, there's also semantic ‑‑ tags for semantic stuff such as article, footer, and nav. Okay. Back in the days, and still we do this a lot, a lot of people use div ID equals nav or div ID equals footer or div ID equals header. So the nice thing is, one of the standards now is why don't we just instead of doing div tag, we just have article tag. I know that in Chrome I can't get too much working with the article and the footer tags. There's a lot of new attributes, for example, for pattern recognition in form fields. There are also new media events. For example, time update, when you want to play a video from one second to two seconds. Geolocation, you know, that feature that, you know, your browser prompts you to do you want to use your location, does this page want to use your location, do you want to, you know, get permission? I mean, I'm sure a lot of people have seen that. That's part of HTML5, okay? And of course, client side storage, which is becoming, like, the next vector for abuse. What's out? Font and center tag. Anything that's presentation-based, font, center, align, border, all right, those are quote-unquote no longer support, like, quote-unquote no longer supported in the HTML5 standard. Why? You know, HTML5, HTML for content generation was never, ever meant for styling purposes. So they're forcing you now to have all that stuff in CSS. It's quote-unquote not supported. By not supported means if you try to validate your page in the official W3C validator, you'll get a lot of not only warning but error messages, and they'll yell at you, okay? Applets and old special effects such as, remember the marquee, all right? Good times. Background sound, you know, those are no longer supported. And this one last guy right here, the no script tag, all right? The no script tag. I have a snort ball here. Can someone tell me what the purpose of the no script tag is? And why do you think it's no longer supported in the HTML5 standard? Okay. I'm going to throw it over there. Someone catch it. All right. Now I want to do a few quick demonstrations that illustrate the power of HTML5, okay? I'm going to do an example on, first of all, a couple of video captioning examples. And if I have time, I'll also do a geo. Okay. I'm going to do a video location as well. Hopefully this thing will work. Hello. Okay. Now, I had, this is, this was an example, this was a video that was built by a high school student, Rachel Solmonte. She's taking my summer class right now at Tufts. And she did a video called Double Rainbow. And unfortunately, you know, I'm just going to play, I think the screen resolution will go up. But, you know. Okay. Okay. Okay. Yeah, there's no sound in this. Okay. Okay. It's almost like a – This is actually, I don't know where, what happened to sound. But there's a song that plays in the background. But yeah, it's very much like if you just can imagine if there's sound playing, it's karaoke. karaoke. No plug-in necessary. Okay? No plug-in necessary to generate this stuff. Okay? And you've got SpongeBob. Let's go back. All right? And this is actually one of my favorites. This was in my web programming class. I had the students, you know, build a video caption. And this was a great student, a very good student of mine, built a video that took advantage of fail blog. Again, no plug-in necessary. Okay? No plug-in necessary. So you can do some really, really cool things. For example, just picture yourself if you can do, like, videos and, like, interactive media for accessibility purposes, all right? Now here's the catch, just to illustrate the problem with HTML5. This demonstration, this demonstration will not, will only work in Chrome and Firefox. It will not work in Safari. Okay? We're using, we're using org format for the video, all right? So that's video, and I want to see if this, if I can go to about geolocation, WTF.HTML, and this. So this demonstration is an exercise I made my students do, is to find where in the world is our good friend Carmen Sandiego, based on where we are, okay? So I built, I built a JSON feed which actually renders ten random locations around the world. I am actually going to allow, okay, nice that they actually prompt you permission, okay. So here, here we are. We are here. Oh. And Carmen, of course, she is in the 16th chapel. If I hit the refresh button again, she is now in Big Ben. So this is, you know, taking advantage of geolocation. This was a lab that I had the students do. Okay. Let's go back. Just some quick demos. So how does an HTML5 document look like? There's not much to it. If you know about HTML, the mark, if you know a little bit about HTML, then transitioning over to HTML5 is not difficult at all. The only one thing that you really need is the doc type. And look at this. You know, is less than pound, you know, exclamation point, doc type, HTML. That's all you need. A lot better than the doc type for HTML, isn't it? Pretty nice. That's it. And everything else really looks the same, okay? So where are we with areas of concern? So where's the danger, okay? The danger, of course, is with the web browser, the client side, all right? Now because HTML5 can do so much, you can now see the complexity, I mean, you can understand the complexity of a web browser, all right? You can do so much stuff, including, like, client side, like offline storage, okay? Now not only can you actually store a lot more information, content. But you can do so much more. But just imagine if you have a full ‑‑ almost a full‑fledged SQL database on the client side, okay? How about, you know, AJAX and the XML HTTP request object? Remember in JavaScript there was the same domain policy. But now you can actually do cross‑origin requests and even cross‑document messaging as well, okay? And I'm going to show you a little bit ‑‑ a little demo on ‑‑ yes. You can actually do, you know, for example, calculating prime numbers or whatever comes to your mind by way of web workers. Think of background threads, okay? And again, HTML5 is certainly going to make the browsers worse. I mean, last time I checked, I remember the Chrome bounty that just recently happened, and I think two of them were specific to HTML5 features on Chrome, okay? And the first thing I want to talk about is local storage. So local storage and session storage. We all know the good thing known as ‑‑ the thing known as cookies, right? Now here's the deal about cookies, just for your reminder. A cookie can only store four kilobytes of information. Local storage really depends on the browser. Last time I actually checked, it's around five ‑‑ you can store five megabytes of data, okay, for a local storage item, okay? If you actually can understand the whole concept of cookies and sessions, I mean, local storage and session storage, same idea. Key value storage. Very, very simple. It's very simple to use. It's ridiculously simple to use, okay? Persistence is that the only difference between local storage and session storage is persistence, okay? Session storage, if you can infer from the name, it only lasts, you know, until the browser is closed, okay? Local storage, something else. How do you use local storage or session storage by way of JavaScript? Really simple. These are local storage or session storage dot get item, dot set item, okay, or delete item. Or, if you prefer, you can use the associative array to hash syntax, okay, using square brackets. Here is just an example. Let's go back, okay? So here we are. Local storage example dot HTML. The phrase that pays is bonkers. Now, if I type in doo and doo doo. Okay. Okay. So I'm in Chrome. And using Chrome developer tools, go to view, go to developer tools, okay, under resources, all right, you see databases, local storage, session storage, cookies, application cache. Let's go to local storage and see what happens, okay? Here is my domain. 192.168.156.130. And, of course, key value pairs. Okay. You take a look. My key is just, I'm just using, I'm just generating time stamps as my key. And the value, of course, is everything that I have entered, okay? Not too hard. Let's go over and just view the source, okay? View, view source, all right? So my body is really, really simple. There's not much to it, okay? Just one div, one result, all right? One form tag. Look at my init function. First time it goes, first time the page loads is local storage dot set item. The key is phrase and the value is bonkers, all right? So if I actually hit return, okay, store. When I actually type something in, store is, okay, first get the thing that was in the text box, local storage, and, of course, the index, I mean, the key is going to be a time stamp equals text, all right? And how you render out all each and every item onto the page is I just do a very simple for loop and just, you know, go through my local storage and just render everything out to the page, okay? Very, very similar to the whole concept of cookies, all right? You got the same domain policy. But of course, well, let's go back. I actually want to change something to, actually, I'm going to come here. I'm going to go back. And I'm going to say, all right, but what's one of the things that you can do with local storage? Go to view, go to developer tools again. And now I can go to local storage and instead of do do, I can type h1, okay, and hit enter. And instead of do, I can have image src.exe. I don't care what it is, okay, get out of here, and I'm going to type Batman, and watch what happens, okay? And of course, well, this is broken, there's no image there, but you do see that now trap actually is the, you know, and as header one now takes into effect. So now you're starting to see some of the old hacks, okay? Some really age-old security principles, okay? So, think about this for a second. Here's the analogy. Is there a way that you can grab all the cookies on a person's machine? Other than beating the person up and taking their machine, which, of course, that is another thing that you can do with local storage. You can steal someone's machine and look into, you know, take, open their browser and just do what I did. You can see all the other values, but, you know, what's the other way that you can steal everyone's cookies? What's the attack? What attack do you use? Exactly. Oh, look at this. If you have a cross-site scripting vulnerability in your application, look at everything in local storage that's going to be susceptible, and there's a simple example, okay? And it just befuddles me. This is always a principle that I always, I mean, as dumb as this sounds, you're always going to have people that decide to want to store really sensitive information in local storage. Why? Okay? Next up, WebSQL. This is not new. This is not new, but I'm sure some of you, how many people remember the good old days of Google Gears? Unfortunately, you had to download a plug-in for that thing, okay? Now, this will bring SQL largely, like, a lot of, you know, good stuff to the client side. Here's some of the core methods, all right? You have open database, okay? You have transaction, and you have execute SQL, okay? Even prepared statements are supported. But you do also have the usual game. Signing of attacks, cross-site scripting, SQL injection. Let me show you an example, okay? Let's go back, all right? And I got three simple examples, three examples. I am going to close out of this. And now, I am going to do actual size, and let's go to WebSQL example number one, okay? And I'm going to say something, just really rudimentary. Go get me a beer. Homer. Homer. Okay? Homer says, go get me a beer, all right? Okay? Now, I'm going to hit kick and hit enter, all right? So, where's the data stored? Well, again, in Chrome, go to developer, developer tools, go to resources, now go to databases. Now. My database, I have one database called demo-mchow. And I can expand it. And I have one table called thoughts. Okay? I have a date key. I have three fields, date key, phrase, and handle. All right? Now, if I go to, all right? Okay. All right. General. I don't know why that's not showing up for some reason. I'm going to vote for tools, demo. Okay? Well, at any rate, how this works. Use source. this is what happens so DB open database DB equals open database you give it a database name you give it a version number some description and of course the last field the 5000 or open database is some size okay and here's around roughly five megabytes so I'm only going to you know open a create a new beta database if you know it's you know if it is if it doesn't exist already if the database already you know if not exists create table you notice one thing about when I'm creating the table called thoughts the three fields doesn't take in any data type no database data types needed so it's pretty loose okay now how do I insert data yeah uh well I do a transaction DB transaction and I inside is a function execute SQL and there is my SQL statement right here so of course you know another oldie but goodie this is bad I mean this is bad principal improvement to make of course is to use prepared statements all right now let's go to an example not example one of a one but example number number two. Okay. Okay. That works. Of course, we got a broken image. But let's take a look at the difference in this thing. Let's take a look at the difference. Got a view source. Everything is the same except for one thing. Okay. This is a user-prepared statement. Okay. Execute SQL insert into thoughts, of course. Find the variables with question mark. Okay. Of course, this is nice, but we can do a little bit better. All right. We can do a little bit better. How about escaping all the special characters? All right. Some things that, you know, it doesn't hurt reminding everyone. Image source. Okay. How do I actually did this is very simple. I just wrote my own JavaScript. I just wrote, you know, HTML and code. I just encoded all the HTML. That's about it. All right. So now we've seen local and session storage. We've seen Web SQL. All right. Again, just, you know, the defenses, again, well, don't store sensitive data in the client-side database. You know, very much like Chrome, like local storage, session storage, you can see all the data in the browser. Okay. The other thing is, why do you think, I mean, what's the real power behind local storage and Web SQL? I mean, why is it so, you know, why is it so useful? Yeah, because, you know, not only for, you know, cookie and tracking purposes, everyone here should read the paper on the EverCookies, but also if you're going to do offline work. Okay. So if you're going to work offline and then you're trying to sync online when you go online, can you really, really trust what is stored on the client-side? All right. One other suggestion, of course, is to create your database and store data over SSL. Okay. Oh, and one last thing is, I mentioned a few times when I, especially during geolocation, it's nice, of course, if you prompt the user, you know, good feedback to just say, you know, hey, we would like to use your database. Can we do so? Okay. Or, you know, application cache. Application cache is really, really cool for offline, using a lot of games. For example, if you're going to be on a mobile device, you can't depend that it's going to be on a... You can't depend on networking all the time. Let's say if you're going to be having, like, you have an HTML5 game. All right. Also reduces a lot of server load. Okay. Right now, if I'm not mistaken, the size limit for cache data is around five megabytes. There are two things that you need to do in order to enable application cache. First thing is, in the HTML tag, specify the manifest file by way of the manifest attribute equals, let's give it an example, that manifest. So that's the file that's going to be stored on the root level of the server. Of the WWW folder. But, of course, the manifest file, example.manifest, is going to look like the following. You state the files that need to be explicitly cached. HTML, CSS, you know, all the static content. You can also specify what content need to be... Need required network... You know, require networking. Okay. How you update the application cache, you can add an event listener. All right. Update. And, of course, the attribute, you know, the event is going to be checking. And, you know, the function, you write a function called update cache data to just do something. Well, one of the things about the danger points about the application cache is it can be poisoned. All right. The point, the purpose is, not only there's no permission necessary for any site to cache data onto the browser, look, what are you really caching? And there's a real big catch. Okay. So what happens is, although the root resource is cached, but the normal cache is updated but not the application cache. Okay. Cross origin. JavaScript request. Okay. This is not directly part of the HTML5, but it is introduced. So, of course, if you remember from... S? xhr. It follows large back in the good old days. It largely follows the same domain principle. Okay? IE and ie8, there is a new JavaScript object called X domain request. Even now, in a lot of cases, like in Firefox or in Chrome, the xhr can actually allow for cross- domain requests. How? You guys remember the? Remember that the source, remember that example with Carmen Sandiego, well, let's take a look. If you actually, I'm going to go in, bar www, I'm just going to give you a little snapshot more, and, of course, the script that is used in the request.open in XHR is Acme, oh, actually I don't have it here, oh, XDR.php, and there you go. I know it's a little bit, let me zoom this in. Zoom this in. Okay. How Carmen, how I get the JSON for the Carmen Sandiego demo, well, it's just a few lines of PHP. But what I do is I specify the header, okay, there's a flag called access-control-allow-origin, followed by a colon, and then it should follow a whitelist of allowed sites. I'm using an asterisk here. Now, this is not good. This is a wild card. All right. I'm allowing everyone and everyone in the world to actually have access to this data. This is bad, okay, if you're going to use a wild card. What's even worse is the following. What if, okay, I do access-control-allow-origin, HTTP colon, of course, and, of course, some origin, but, you know, and then I have percent, what is wrong with that second example? Okay. How do you actually separate, okay, a whitelist of allowed websites is using a space. You put that one, you put that in, it's going to, the percent 20, well, it's going to be equated into a space. And so you have actually not one, you have two domains that are allowed. Well, how do you get around, how do you actually, what's the defense? Two things. Number one, you want to add some, of course, either A, some sort of authentication or some key. Key, like Google Maps did back in the days, or validate the response, okay? Cross-document messaging. It is possible to actually, you know, to actually build, for example, a chat, you know, a chat application using straight HTML5 now, using the whole idea of post message. You can communicate, you know, between two different domains, two different, you know, two different, two different origins, two different frames. Okay. Two parts of the, two parts, there's a sender and there's a receiver. The purpose of the sender, okay, of what the sender will do, it will post a message, while the receiver is going to listen for messages being sent. Now, I'm just going to give you a demo. Okay. Here is a demo. Actually, this time I will need, okay. So I have CDM receiver on the server. Okay. I'm going to view source. Okay. Now, the domain of the receiver is 192.168.156.130. And look, the receiver is going to have, I mean, the code is it's going to have one event listener. All right. It's going to listen for a message, and then it's going to check for the origin. All right. So. So, what about the sender? Well, all I can do, I'm going to open file, I'm going to open a file on my desktop. My desktop, DC 19, examples, okay, CDM sender. Here it is. This is a sender. That's an iframe. That contains code to the receiver. View source. Okay. So, what I do is, you know, have one text field. Okay. One form field. And then all it's going to do, where is the post message? Just short this. Here it is. One iframe. And the post message. Post message. message. The message and, of course, the domain. So how this works. Okay. Hello. Goodbye. And remember, okay, it is everything is all listened by way of the receiver on 192 on my virtual machine. So what's the problem here? Well, here's the catch. You really also want to verify where the message is coming from. Okay. And you can do that. All right. There is when you are the receiver, when you're listening for a message, okay, the callback to receive a message, it takes in one argument, the event. You can check where the origin is. Okay. Event.Origin equals equals or does not equal. All right. And you can check the origin that way. Okay. Yeah. It's also been a subject of controversy. For more information, of course, check out the Mozilla SDK documentation. All right. Some really powerful stuff, web workers. How do you actually add comp you can now add really computational power, you know, to the background of whatever page you're actually working on. Okay. Think of threads. Okay. And it is really, really powerful. It's really, really easy to use. All right. Very, very easy to use. How you actually spawn a worker? Well, you set a variable. W equals new worker. Okay. And, of course, the parameter is going to be, say, some JavaScript file. All right. On message, of course, you can also have that JS file actually send back messages to you. Okay. And to terminate the thread, you just do, well, it's going to be W.terminate. Okay. There are some few caveats. For example, a web worker has to be on a server. It cannot run on the machine. Okay. The same origin principle applies. But here's the real funny stuff that the worker have access to. What stuff does a worker have access to? It have access to, oh, the navigation object, the XHR. Even the application cache and the ability to spawn other workers. Really, really cool. What the worker on the flip side does not have access to, of course, is, like, the document object and the window. What can you do with this? Use your wildest imagination. Someone here tried to build a password cracker with this thing. You can now do this. All right. Now how does this work? I'll give you an example. Get out of here. Go back. All right. And this, okay, what's the example? Ah, here it is. Worker test. All right. And, yeah, there's no way to kill this thing, either. There's no X button to stop this. All right. How this works, I have the HTML. Let me ‑‑ yeah, it's still going to run, but I don't want to crash this machine. Okay. There it is. There's even more. So there's no way to stop this other than for me to close the browser. All right. So how this really works? Well, let me show you what really happens. Clear. Okay. More worker.js. That's it. That's a script. Okay. Just a very simple script to just find the prime numbers. How the page looks. More worker test2.html. Here it is. Very simple markup. One core computation. All right. I have one script tag. Okay. Worker equals new worker, and it will point to that worker JavaScript file that I just showed you. All right. And, of course, you can actually check. If there is an event from the JS file sent back to you by, well, worker.onMessage. That's when you're going to be receiving messages from the JS file. Actually, let me go back. Okay. How this JS file, this thing that gets spawned, sends messages back to your page. Look at that last line. It's a post message. Okay. It will send data back to the HTML page. Okay. And that's WebWorkers. Really, really powerful stuff. But, of course, you saw the demo on video. You saw geolocation. One other thing I haven't even talked about is what about, you know, the Canvas? What about browser rendering of 2D and 3D graphics? What about SVG rendering of, you know, just on the fly SVG rendering? Well, depends on the browser. Okay. Here I'm going to pose a scenario. A lot of people now using, like, you know, using video, HTML5 video, like YouTube and Brightcove. Well, what happens if there are flaws in the codec? Think about it. Okay. Also, this actually works. You can embed a script. Okay. Inside the onError attribute in the audio tag. Already, I already pointed out. In the latest bounty hunt by Google Chrome, two of the bugs were found, were specific to HTML5 features on Chrome. Well, there's also a heap buffer. There was a heap buffer overflow by way of the, you know, that, you know, had pertained to, had everything to do with the HTML5 Canvas in Opera. Okay. Also, we all love regular expressions. Right? Regular expression for pattern matching. Well, there's one new attribute in the form field in HTML5, which is called pattern. All right. So, you can do client-side validation. Let's say client-side validation of an email address. Okay. An example will be input, and then you feed pattern equal, well, some regex. What happens, okay, if, for example, your pattern is, like, A star, and, of course, your value is just a long running stream of As? Well, there it is. There is a potential client, there is a potential for regular expression denial of service. All right. And, of course, this was actually found in one of the versions of Opera. Okay. So, what's the whole story here? You know, so, in summary, look, HTML5 can do a lot of really, really cool stuff. You can build full-fledged web applications, all right, and a lot of really groundbreaking, seminal stuff. Right now, the only thing that I know that Mozilla is working on a plug-in for taking, you know, for accessing your camera and your microphone on your device by way of JavaScript, so there is a potential that you may be able to build chat roulette with HTML5 one day. But here's the bottom line. Look. You know, you can do all these cool things. But there's two things that really stands out. Number one, security seems like a complete afterthought, like most of the times, when they're putting together the HTML5 standard. Okay. And the second thing is, a lot of the stuff to really defend yourself, this is not new. Okay. It's not news. Like, for example, how do you actually, you know, the defenses for local storage, web SQL. You know. They're all the stuff that you've heard in the past. Okay. Sanitize your data. You know. Don't store sensitive information. Okay. A lot of the same old problems. Same old resolution in just a brand-new environment. Of course, another caveat just to keep in mind is the standard is evolving. It's changing, like, every day. So it's even hard for me to keep up. But why am I giving this talk? Look. HTML5, this whole topic of HTML5 is not going away any time soon. All right. Now, because of the iPhone and the iPod, you know, all these devices. Okay. Because here's the problem if you build mobile applications. Mobile applications, you're going to use the Android SDK or the iPhone SDK. All right. There's a lot of fragmentation issues. Because if you're going to build a web app, you have to build something directly for using the Android SDK. Directly, you know, using the iOS SDK. All right. HTML5 is one of the most viable options if you want to have, you know, one environment. Just one app that can run on everything. All right. And a lot of people now know of the problem of segmentation in the mobile app world. Okay. So this can't be ignored. HTML5 just cannot be ignored. All right. And it seems like, well, I got some good news. I got ten minutes left. And I am done. Thank you. All right.