SlideShare a Scribd company logo
Cross-Site Ajax Challenges and Techniques for Building Rich Web 2.0 Mashups Joseph Smarr Plaxo, Inc. [email_address]
The promise of mashups Create new experiences by combining  components from different authors Each site focuses on what it does best Can wire up components in a novel way Google maps + Craigslist = HousingMaps Rich interaction often requires talking  back and forth between components House’s address    lat / long    map it
Talking between web components Normal situation : all on the same web site Communicate across frames / iframes / popups Talk to server using AJAX (XMLHttpRequest) Problem : doesn’t work when components  live at different domains (mashup situation) Same-origin   policy Can include JavaScript / images from another domain Can’t talk to frame / iframe popup or send an XHR Prevents snooping on secret web pages (e.g. intranet)
So, how do mashups communicate? CAN  include image / JavaScript / CSS from Domain B   CAN  send XMLHttpRequest to Domain A   CAN  talk to other frames / iframes / popups on Domain A  CAN'T  send XMLHttpRequest to Domain B  CAN'T  talk to other frames / iframes / popups on Domain B  CAN  talk to other pages  on Domain A   CAN’T  talk to any page on Domain A  Domain B XML / Web Page XHR Image CSS JavaScript
How do mashups communicate? Often, they don’t (Google maps 1.0) Single JavaScript    all processing done locally Plotting lat/long or fetching image tiles is deterministic Can’t get any additional data (e.g. geo-coding) Server-side proxy (HousingMaps, Flickr) Talk to your server    it talks to the foreign site Problem: bottleneck; barrier to mass deployment
Server-side proxy Web Page Domain A Server Domain A Server Domain B
How do mashups communicate? Often, they don’t (Google maps 1.0) Single JavaScript    all processing done locally Plotting lat/long or fetching image tiles is deterministic Can’t get any additional data (e.g. geo-coding) Server-side proxy (HousingMaps, Flickr) Talk to your server    it talks to the foreign site Problem: bottleneck; barrier to mass deployment Use flash for cross-domain communication Can use crossdomain.xml to allow foreign sites Yahoo maps uses this to do geo-coding
Flash proxy Web Page Domain A Server Domain B Flash crossdomain.xml
How do mashups communicate? JSON-P (Script injection + callback) Dynamically load JavaScript file with data Use DHTML to inject a  <script>  tag in the document Data is returned in JSON (JavaScript data format) Clever trick: specify callback function on URL foreign-site.com/json-api.js? callback=myFunc Loads  myFunc ({ data: “hello” });     round-trip! Works well in practice, but some drawbacks Limited control vs. XHR (just loads or doesn’t) API provider can return malicious code (e.g. steal cookies)
JSON-P Web Page Domain A Server Domain B <script> JSON + callback
Using JSON-P in OO web apps Problem : callback function has to be global Complex code maintains state / instances Would like to handle callback with instance function on instantiated object Solution : bind the callback dynamically Create a globally-unique function name Usually global prefix + auto-incremented counter Use a closure to call your function in object-scope Send the global function name as callback     it calls your scoped function
Dynamically binding a global callback var cbName = 'cb' + JSON.callbackCounter++; var cbFunc = function(jsonData) { myFunc .call( myObj , jsonData); // call bound callback }; JSON.callbacks[cbName] = cbFunc; var globalCallbackName = ‘JSON.callbacks.’ + cbName // url: '/json-api.js?callback=' + globalCallbackName; Used by dojo (ScriptSrcIO), Google Maps 2.5, Plaxo, etc.
Summary of cross-site techniques so far No cross-site communication Include partner’s JS file once (can’t talk again) Server-side proxy Talk on the backend (bottleneck, barrier to adoption) Flash proxy Talk through cross-domain flash (requires flash) JSON-P Talk through script-injection with callback  (less control, partner could be malicious)
What about updating another web page? Proxies / JSON-P let you access foreign data But still can’t touch a foreign frame/iframe/popup Many potential mashups would like to interact with existing web pages Auto-fill a form with your contact info Highlight relevant search results / text snippets How can two sites that want to cooperate get around the  same-origin  policy?
 
What does the partner site have to do? Add the  button to your page <a onclick=&quot; showPlaxoABChooser('textarea', '/cb.html') ; return false&quot; href=&quot;#&quot;> <img src=&quot;http://www.plaxo.com/images/abc/buttons /add_button.gif&quot; alt=&quot;Add from my address book&quot; /></a> Specify the ID of your e-mail <textarea> Specify the location of your hidden callback page Add a small callback page on your site <html><head><script type=&quot;text/javascript&quot; src=&quot;https://www.plaxo.com/ab_chooser/abc_comm.jsdyn&quot;> </script></head><body></body></html> Full instructions and demo:  http:// www.plaxo.com/api
What does Plaxo have to do? Remember: Plaxo filled in a textarea on zazzle! Need to get around  same-origin  policy Without server-side proxy (JS/HTML only) JSON-P won’t solve this problem Widget popup is hosted by Plaxo and goes thru several steps Zazzle doesn’t know when to request the contact data Solution:  “The JavaScript Wormhole” Add hidden callback page on zazzle that includes Plaxo script Plaxo popup loads callback in an iframe when done Script is dynamically generated, and includes selected data IFrame is also on zazzle (and has the data), so it can tell parent.opener to fill in the textfield
zazzle.com/email_this plaxo.com/ab_chooser plaxo.com/ab_chooser Iframe: zazzle.com/cb.html    Script: plaxo.com/ab_chooser/abc_comm.jsdyn
Who’s using the Plaxo widget? See more at  http://www.plaxo.com/api/gallery Using the widget? Let us know!
Generalizing the JavaScript Wormhole Site has a generic callback page to give you access Site tells you the location of their callback page Callback page loads your domain’s JavaScript JavaScript is dynamically generated to include your data Can pass script url with query args to callback page /cb.html? http://foreign-site.com/json-api.js?name=val Access query string on cb page with  location.search Site can restrict callback page to trusted hosts Only load script if it’s on a trusted domain Could further restrict to certain URL prefixes, etc.
<html><head><title>Generalized JavaScript Wormhole</title> <script type=&quot;text/javascript&quot;> var trustedDomains = [ &quot;http://www.plaxo.com/api/&quot;, &quot;http://www.google.com/&quot; ]; function isTrustedDomain(url) { for (var i = 0; i < trustedDomains.length; i++) if (url.indexOf(trustedDomains[i]) == 0)  return true; return false; } function doWormhole() { var url = location.search.substr(1); // chop off ? if (isTrustedDomain(url)) { var script = document.createElement('script'); script.type = &quot;text/javascript&quot;; script.src = url; document.getElementsByTagName(&quot;head&quot;)[0].appendChild(script); } else alert(&quot;ignoring untrusted url: &quot; + url); } </script></head><body onload=&quot;doWormhole()&quot;></body></html>
Where do we go from here? Ajax is a “hack” on top of an old platform The platform can evolve
Where do we go from here? Ajax is a “hack” on top of an old platform The platform is evolving
Where do we go from here? Ajax is a “hack” on top of an old platform The platform is evolving What platform do we want to build?
Should we open cross-domain XHR? After all, we can already include foreign JavaScript, image, and CSS files So why not XML too? (“just another resource file”) HTML looks like XML (esp. XHTML) Hard to make sure you  really  meant to serve that page as XML data (cf. js / img / css) Personal / private info more often in XML / HTML But increasingly a problem with JS too (JSON) Cookies / creds sent with XHR request Can’t easily distinguish direct vs. XHR access
Trust relationships between sites Random site accessing this file vs. trusted partner Flash does this with crossdomain.xml Web services do this with certs / IP whitelists JavaScript wormhole does it (sort of) Should a trust relationship exist for mashups? Want to minimize barriers to adoption / innovation When sharing user info, should have prior agreement? How formal / technical should this trust be?
Restricting access to unauthorized info Restrict XHR to same “internet zone” So public site can’t access intranet page Don’t send  any  cookies / credentials via XHR Practically restricts cross-site comm. to fully public info Could still send auth info on URL But now other site has it Give other site limited-access token? White-list authorized sites with cross-domain file Return special response headers for public pages Legacy problem for existing content
Proposals for better cross-site tools  ContextAgnosticXmlHttpRequest  (Chris Holland) Alternative to normal XmlHttpRequest for cross-site Don’t send/receive any cookie or HTTP auth info Server must specify X-Allow-Foreign-Hosts in response JSONRequest  (Douglas Crockford) New browser object for cross-site JSON (like XHR) Allows GET / POST / cancel of JSON request / response No cookies / auth info sent or received Requires special headers in request / response
In conclusion… Cross-site communication is tricky but important Key enabling technology for building rich mashups Raises legitimate security issues that can’t be ignored Today: Use server-side proxy or JSON-P Proxy introduces bottleneck, but provides full access JSON-P is more scalable, but limited to JSON APIs JavaScript Wormhole lets you touch foreign pages Keep the discussion of better tools / protocols going! This problem is here to stay Browser developers are listening!
For further reading… Cross-site limitations http://getahead.ltd.uk/ajax/cross-domain-xhr http:// msdn.microsoft.com/library/default.asp?url =/workshop/author/ om/xframe_scripting_security.asp FlashXMLHttpRequest http:// blog.monstuff.com/FlashXMLHttpRequest ContextAgnosticXMLHttpRequest http://chrisholland.blogspot.com/2005/03/contextagnosticxmlhttprequest-informal.html JSONRequest http:// json.org/JSONRequest.html

More Related Content

PPT
Joomla security nuggets
PDF
Opening up the Social Web - Standards that are bridging the Islands
PPT
Pragmatics of Declarative Ajax
PPTX
RESTful design
PDF
SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...
PDF
HTML5 Introduction
KEY
Intro to Ruby
PPTX
Css, xhtml, javascript
Joomla security nuggets
Opening up the Social Web - Standards that are bridging the Islands
Pragmatics of Declarative Ajax
RESTful design
SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...
HTML5 Introduction
Intro to Ruby
Css, xhtml, javascript

What's hot (20)

PDF
HTTP/2 BrightonSEO 2018
ODP
A Holistic View of Website Performance
PPTX
The internet for SEOs by Roxana Stingu
PPTX
Internet protocalls & WCF/DReAM
PDF
Keypoints html5
PPT
Advanced Json
KEY
Building A Gem From Scratch
PDF
HTML5 & Friends
DOC
QuickConnect
PDF
HTML5 Semantics, Accessibility & Forms [Carsonified HTML5 Online Conference]
KEY
Story-driven Testing
PDF
Html 5 in a big nutshell
ODP
PDF
HTML5: Smart Markup for Smarter Websites [Future of Web Apps, Las Vegas 2011]
PPTX
.htaccess for SEOs - A presentation by Roxana Stingu
PDF
Command Line Hacks For SEO - Brighton April 2018 - Tom Pool
PDF
HTML5 Essentials
PDF
HTTP Basics Demo
PPTX
Real-time Ruby for the Real-time Web
PDF
Plone.restapi - a bridge to the modern web
HTTP/2 BrightonSEO 2018
A Holistic View of Website Performance
The internet for SEOs by Roxana Stingu
Internet protocalls & WCF/DReAM
Keypoints html5
Advanced Json
Building A Gem From Scratch
HTML5 & Friends
QuickConnect
HTML5 Semantics, Accessibility & Forms [Carsonified HTML5 Online Conference]
Story-driven Testing
Html 5 in a big nutshell
HTML5: Smart Markup for Smarter Websites [Future of Web Apps, Las Vegas 2011]
.htaccess for SEOs - A presentation by Roxana Stingu
Command Line Hacks For SEO - Brighton April 2018 - Tom Pool
HTML5 Essentials
HTTP Basics Demo
Real-time Ruby for the Real-time Web
Plone.restapi - a bridge to the modern web
Ad

Viewers also liked (20)

PDF
07 ZamyšLení Velké MyšLenky
PPT
Transforming Your Business in the "Cloud" with Callidus Software and Salesfor...
PPT
หมวก6ใบ
PPT
La mappa della cultura immateriale
PPS
Arte Con Solo Una Hoja De Papel
PPT
PPT
Elluminate Wiki Intro 29749
PPT
Comete
PPTX
GeoGraphics
PPS
Unfolding Of A Vision
PPTX
Land and Light
PPT
Milano Smart City
PPT
Milieu
PPT
Request for a decentralized social network
PPT
Las Tendas-Madrid
PDF
Mexico City - Cuidad de Mexico
PDF
Gp Parki Narodowe
07 ZamyšLení Velké MyšLenky
Transforming Your Business in the "Cloud" with Callidus Software and Salesfor...
หมวก6ใบ
La mappa della cultura immateriale
Arte Con Solo Una Hoja De Papel
Elluminate Wiki Intro 29749
Comete
GeoGraphics
Unfolding Of A Vision
Land and Light
Milano Smart City
Milieu
Request for a decentralized social network
Las Tendas-Madrid
Mexico City - Cuidad de Mexico
Gp Parki Narodowe
Ad

Similar to Joseph-Smarr-Plaxo-OSCON-2006 (20)

ODP
Implementing Comet using PHP
PPT
Think jQuery
PDF
Divide et impera
PPT
Grails Introduction - IJTC 2007
PPT
Using Ajax In Domino Web Applications
PPTX
Project Feedloop
ODP
ActiveWeb: Chicago Java User Group Presentation
PPTX
Introduction about-ajax-framework
ODP
Scout xss csrf_security_presentation_chicago
PPT
PPT
Gooogle Web Toolkit
PPT
Getting More Traffic From Search Advanced Seo For Developers Presentation
PPT
Introduction to Alfresco Surf Platform
PDF
Cape Cod Web Technology Meetup - 2
PPT
Mobile webapplication development
PPT
Advanced SEO for Web Developers
PDF
IE 8 et les standards du Web - Chris Wilson - Paris Web 2008
PPTX
HTML5 Web Workers-unleashed
PDF
Pushing the Web: Interesting things to Know
PPT
Ajax to the Moon
Implementing Comet using PHP
Think jQuery
Divide et impera
Grails Introduction - IJTC 2007
Using Ajax In Domino Web Applications
Project Feedloop
ActiveWeb: Chicago Java User Group Presentation
Introduction about-ajax-framework
Scout xss csrf_security_presentation_chicago
Gooogle Web Toolkit
Getting More Traffic From Search Advanced Seo For Developers Presentation
Introduction to Alfresco Surf Platform
Cape Cod Web Technology Meetup - 2
Mobile webapplication development
Advanced SEO for Web Developers
IE 8 et les standards du Web - Chris Wilson - Paris Web 2008
HTML5 Web Workers-unleashed
Pushing the Web: Interesting things to Know
Ajax to the Moon

More from guestfbf1e1 (13)

PPT
xrefer-lightowlers
PPT
unusualevent
PPT
training_tuftspma
PPT
Sess_39_NAMCS&NHAMCS_hands-on_SCHAPPERT
PPT
20070612150756-0
PPT
DesmedtXSB
PPT
GeneticAlgorithm
PPT
dorsdl2006-arrow
PPT
kevin_mcmahon_power_point_slides
PPT
WLCG-Discu
PPT
xreferplus-dereksturdy
PPT
PPT
LearningProgressionstoELit_Anderson
xrefer-lightowlers
unusualevent
training_tuftspma
Sess_39_NAMCS&NHAMCS_hands-on_SCHAPPERT
20070612150756-0
DesmedtXSB
GeneticAlgorithm
dorsdl2006-arrow
kevin_mcmahon_power_point_slides
WLCG-Discu
xreferplus-dereksturdy
LearningProgressionstoELit_Anderson

Recently uploaded (20)

PDF
Mushroom cultivation and it's methods.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Encapsulation theory and applications.pdf
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
A comparative study of natural language inference in Swahili using monolingua...
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
Getting Started with Data Integration: FME Form 101
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
A novel scalable deep ensemble learning framework for big data classification...
PPTX
A Presentation on Touch Screen Technology
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Mushroom cultivation and it's methods.pdf
Assigned Numbers - 2025 - Bluetooth® Document
Encapsulation theory and applications.pdf
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Univ-Connecticut-ChatGPT-Presentaion.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
A comparative study of natural language inference in Swahili using monolingua...
SOPHOS-XG Firewall Administrator PPT.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
gpt5_lecture_notes_comprehensive_20250812015547.pdf
OMC Textile Division Presentation 2021.pptx
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
cloud_computing_Infrastucture_as_cloud_p
Getting Started with Data Integration: FME Form 101
Unlocking AI with Model Context Protocol (MCP)
A novel scalable deep ensemble learning framework for big data classification...
A Presentation on Touch Screen Technology
Digital-Transformation-Roadmap-for-Companies.pptx
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf

Joseph-Smarr-Plaxo-OSCON-2006

  • 1. Cross-Site Ajax Challenges and Techniques for Building Rich Web 2.0 Mashups Joseph Smarr Plaxo, Inc. [email_address]
  • 2. The promise of mashups Create new experiences by combining components from different authors Each site focuses on what it does best Can wire up components in a novel way Google maps + Craigslist = HousingMaps Rich interaction often requires talking back and forth between components House’s address  lat / long  map it
  • 3. Talking between web components Normal situation : all on the same web site Communicate across frames / iframes / popups Talk to server using AJAX (XMLHttpRequest) Problem : doesn’t work when components live at different domains (mashup situation) Same-origin policy Can include JavaScript / images from another domain Can’t talk to frame / iframe popup or send an XHR Prevents snooping on secret web pages (e.g. intranet)
  • 4. So, how do mashups communicate? CAN include image / JavaScript / CSS from Domain B CAN send XMLHttpRequest to Domain A CAN talk to other frames / iframes / popups on Domain A CAN'T send XMLHttpRequest to Domain B CAN'T talk to other frames / iframes / popups on Domain B CAN talk to other pages on Domain A CAN’T talk to any page on Domain A Domain B XML / Web Page XHR Image CSS JavaScript
  • 5. How do mashups communicate? Often, they don’t (Google maps 1.0) Single JavaScript  all processing done locally Plotting lat/long or fetching image tiles is deterministic Can’t get any additional data (e.g. geo-coding) Server-side proxy (HousingMaps, Flickr) Talk to your server  it talks to the foreign site Problem: bottleneck; barrier to mass deployment
  • 6. Server-side proxy Web Page Domain A Server Domain A Server Domain B
  • 7. How do mashups communicate? Often, they don’t (Google maps 1.0) Single JavaScript  all processing done locally Plotting lat/long or fetching image tiles is deterministic Can’t get any additional data (e.g. geo-coding) Server-side proxy (HousingMaps, Flickr) Talk to your server  it talks to the foreign site Problem: bottleneck; barrier to mass deployment Use flash for cross-domain communication Can use crossdomain.xml to allow foreign sites Yahoo maps uses this to do geo-coding
  • 8. Flash proxy Web Page Domain A Server Domain B Flash crossdomain.xml
  • 9. How do mashups communicate? JSON-P (Script injection + callback) Dynamically load JavaScript file with data Use DHTML to inject a <script> tag in the document Data is returned in JSON (JavaScript data format) Clever trick: specify callback function on URL foreign-site.com/json-api.js? callback=myFunc Loads myFunc ({ data: “hello” });  round-trip! Works well in practice, but some drawbacks Limited control vs. XHR (just loads or doesn’t) API provider can return malicious code (e.g. steal cookies)
  • 10. JSON-P Web Page Domain A Server Domain B <script> JSON + callback
  • 11. Using JSON-P in OO web apps Problem : callback function has to be global Complex code maintains state / instances Would like to handle callback with instance function on instantiated object Solution : bind the callback dynamically Create a globally-unique function name Usually global prefix + auto-incremented counter Use a closure to call your function in object-scope Send the global function name as callback  it calls your scoped function
  • 12. Dynamically binding a global callback var cbName = 'cb' + JSON.callbackCounter++; var cbFunc = function(jsonData) { myFunc .call( myObj , jsonData); // call bound callback }; JSON.callbacks[cbName] = cbFunc; var globalCallbackName = ‘JSON.callbacks.’ + cbName // url: '/json-api.js?callback=' + globalCallbackName; Used by dojo (ScriptSrcIO), Google Maps 2.5, Plaxo, etc.
  • 13. Summary of cross-site techniques so far No cross-site communication Include partner’s JS file once (can’t talk again) Server-side proxy Talk on the backend (bottleneck, barrier to adoption) Flash proxy Talk through cross-domain flash (requires flash) JSON-P Talk through script-injection with callback (less control, partner could be malicious)
  • 14. What about updating another web page? Proxies / JSON-P let you access foreign data But still can’t touch a foreign frame/iframe/popup Many potential mashups would like to interact with existing web pages Auto-fill a form with your contact info Highlight relevant search results / text snippets How can two sites that want to cooperate get around the same-origin policy?
  • 15.  
  • 16. What does the partner site have to do? Add the button to your page <a onclick=&quot; showPlaxoABChooser('textarea', '/cb.html') ; return false&quot; href=&quot;#&quot;> <img src=&quot;http://www.plaxo.com/images/abc/buttons /add_button.gif&quot; alt=&quot;Add from my address book&quot; /></a> Specify the ID of your e-mail <textarea> Specify the location of your hidden callback page Add a small callback page on your site <html><head><script type=&quot;text/javascript&quot; src=&quot;https://www.plaxo.com/ab_chooser/abc_comm.jsdyn&quot;> </script></head><body></body></html> Full instructions and demo: http:// www.plaxo.com/api
  • 17. What does Plaxo have to do? Remember: Plaxo filled in a textarea on zazzle! Need to get around same-origin policy Without server-side proxy (JS/HTML only) JSON-P won’t solve this problem Widget popup is hosted by Plaxo and goes thru several steps Zazzle doesn’t know when to request the contact data Solution: “The JavaScript Wormhole” Add hidden callback page on zazzle that includes Plaxo script Plaxo popup loads callback in an iframe when done Script is dynamically generated, and includes selected data IFrame is also on zazzle (and has the data), so it can tell parent.opener to fill in the textfield
  • 18. zazzle.com/email_this plaxo.com/ab_chooser plaxo.com/ab_chooser Iframe: zazzle.com/cb.html  Script: plaxo.com/ab_chooser/abc_comm.jsdyn
  • 19. Who’s using the Plaxo widget? See more at http://www.plaxo.com/api/gallery Using the widget? Let us know!
  • 20. Generalizing the JavaScript Wormhole Site has a generic callback page to give you access Site tells you the location of their callback page Callback page loads your domain’s JavaScript JavaScript is dynamically generated to include your data Can pass script url with query args to callback page /cb.html? http://foreign-site.com/json-api.js?name=val Access query string on cb page with location.search Site can restrict callback page to trusted hosts Only load script if it’s on a trusted domain Could further restrict to certain URL prefixes, etc.
  • 21. <html><head><title>Generalized JavaScript Wormhole</title> <script type=&quot;text/javascript&quot;> var trustedDomains = [ &quot;http://www.plaxo.com/api/&quot;, &quot;http://www.google.com/&quot; ]; function isTrustedDomain(url) { for (var i = 0; i < trustedDomains.length; i++) if (url.indexOf(trustedDomains[i]) == 0) return true; return false; } function doWormhole() { var url = location.search.substr(1); // chop off ? if (isTrustedDomain(url)) { var script = document.createElement('script'); script.type = &quot;text/javascript&quot;; script.src = url; document.getElementsByTagName(&quot;head&quot;)[0].appendChild(script); } else alert(&quot;ignoring untrusted url: &quot; + url); } </script></head><body onload=&quot;doWormhole()&quot;></body></html>
  • 22. Where do we go from here? Ajax is a “hack” on top of an old platform The platform can evolve
  • 23. Where do we go from here? Ajax is a “hack” on top of an old platform The platform is evolving
  • 24. Where do we go from here? Ajax is a “hack” on top of an old platform The platform is evolving What platform do we want to build?
  • 25. Should we open cross-domain XHR? After all, we can already include foreign JavaScript, image, and CSS files So why not XML too? (“just another resource file”) HTML looks like XML (esp. XHTML) Hard to make sure you really meant to serve that page as XML data (cf. js / img / css) Personal / private info more often in XML / HTML But increasingly a problem with JS too (JSON) Cookies / creds sent with XHR request Can’t easily distinguish direct vs. XHR access
  • 26. Trust relationships between sites Random site accessing this file vs. trusted partner Flash does this with crossdomain.xml Web services do this with certs / IP whitelists JavaScript wormhole does it (sort of) Should a trust relationship exist for mashups? Want to minimize barriers to adoption / innovation When sharing user info, should have prior agreement? How formal / technical should this trust be?
  • 27. Restricting access to unauthorized info Restrict XHR to same “internet zone” So public site can’t access intranet page Don’t send any cookies / credentials via XHR Practically restricts cross-site comm. to fully public info Could still send auth info on URL But now other site has it Give other site limited-access token? White-list authorized sites with cross-domain file Return special response headers for public pages Legacy problem for existing content
  • 28. Proposals for better cross-site tools ContextAgnosticXmlHttpRequest (Chris Holland) Alternative to normal XmlHttpRequest for cross-site Don’t send/receive any cookie or HTTP auth info Server must specify X-Allow-Foreign-Hosts in response JSONRequest (Douglas Crockford) New browser object for cross-site JSON (like XHR) Allows GET / POST / cancel of JSON request / response No cookies / auth info sent or received Requires special headers in request / response
  • 29. In conclusion… Cross-site communication is tricky but important Key enabling technology for building rich mashups Raises legitimate security issues that can’t be ignored Today: Use server-side proxy or JSON-P Proxy introduces bottleneck, but provides full access JSON-P is more scalable, but limited to JSON APIs JavaScript Wormhole lets you touch foreign pages Keep the discussion of better tools / protocols going! This problem is here to stay Browser developers are listening!
  • 30. For further reading… Cross-site limitations http://getahead.ltd.uk/ajax/cross-domain-xhr http:// msdn.microsoft.com/library/default.asp?url =/workshop/author/ om/xframe_scripting_security.asp FlashXMLHttpRequest http:// blog.monstuff.com/FlashXMLHttpRequest ContextAgnosticXMLHttpRequest http://chrisholland.blogspot.com/2005/03/contextagnosticxmlhttprequest-informal.html JSONRequest http:// json.org/JSONRequest.html