Socket
Socket
Sign inDemoInstall

xssfilter-js

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    xssfilter-js

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


Version published
Weekly downloads
2
Maintainers
1
Install size
12.8 kB
Created
Weekly downloads
 

Readme

Source

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将过滤成对应的‘全角’文本(如select 、delete from、ping )

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';

Keywords

FAQs

Last updated on 21 Feb 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc