https://github.com/forthedamn/safe-window-location
location parent(top) window safely in koa
https://github.com/forthedamn/safe-window-location
koa safe safe-location window xss
Last synced: about 1 month ago
JSON representation
location parent(top) window safely in koa
- Host: GitHub
- URL: https://github.com/forthedamn/safe-window-location
- Owner: forthedamn
- License: mit
- Created: 2017-12-25T06:30:36.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-27T06:07:23.000Z (almost 8 years ago)
- Last Synced: 2025-02-19T16:18:32.306Z (over 1 year ago)
- Topics: koa, safe, safe-location, window, xss
- Language: JavaScript
- Homepage:
- Size: 94.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# safe-window-location
[![NPM version][npm-image]][npm-url]
[](https://travis-ci.org/forthedamn/safe-window-location)
[](https://codecov.io/gh/forthedamn/safe-window-location)
[](LICENSE)
[npm-image]: https://img.shields.io/npm/v/safe-window-location.svg?style=flat-square
[npm-url]: https://npmjs.org/package/safe-window-location
> redirect parent(top) window location safely
## Install
```sh
npm install safe-window-location
yarn add safe-window-location
```
## Usage
```
// ./config/default.js
module.exports = {
urlWhiteList: [
/**
* allow the hostname end with 'github.com'
* like 'https://github.com/**'
*/
/github\.com$/
]
}
```
```js
const SafeWindowLocation = require('safe-window-location');
const app = new Koa();
app.use((ctx, next) => {
// set parent window as new location
return SafeWindowLocation(ctx, 'new location', 'parent', 'urlWhiteList');
})
```
param | usage | required | default
--- | --- | ---| ---
ctx | koa context | yes |
location | window location, like https://www.npmjs.com | - | /
target | window target, like window.parent | - | parent
config name | config option name | - | whiteList