# xssfilter-js

> Injection attack filter-to filter sensitive keywords in text or DOM elements to prevent XSS, command injection, and sql injection attacks

Latest version **1.0.1** (published 2021-02-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install xssfilter-js
pnpm add xssfilter-js
yarn add xssfilter-js
bun add xssfilter-js
```

Provides the command `xssfilter-js`.

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2021-02-21 |
| First published | 2021-02-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | szl |
| Maintainers | s21 |
| Keywords | javascript, xss |

## Links

- npm: https://www.npmjs.com/package/xssfilter-js
- Repository: https://github.com/booms21/injectFilter.js
- Homepage: https://github.com/booms21/injectFilter.js#readme
- Issues: https://github.com/booms21/injectFilter.js/issues
- npm.io page: https://npm.io/package/xssfilter-js

## Recent versions

- 1.0.1 (latest) — 2021-02-21
- 1.0.0 — 2021-02-21

## README

# injectFilter.js
注入攻击过滤器(兼容IE)-实现过滤文本或DOM元素中的敏感关键字防止XSS、命令注入、sql注入攻击

大小：4KB

NPM 地址：https://www.npmjs.com/package/xssfilter-js
# Docs文档:
## 安装：
```
npm install xssfilter-js
```
## options 配置项:
```
//创建一个InjectFilter对象，可传入options配置对象
var inf = new InjectFilter(options);


options.tokens = 可添加额外的自定义过滤字符，对象类型键值对
{'需要替换的目标字符':'字符1'} 
key为需要替换的字符，value为想要将目标字符替换成的字符。



options.xss = true; 
默认为true。 需为布尔值，是否启用过滤xss注入


options.command = true;
默认为true。 需为布尔值，是否启用过滤command(命令注入)



options.sql = true;
默认为true。 需为布尔值，是否启用过滤sql注入
注：命令和sql将过滤成对应的‘全角’文本(如ｓｅｌｅｃｔ　、ｄｅｌｅｔｅ　ｆｒｏｍ、ｐｉｎｇ )
```
# Demo：
```
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="injectFilter.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
</head>
<body>
    <div id='aa' onclick="javascript:alert('hello world')">) or 1=1</div>
</body>
<script>
  var inf = new InjectFilter({tokens:{'or':'|||'}});
     $('#aa').html(inf.filter(document.getElementById('aa')))
</script>

</html>
```
ES6:
```
import injectFilter from './injectFilter';
```

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