Safe-url
Returns a safe url of the given string
Motivation
Solves potential XSS vulnerabilities when javascript:
is used as a protocol.
Installation
yarn add @kaliber/safe-url
Usage
This function should be used when you want to navigate a user to a other url especially when you take the value form the url. A use case would be to check a returnUrl.
Basic usage
import { safeUrl } from '@kaliber/safe-url'
const { returnUrl } = req.query
window.location.href = safeUrl(returnUrl)
window.location.href = safeUrl(returnUrl)
allowedHostsList
import { safeUrl } from '@kaliber/safe-url'
safeUrl('https://npm.com/', { allowedHostsList: ['kaliber.net'] })
safeUrl('https://kaliber.net/', { allowedHostsList: ['kaliber.net'] })
Disclaimer
This library is intended for internal use, we provide no support, use at your own risk. It does not import React, but expects it to be provided, which @kaliber/build can handle for you.
This library is not transpiled.