# winchan

> 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

Latest version **0.2.2** (published 2019-06-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install winchan
pnpm add winchan
yarn add winchan
bun add winchan
```

## Health

**Score 18/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2019-06-17 |
| First published | 2014-06-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/winchan) |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 595.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Maintainers | auth0npm, cristiandouce, luisrudge, pose |

## Links

- npm: https://www.npmjs.com/package/winchan
- Repository: https://github.com/auth0/winchan
- Homepage: https://github.com/auth0/winchan#readme
- Issues: https://github.com/auth0/winchan/issues
- npm.io page: https://npm.io/package/winchan

## Recent versions

- 0.2.2 (latest) — 2019-06-17
- 0.2.1 — 2018-09-26
- 0.2.0 — 2017-01-03
- 0.1.4 — 2016-10-12
- 0.1.3 — 2016-09-26
- 0.1.2 — 2015-10-25
- 0.1.1 — 2015-01-26
- 0.1.0 — 2015-01-19
- 0.0.6 — 2014-07-07
- 0.0.5 — 2014-07-04
- 0.0.4 — 2014-06-30
- 0.0.3 — 2014-06-17
- 0.0.2 — 2014-06-17

## README

## 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][].

  [BrowserID]: https://browserid.org

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:

    $ npm i
    $ 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

    $ npm i
    $ 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:

    $ npm i
    $ 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`

---
_Source: https://npm.io/package/winchan · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
