XSS repair for the smarty template.
对Smarty模板进行XSS校验修复
安装
npm install smarty-xssrepair
原理
通过配置对应类型(js、event、path、xml、data)的转义插件名称,对Smarty模板进行XSS检验修复。
使用方法
载入模块
var xss = require('smarty-xssrepair');
设置配置参数
var option = {}
escapeMap = {
'js' : 'f_escape_js',
'html' : 'f_escape_xml',
'data' : 'f_escape_data',
'path' : 'f_escape_path',
'event' : 'f_escape_event',
'no_escape' : 'escape:none'
};
option['fileContent'] = '<div class="{#$spUserInfo.userName|f_escape_xml#}">{#$spUserInfo.city|f_escape_xml#}</div>';
option['_check_pattern'] = escapeMap;
option['isXssAutoFixed'] = true;
option['leftDelimiter'] = '{#';
option['rightDelimiter'] = '#}';
option['xssSafeVars'] = ['fis_safe','fis_xss'];
var result = xss.parse(option);
console.log(result['content']);
测试
系统测试
在源码目录执行命令:npm test