Giter Site home page Giter Site logo

mozilla-github-standards / d89ede2460318719523cd3bdcbe26b12ee5db8e10b141de504807ad7e612d5a1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mozilla/winchan

0.0 0.0 0.0 164 KB

A library for opening browser windows that take parameters and load content cross domain.

HTML 12.25% JavaScript 81.14% Shell 0.12% CSS 6.49%

d89ede2460318719523cd3bdcbe26b12ee5db8e10b141de504807ad7e612d5a1's Introduction

An abstraction for opening browser windows cross domain

Here's the scenario: You want to build a secure means of some untrusted site opening a window, which loads content at a trusted site. Then you want the untrusted dude to be able to pass in parameters. Then you want the trusted code to do any amount of stuff, and return a response.

This kinda thing is what lots of services on the web do, services like BrowserID.

Trouble is that this is stupidly hard:

  • Mobile Firefox doesn't like it when you open windows with window options
  • IE 8 & 9 don't even allow postMessage between opener and window
  • iOS 5 has some interesting optimizations that can bite you if not careful
  • you should tightly check origins to avoid classes of attacks
  • you probably will have to add stuff in the DOM, you should make sure you can clean this up and avoid introducing fragile code

WinChan is an abstraction to solve these problems and make it easy to open windows which take and return parameters and load content cross domain.

Browser Support

WinChan is expected to work on:

  • winxp - win7 on IE8 and IE9
  • windows, linux, osx - Chrome, Firefox, Opera, and Safari
  • Android's "native" browser - 2.1, 2.2, 2.3.4, 3.2 (and presumably newer)
  • Fennec on Android

Usage

For the site spawning the window, the "untrusted" or "client" code:

WinChan.open({
  url: "http://trusted.host/dialog.html",
  relay_url: "http://trusted.host/relay.html",
  window_features: "menubar=0,location=0,resizable=0,scrollbars=0,status=0,dialog=1,width=700,height=375",
  params: {
    these: "things",
    are: "input parameters"
  }
}, function(err, r) {
  // err is a string on failure, otherwise r is the response object
});

For the site providing the window, the "trusted" code:

WinChan.onOpen(function(origin, args, cb) {
  // origin is the scheme+host+port that cause window invocation,
  // it can be trusted

  // args are the untrusted arguments provided by the calling site

  // and cb you can call within the function, or synchronously later.
  // calling it indicated the window is done and can be closed.
  cb({
    "these things": "are the response"
  });
});

Finally, you'll notice that the trusted code needs to host 'relay.html' somewhere (required for IE support).

Running Examples

there's a little tiny webserver in-tree to let you run the examples. You'll need node.js and npm installed. Once you have these, just:

$ scripts/setup_dev_deps.sh
$ scripts/run_example.js

Now load http://127.0.0.1:8100/example (or the more complicated example which demonstrates navigation away and back in window at http://127.0.0.1:8100/complex_example

Running Unit Tests

node.js and npm are required to run the unit tests. Once installed

$ scripts/setup_dev_deps.sh
$ scripts/run_example.js

And open http://127.0.0.1:8100/test in your favorite web browser.

NOTE: You'll need to disable popup blocking for localhost to run tests!

Testing over the network

the run_example.js script will bind whatever IP is in the IP_ADDRESS env var. So to test over the network:

$ scripts/setup_dev_deps.sh
$ IP_ADDRESS=<my external IP> scripts/run_example.js

(repace <my external IP> with your IP address)

then hit http://<my external IP>:8100/test

LICENSE

Copyright (c) 2012 Lloyd Hilaiel

Permission is hereby granted, free of charge, to any person obtaining a copy 
of this software and associated documentation files (the "Software"), to deal in 
the Software without restriction, including without limitation the rights to use, 
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 
Software, and to permit persons to whom the Software is furnished to do so, 
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all 
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

d89ede2460318719523cd3bdcbe26b12ee5db8e10b141de504807ad7e612d5a1's People

Contributors

fmarier avatar jaredhirsch avatar lloyd avatar mozilla-github-standards avatar ozten avatar seanmonstar avatar zeh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.