290 likes | 392 Views
WEB308: Usability, SEO, Security: Common RIA and Ajax Mistakes (and Fixes). Christian Wenz Arrabiata Solutions GmbH. Common Mistakes. Bookmarks/ maintaining state Back/ forward buttons Not robust w/r/t latency Too many concurrent HTTP requests SEO Security. Traditional Web Model.
E N D
WEB308: Usability, SEO, Security:Common RIA and Ajax Mistakes (and Fixes) Christian Wenz Arrabiata Solutions GmbH
Common Mistakes • Bookmarks/maintainingstate • Back/forwardbuttons • Not robust w/r/t latency • Toomanyconcurrent HTTP requests • SEO • Security
Traditional Web Model Request Response Request Response Client Server
RIA Model Request Response RIA Request Response Client Server
Bookmarks • Applicationschangestate • Yetwith RIAs, the URL does not change (to avoid a pagerefresh) • Thus bydefaultbookmarksonlyrefertothestartpage
Fixing Bookmarks • Cookies • Requirecookiesupport, not portable to otherbrowsersormachines (thelatterworkswithprofilesandsynchronization, though) • Puttingstateinformation in the URL • Must usehash/anchor, toavoidpagerefresh • Not visibletosearchengines • Becarefulwhenparsingthisinformation
Back/Forward Buttons • Browsers‘ back/forwardbuttonsnavigatetothepreceding/successing URL • Whenthe URL doesn‘tchange, thebuttons do not work
Fixing Back/Forward Buttons • Changingthe URL hashgives back/forwardbuttonssomethingtoworkwith • hashchangeevent in HTML5 • Not in olderbrowsers, though • Formaximumbrowsercompatibility, weneedactual HTTP requests • HTTP requests in themainbrowserwindowwouldcause a refresh, though • Solution: useiframes
Fixing Back/Forward Buttons (2) Preservingstate Retrievingstate Browser Browser App changesstate App changesstate Data iswritten Data isread Iframe Iframe User clicks back/forwardbutton
Historysupport in ASP.NET • EnableHistoryfeatureofScriptManager • Allowsaddingofhistorypoints • Provideseventhandlerfor back/forwardbuttonclick • Server API (usefulwhenusingUpdatePanels) • Client API
Adding Back/Forward Button Support to an ASP.NET Application demo
Historysupport in jQuery • Variouspluginoptions: • BBQ plugin(http://benalman.com/projects/jquery-bbq-plugin/) • hashchangeplugin (http://benalman.com/projects/jquery-hashchange-plugin/) • Historyplugin (http://tkyk.github.com/jquery-history-plugin/)
Adding Back/Forward Button Support to a JavaScript Application demo
HTTP: Latencyand Error Handling • HTTP requestsmaytake time • JavaScript does not feature a built-in processqueue • Potential sideeffectsifyou send multiple requests in a shortperiodof time iftheordermatters • Also, JavaScript does not provide a decenterrorhandlingif a requestfails (ortakestoolong) • Timeouts • Droppedconnections
Fixing HTTP Latencyand Error Handling • Add randomlatencyduringtesting • Implement a customtimeouthandlin • Abort/restartconnectionsthattaketoolong • WhenusingASP.NET‘s JavaScript web serviceprocy, useset_timeout()toprovide a timeoutvalue
Concurrent HTTP Requests • The numberofconcurrent HTTP requeststothe same FQDN is limited • HTTP 1.1 RFC: a „client SHOULD NOT maintainmorethantwoconnectionswith a serverorproxy“ • Internet Explorer 8+, Firefox 3+: 6 connections • Other recentbrowsers: usually 4 or 6 connections, sometimesmore • Olderbrowsers: usually 2 or 4 connections • Youcannotcontrolwhathappens in otherbrowserinstancesortabs • But youcanlimittheresourcesyouareusing
Fixing Concurrent HTTP Requests • Bufferdata on theclientandcombineseveralrequestsintoone • Uselong-livingconnections • Useone HTTP connectiontocontinuously send orretrievedata • Approach also called „Comet“
Search Engine Optimization • Search engines do not reallyspeak JavaScript or Silverlight • Technically, theymightseeandindexdynamiccontent. • But don‘tbet on it • Dynamicallyloadedcontentis invisible tosearchengines • RIAs usuallyonlyhaveone URL (andthe URL hashis not usedbysearchengines)
Fixing Search Engine Optimization • Provide all relevant contentasstatic HTML pages • Use links, ifpossible • Create an alternative versionofyoursitethatdoes not require JavaScript orplugins
Web Application Security • Using a RIA technologymightincreasetheattacksurface • Using a RIA technologymightrestrictwhatyourapplicationisallowedto do • Cross-Site Scripting (XSS) • Cross-Site Request Forgery (CSRF) • SQL Injection • …
Cross-Site Request Forgery • Browsers send cookiesforfree … Other website Requestspage Sends script Victim (browser) Requestspage Attacker (website)
RIA´s Same Origin Policy • Toprevent CSRF (andforsomeotherreasons), JavaScript, Silvelrightandother RIA technologiesimplement a „same originpolicy“ (SOP) • HTTP Requestsmayonlybesenttotheoriginserver (protocol, port, domainname) • With JavaScript, theoriginserveristheserverthe HTML comesfrom • With Silverlight (andotherplugins), theoriginserveristheserverthe Silverlight applicationcomesfrom • Policyfileshelptocircumventthisrestriction • Policyfilesneedtobeplaced on thetargetserver
Fixing RIA Security • Audit all backend servicesfor XSS, SQL Injectionandothervulnerabilities • Protectagainst CSRF attacks • Keep in mindthattheclientcannotbecontrolled • Don‘tstore sensitive data in JavaScript or Silverlight • Do not trustdatabeingsentfromyourclientapplicationtotheserver • Mindtheusualsecurityadvice: Validateinput, escapeoutput
ThankYou! • Questions? • Email: christian.wenz@arrabiata.de • WWW: http://www.arrabiata.net/ • Twitter: @chwenz
Session Evaluations Tell us what you think, and you could win! All evaluations submitted are automatically entered into a daily prize draw* Sign-in to the Schedule Builder at http://europe.msteched.com/topic/list/ * Details of prize draw rules can be obtained from the Information Desk.
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.