https://github.com/braintree/sanitize-url
https://github.com/braintree/sanitize-url
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/braintree/sanitize-url
- Owner: braintree
- License: mit
- Created: 2017-08-02T15:46:33.000Z (almost 9 years ago)
- Default Branch: main
- Last Pushed: 2024-12-20T20:20:44.000Z (over 1 year ago)
- Last Synced: 2025-04-07T02:04:18.844Z (over 1 year ago)
- Language: TypeScript
- Size: 961 KB
- Stars: 338
- Watchers: 18
- Forks: 39
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# sanitize-url
## Installation
```sh
npm install -S @braintree/sanitize-url
```
## Usage
```js
var sanitizeUrl = require("@braintree/sanitize-url").sanitizeUrl;
sanitizeUrl("https://example.com"); // 'https://example.com'
sanitizeUrl("http://example.com"); // 'http://example.com'
sanitizeUrl("www.example.com"); // 'www.example.com'
sanitizeUrl("mailto:hello@example.com"); // 'mailto:hello@example.com'
sanitizeUrl(
"https://example.com"
); // https://example.com
sanitizeUrl("javascript:alert(document.domain)"); // 'about:blank'
sanitizeUrl("jAvasCrIPT:alert(document.domain)"); // 'about:blank'
sanitizeUrl(decodeURIComponent("JaVaScRiP%0at:alert(document.domain)")); // 'about:blank'
// HTML encoded javascript:alert('XSS')
sanitizeUrl(
"javascript:alert('XSS')"
); // 'about:blank'
```
## Testing
This library uses [Vitest](https://vitest.dev/). All testing dependencies
will be installed upon `npm install` and the test suite can be executed with
`npm test`. Running the test suite will also run lint checks upon exiting.
npm test
To generate a coverage report, use `npm run coverage`.