# xss-checker

> This package tries to prevent cross-site scripting (XSS) by checking user input for malicious javascript!

Latest version **1.0.1** (published 2020-07-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install xss-checker
pnpm add xss-checker
yarn add xss-checker
bun add xss-checker
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2020-07-02 |
| First published | 2020-07-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 454.3 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Fabio Keller |
| Maintainers | leadingweb |
| Keywords | cross-site, scripting, XSS, xss-checker, input, validation, xss, check |

## Links

- npm: https://www.npmjs.com/package/xss-checker
- Repository: https://github.com/LeadingWeb/xss-checker
- Homepage: https://github.com/LeadingWeb/xss-checker#readme
- Issues: https://github.com/LeadingWeb/xss-checker/issues
- npm.io page: https://npm.io/package/xss-checker

## Dependencies (1)

- [fs](https://npm.io/package/fs.md) 0.0.1-security

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2020-07-02
- 1.0.0 — 2020-07-02

## README

# What is this?

This package is a simple way to check if a string contains any HTML or JavaScrpipt so your database stays clean.

# Installation

There are two main ways you can use this, either with nodejs on the backend or you could use it on the front end as well.

For nodejs, just install the npm package:

`npm i xss-checker`


To use it on your front-end you can just copy the 'front-xss-checker' folder into your project and link to it as a script tag:

`<script src="./front-xss-checker/validate.js"></script>`


# Usage

After importing, you can just check any string for XSS attempts by using the function (front-end):
`validateXSS("Your input string");`

(nodejs) 
`xss.validate('Your input string');`


This function returns the matches against a current XSS-Payload list, so if it returns 0 the input is probably safe.


# NPM Example

```
const Xss = require('./index');
const xss = new Xss;

//The user input you want to check
const input = "<svg onload=alert(1)>";

xss.init()
    .then(() => {
        if(xss.validate(input) === 0) {
            //The input is clean and can be added to the database
        }else {
            //The input contains malicious Javascript
            console.log(input);
        }
    })

```



# Front-End Example

Don't forget to add the script tag to your HTML:
`validateXSS("Your input string");`


```

//The user input you want to check
const input = "<svg onload=alert(1)>";

const check = validateXSS(input);
if (check == 0) {

    //check == 0 means the input is safe, so you can add send it to the server

} else {
    console.log(`XSS! ${{check}});
}

```

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