| By Douglas Crockford | Article Rating: |
|
| June 4, 2008 10:15 PM EDT | Reads: |
5,131 |
Yahoo! User Interface BlogCooperating applications, such as mashups, must be able to exchange objects with robust interfaces. An object must be able to encapsulate its state such that the state can be modified only as permitted by its own methods. JavaScript’s objects are soft and currently the language does not include any means to harden them, so an attacker can easily access the fields directly and replace the methods with his own.
Fortunately, JavaScript provides the means to construct durable objects that can perfectly guard their state by using a variation of the Module Pattern. You’ll recall that the Module Pattern makes it possible to make an object with privileged methods. Privileged methods are able to access the private state of the constructor’s closure. By adding one simple rule, we can easily generate secure objects:
A durable object contains no visible data members, and its methods use neitherThis is a template for a durable constructor:thisnorthat.
function durable(parameters) { var that = {} or the product of another durable constructor; var private variables; function method() { … }
that.method = method;return that; } Define all of your methods as private methods. The methods you choose to expose to the public get copied into that. None of the functions defined or inherited make use of
that or this. We can give the object created by the durable constructor to untrusted code. That code will be unable to get direct access to the private state. It can replace the methods with its own methods, but that only reduces the usefulness of the object to the attacker. It does not weaken or confuse the object. Each method is a capability. The object is just a collection of capabilities. Durable objects allow code from multiple (possibly untrusted) parties to cooperate. Durable objects can be expressed in a safe subset of JavaScript, such as ADsafe or Cajita.
[This appeared originally here and is republished by kind permission of the author, who retains copyright.]
Published June 4, 2008 Reads 5,131
Copyright © 2008 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Douglas Crockford
Douglas Crockford, an architect at Yahoo!, is an AJAXWorld regular. A technologist of parts, he has developed office automation systems, done research in games and music at Atari, and been both Director of Technology at Lucasfilm and Director of New Media at Paramount. He was the founder and CEO of Electric Communities/Communities.com and the founder and CTO of State Software, where he discovered JSON. He is interested in Blissymbolics, a graphical, symbolic language, and is developing a secure programming language.
- Open Source Java Guru Moving to Joost
- Ulitzer Live! New Media Power Panel at Santa Clara Convention Center
- Bernanke Should Go Back to Teaching
- New Virus Targets Facebook, MySpace and Twitter Users
- Warner Music Group Appoints Renowned Producer Rob Cavallo as Chief Creative Officer
- ITRI's FleXpeaker, an Innovative, Paper-Thin Speaker Technology, Receives 2009 Wall Street Journal Technology Innovation Award
- Get HD Videos to FLV with Fancy Player for Online Sharing
- Apple Store Upper West Side Opening on Saturday, November 14
- Alfred Poor’s New Video Reviews
- iPhone Tips, Tricks & Apps for Business Executives
- LTE - The Rise of the Mobile Prosumer
- Now that's a Da Vinci!
- Open Source Java Guru Moving to Joost
- Apple Introduces New iPod nano With Built-in Video Camera
- Ulitzer Live! New Media Power Panel at Santa Clara Convention Center
- MTV Video Music Award-Winning Green Day To Host Special Music Countdown on SIRIUS XM Radio
- Apple Approves First Official Porn Star App for iPhone
- Bernanke Should Go Back to Teaching
- Pixamba CEO Launches Stock Photography Topic on Ulitzer
- Turn Your Podcast Into an Interactive Live Streaming Experience
- New Virus Targets Facebook, MySpace and Twitter Users
- Sybase and Verizon Team up to Manage Mobility Solutions For Enterprises Worldwide
- LA Phil Launches Microsite Celebrating Incoming Music Director
- Google Sites Exceed 10 Billion Video Views in August
- Video Conference with Flex & FMS
- The Top 250 Players in the Cloud Computing Ecosystem
- AJAX and Enterprise RIA Tools - JSF, Flex, and JavaFX
- SYS-CON Events Announces iTVcon Internet TV Conference & Expo 2007
- iTVCon - Internet Video Conference & Expo Registrations Now Open
- Internet Video Update: First "Webisode" of Quarterlife Will Air on MySpaceTV
- Microsoft's Flash-Killer Silverlight Streaming Video Plug-in Released
- "TV Anywhere, Anytime" Gets a Boost...From Joost
- Android: Who Hates Google Over the Phone?
- From Enterprise to Cloud, Virtualization Today on SYS-CON.TV
- iTVCon - Starts Next Monday! Check Out the Full Speaker Lineup
- Virtualization: "The Leading Technology of the 21st Century"







































