当前位置:   article > 正文

SpringCloud微服务实战——搭建企业级开发框架:微服务安全加固—自定义Gateway拦截器实现防止SQL注入/XSS攻击_gateway拦截器配置

gateway拦截器配置

SQL注入是常见的系统安全问题之一,用户通过特定方式向系统发送SQL脚本,可直接自定义操作系统数据库,如果系统没有对SQL注入进行拦截,那么用户甚至可以直接对数据库进行增删改查等操作。

  XSS全称为Cross Site Script跨站点脚本攻击,和SQL注入类似,都是通过特定方式向系统发送攻击脚本,对系统进行控制和侵害。SQL注入主要以攻击数据库来达到攻击系统的目的,而XSS则是以恶意执行前端脚本来攻击系统。

  项目框架中使用mybatis/mybatis-plus数据持久层框架,在使用过程中,已有规避SQL注入的规则和使用方法。但是在实际开发过程中,由于各种原因,开发人员对持久层框架的掌握水平不同,有些特殊业务情况必须从前台传入SQL脚本。这时就需要对系统进行加固,防止特殊情况下引起的系统风险。

  在微服务架构下,我们考虑如何实现SQL注入/XSS攻击拦截时,肯定不会在每个微服务都实现一遍SQL注入/XSS攻击拦截。根据我们微服务系统的设计,所有的请求都会经过Gateway网关,所以在实现时就可以参照前面的日志拦截器来实现。在接收到一个请求时,通过拦截器解析请求参数,判断是否有SQL注入/XSS攻击参数,如果有,那么返回异常即可。

  我们前面在对微服务Gateway进行自定义扩展时,增加了Gateway插件功能。我们会根据系统需求开发各种Gateway功能扩展插件,并且可以根据系统配置文件来启用/禁用这些插件。下面我们就将防止SQL注入/XSS攻击拦截器作为一个Gateway插件来开发和配置。

1、新增SqlInjectionFilter 过滤器和XssInjectionFilter过滤器,分别用于解析请求参数并对参数进行判断是否存在SQL注入/XSS攻脚本。此处有公共判断方法,通过配置文件来读取请求的过滤配置,因为不是多有的请求都会引发SQL注入和XSS攻击,如果无差别的全部拦截和请求,那么势必影响到系统的性能。
  • 判断SQL注入的拦截器
  1. /**
  2. * 防sql注入
  3. * @author GitEgg
  4. */
  5. @Log4j2
  6. @AllArgsConstructor
  7. public class SqlInjectionFilter implements GlobalFilter, Ordered {
  8. ......
  9. // 当返回参数为true时,解析请求参数和返回参数
  10. if (shouldSqlInjection(exchange))
  11. {
  12. MultiValueMap<String, String> queryParams = request.getQueryParams();
  13. boolean chkRetGetParams = SqlInjectionRuleUtils.mapRequestSqlKeyWordsCheck(queryParams);
  14. boolean chkRetJson = false;
  15. boolean chkRetFormData = false;
  16. HttpHeaders headers = request.getHeaders();
  17. MediaType contentType = headers.getContentType();
  18. long length = headers.getContentLength();
  19. if(length > 0 && null != contentType && (contentType.includes(MediaType.APPLICATION_JSON)
  20. ||contentType.includes(MediaType.APPLICATION_JSON_UTF8))){
  21. chkRetJson = SqlInjectionRuleUtils.jsonRequestSqlKeyWordsCheck(gatewayContext.getRequestBody());
  22. }
  23. if(length > 0 && null != contentType && contentType.includes(MediaType.APPLICATION_FORM_URLENCODED)){
  24. log.debug("[RequestLogFilter](Request)FormData:{}",gatewayContext.getFormData());
  25. chkRetFormData = SqlInjectionRuleUtils.mapRequestSqlKeyWordsCheck(gatewayContext.getFormData());
  26. }
  27. if (chkRetGetParams || chkRetJson || chkRetFormData)
  28. {
  29. return WebfluxResponseUtils.responseWrite(exchange, "参数中不允许存在sql关键字");
  30. }
  31. return chain.filter(exchange);
  32. }
  33. else {
  34. return chain.filter(exchange);
  35. }
  36. }
  37. ......
  38. }
  • 判断XSS攻击的拦截器
  1. /**
  2. * 防xss注入
  3. * @author GitEgg
  4. */
  5. @Log4j2
  6. @AllArgsConstructor
  7. public class XssInjectionFilter implements GlobalFilter, Ordered {
  8. ......
  9. // 当返回参数为true时,记录请求参数和返回参数
  10. if (shouldXssInjection(exchange))
  11. {
  12. MultiValueMap<String, String> queryParams = request.getQueryParams();
  13. boolean chkRetGetParams = XssInjectionRuleUtils.mapRequestSqlKeyWordsCheck(queryParams);
  14. boolean chkRetJson = false;
  15. boolean chkRetFormData = false;
  16. HttpHeaders headers = request.getHeaders();
  17. MediaType contentType = headers.getContentType();
  18. long length = headers.getContentLength();
  19. if(length > 0 && null != contentType && (contentType.includes(MediaType.APPLICATION_JSON)
  20. ||contentType.includes(MediaType.APPLICATION_JSON_UTF8))){
  21. chkRetJson = XssInjectionRuleUtils.jsonRequestSqlKeyWordsCheck(gatewayContext.getRequestBody());
  22. }
  23. if(length > 0 && null != contentType && contentType.includes(MediaType.APPLICATION_FORM_URLENCODED)){
  24. log.debug("[RequestLogFilter](Request)FormData:{}",gatewayContext.getFormData());
  25. chkRetFormData = XssInjectionRuleUtils.mapRequestSqlKeyWordsCheck(gatewayContext.getFormData());
  26. }
  27. if (chkRetGetParams || chkRetJson || chkRetFormData)
  28. {
  29. return WebfluxResponseUtils.responseWrite(exchange, "参数中不允许存在XSS注入关键字");
  30. }
  31. return chain.filter(exchange);
  32. }
  33. else {
  34. return chain.filter(exchange);
  35. }
  36. }
  37. ......
  38. }
2、新增SqlInjectionRuleUtils工具类和XssInjectionRuleUtils工具类,通过正则表达式,用于判断参数是否属于SQL注入/XSS攻击脚本。
  • 通过正则表达式对参数进行是否有SQL注入风险的判断
  1. /**
  2. * 防sql注入工具类
  3. * @author GitEgg
  4. */
  5. @Slf4j
  6. public class SqlInjectionRuleUtils {
  7. /**
  8. * SQL的正则表达式
  9. */
  10. private static String badStrReg = "\\b(and|or)\\b.{1,6}?(=|>|<|\\bin\\b|\\blike\\b)|\\/\\*.+?\\*\\/|<\\s*script\\b|\\bEXEC\\b|UNION.+?SELECT|UPDATE.+?SET|INSERT\\s+INTO.+?VALUES|(SELECT|DELETE).+?FROM|(CREATE|ALTER|DROP|TRUNCATE)\\s+(TABLE|DATABASE)";
  11. /**
  12. * SQL的正则表达式
  13. */
  14. private static Pattern sqlPattern = Pattern.compile(badStrReg, Pattern.CASE_INSENSITIVE);
  15. /**
  16. * sql注入校验 map
  17. *
  18. * @param map
  19. * @return
  20. */
  21. public static boolean mapRequestSqlKeyWordsCheck(MultiValueMap<String, String> map) {
  22. //对post请求参数值进行sql注入检验
  23. return map.entrySet().stream().parallel().anyMatch(entry -> {
  24. //这里需要将参数转换为小写来处理
  25. String lowerValue = Optional.ofNullable(entry.getValue())
  26. .map(Object::toString)
  27. .map(String::toLowerCase)
  28. .orElse("");
  29. if (sqlPattern.matcher(lowerValue).find()) {
  30. log.error("参数[{}]中包含不允许sql的关键词", lowerValue);
  31. return true;
  32. }
  33. return false;
  34. });
  35. }
  36. /**
  37. * sql注入校验 json
  38. *
  39. * @param value
  40. * @return
  41. */
  42. public static boolean jsonRequestSqlKeyWordsCheck(String value) {
  43. if (JSONUtil.isJsonObj(value)) {
  44. JSONObject json = JSONUtil.parseObj(value);
  45. Map<String, Object> map = json;
  46. //对post请求参数值进行sql注入检验
  47. return map.entrySet().stream().parallel().anyMatch(entry -> {
  48. //这里需要将参数转换为小写来处理
  49. String lowerValue = Optional.ofNullable(entry.getValue())
  50. .map(Object::toString)
  51. .map(String::toLowerCase)
  52. .orElse("");
  53. if (sqlPattern.matcher(lowerValue).find()) {
  54. log.error("参数[{}]中包含不允许sql的关键词", lowerValue);
  55. return true;
  56. }
  57. return false;
  58. });
  59. } else {
  60. JSONArray json = JSONUtil.parseArray(value);
  61. List<Object> list = json;
  62. //对post请求参数值进行sql注入检验
  63. return list.stream().parallel().anyMatch(obj -> {
  64. //这里需要将参数转换为小写来处理
  65. String lowerValue = Optional.ofNullable(obj)
  66. .map(Object::toString)
  67. .map(String::toLowerCase)
  68. .orElse("");
  69. if (sqlPattern.matcher(lowerValue).find()) {
  70. log.error("参数[{}]中包含不允许sql的关键词", lowerValue);
  71. return true;
  72. }
  73. return false;
  74. });
  75. }
  76. }
  77. }
  • 通过正则表达式对参数进行是否有XSS攻击风险的判断
  1. /**
  2. * XSS注入过滤工具类
  3. * @author GitEgg
  4. */
  5. public class XssInjectionRuleUtils {
  6. private static final Pattern[] PATTERNS = {
  7. // Avoid anything in a <script> type of expression
  8. Pattern.compile("<script>(.*?)</script>", Pattern.CASE_INSENSITIVE),
  9. // Avoid anything in a src='...' type of expression
  10. Pattern.compile("src[\r\n]*=[\r\n]*\\\'(.*?)\\\'", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL),
  11. Pattern.compile("src[\r\n]*=[\r\n]*\\\"(.*?)\\\"", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL),
  12. // Remove any lonesome </script> tag
  13. Pattern.compile("</script>", Pattern.CASE_INSENSITIVE),
  14. // Avoid anything in a <iframe> type of expression
  15. Pattern.compile("<iframe>(.*?)</iframe>", Pattern.CASE_INSENSITIVE),
  16. // Remove any lonesome <script ...> tag
  17. Pattern.compile("<script(.*?)>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL),
  18. // Remove any lonesome <img ...> tag
  19. Pattern.compile("<img(.*?)>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL),
  20. // Avoid eval(...) expressions
  21. Pattern.compile("eval\\((.*?)\\)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL),
  22. // Avoid expression(...) expressions
  23. Pattern.compile("expression\\((.*?)\\)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL),
  24. // Avoid javascript:... expressions
  25. Pattern.compile("javascript:", Pattern.CASE_INSENSITIVE),
  26. // Avoid vbscript:... expressions
  27. Pattern.compile("vbscript:", Pattern.CASE_INSENSITIVE),
  28. // Avoid onload= expressions
  29. Pattern.compile("on(load|error|mouseover|submit|reset|focus|click)(.*?)=", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL)
  30. };
  31. public static String stripXSS(String value) {
  32. if (StringUtils.isEmpty(value)) {
  33. return value;
  34. }
  35. for (Pattern scriptPattern : PATTERNS) {
  36. value = scriptPattern.matcher(value).replaceAll("");
  37. }
  38. return value;
  39. }
  40. public static boolean hasStripXSS(String value) {
  41. if (!StringUtils.isEmpty(value)) {
  42. for (Pattern scriptPattern : PATTERNS) {
  43. if (scriptPattern.matcher(value).find() == true)
  44. {
  45. return true;
  46. }
  47. }
  48. }
  49. return false;
  50. }
  51. /**
  52. * xss注入校验 map
  53. *
  54. * @param map
  55. * @return
  56. */
  57. public static boolean mapRequestSqlKeyWordsCheck(MultiValueMap<String, String> map) {
  58. //对post请求参数值进行sql注入检验
  59. return map.entrySet().stream().parallel().anyMatch(entry -> {
  60. //这里需要将参数转换为小写来处理
  61. String lowerValue = Optional.ofNullable(entry.getValue())
  62. .map(Object::toString)
  63. .map(String::toLowerCase)
  64. .orElse("");
  65. if (hasStripXSS(lowerValue)) {
  66. return true;
  67. }
  68. return false;
  69. });
  70. }
  71. /**
  72. * xss注入校验 json
  73. *
  74. * @param value
  75. * @return
  76. */
  77. public static boolean jsonRequestSqlKeyWordsCheck(String value) {
  78. if (JSONUtil.isJsonObj(value)) {
  79. JSONObject json = JSONUtil.parseObj(value);
  80. Map<String, Object> map = json;
  81. //对post请求参数值进行sql注入检验
  82. return map.entrySet().stream().parallel().anyMatch(entry -> {
  83. //这里需要将参数转换为小写来处理
  84. String lowerValue = Optional.ofNullable(entry.getValue())
  85. .map(Object::toString)
  86. .map(String::toLowerCase)
  87. .orElse("");
  88. if (hasStripXSS(lowerValue)) {
  89. return true;
  90. }
  91. return false;
  92. });
  93. } else {
  94. JSONArray json = JSONUtil.parseArray(value);
  95. List<Object> list = json;
  96. //对post请求参数值进行sql注入检验
  97. return list.stream().parallel().anyMatch(obj -> {
  98. //这里需要将参数转换为小写来处理
  99. String lowerValue = Optional.ofNullable(obj)
  100. .map(Object::toString)
  101. .map(String::toLowerCase)
  102. .orElse("");
  103. if (hasStripXSS(lowerValue)) {
  104. return true;
  105. }
  106. return false;
  107. });
  108. }
  109. }
  110. }
3、在GatewayRequestContextFilter 中新增判断那些请求需要解析参数。因为出于性能等方面的考虑,网关并不是对所有的参数都进行解析,只有在需要记录日志、防止SQL注入/XSS攻击时才会进行解析。
  1. /**
  2. * check should read request data whether or not
  3. * @return boolean
  4. */
  5. private boolean shouldReadRequestData(ServerWebExchange exchange){
  6. if(gatewayPluginProperties.getLogRequest().getRequestLog()
  7. && GatewayLogTypeEnum.ALL.getType().equals(gatewayPluginProperties.getLogRequest().getLogType())){
  8. log.debug("[GatewayContext]Properties Set Read All Request Data");
  9. return true;
  10. }
  11. boolean serviceFlag = false;
  12. boolean pathFlag = false;
  13. boolean lbFlag = false;
  14. List<String> readRequestDataServiceIdList = gatewayPluginProperties.getLogRequest().getServiceIdList();
  15. List<String> readRequestDataPathList = gatewayPluginProperties.getLogRequest().getPathList();
  16. if(!CollectionUtils.isEmpty(readRequestDataPathList)
  17. && (GatewayLogTypeEnum.PATH.getType().equals(gatewayPluginProperties.getLogRequest().getLogType())
  18. || GatewayLogTypeEnum.CONFIGURE.getType().equals(gatewayPluginProperties.getLogRequest().getLogType()))){
  19. String requestPath = exchange.getRequest().getPath().pathWithinApplication().value();
  20. for(String path : readRequestDataPathList){
  21. if(ANT_PATH_MATCHER.match(path,requestPath)){
  22. log.debug("[GatewayContext]Properties Set Read Specific Request Data With Request Path:{},Math Pattern:{}", requestPath, path);
  23. pathFlag = true;
  24. break;
  25. }
  26. }
  27. }
  28. Route route = exchange.getAttribute(ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR);
  29. URI routeUri = route.getUri();
  30. if(!"lb".equalsIgnoreCase(routeUri.getScheme())){
  31. lbFlag = true;
  32. }
  33. String routeServiceId = routeUri.getHost().toLowerCase();
  34. if(!CollectionUtils.isEmpty(readRequestDataServiceIdList)
  35. && (GatewayLogTypeEnum.SERVICE.getType().equals(gatewayPluginProperties.getLogRequest().getLogType())
  36. || GatewayLogTypeEnum.CONFIGURE.getType().equals(gatewayPluginProperties.getLogRequest().getLogType()))){
  37. if(readRequestDataServiceIdList.contains(routeServiceId)){
  38. log.debug("[GatewayContext]Properties Set Read Specific Request Data With ServiceId:{}",routeServiceId);
  39. serviceFlag = true;
  40. }
  41. }
  42. if (GatewayLogTypeEnum.CONFIGURE.getType().equals(gatewayPluginProperties.getLogRequest().getLogType())
  43. && serviceFlag && pathFlag && !lbFlag)
  44. {
  45. return true;
  46. }
  47. else if (GatewayLogTypeEnum.SERVICE.getType().equals(gatewayPluginProperties.getLogRequest().getLogType())
  48. && serviceFlag && !lbFlag)
  49. {
  50. return true;
  51. }
  52. else if (GatewayLogTypeEnum.PATH.getType().equals(gatewayPluginProperties.getLogRequest().getLogType())
  53. && pathFlag)
  54. {
  55. return true;
  56. }
  57. return false;
  58. }
4、在GatewayPluginProperties中新增配置,用于读取Gateway过滤器的系统配置,判断开启新增的防止SQL注入/XSS攻击插件。
  1. @Slf4j
  2. @Getter
  3. @Setter
  4. @ToString
  5. public class GatewayPluginProperties implements InitializingBean {
  6. public static final String GATEWAY_PLUGIN_PROPERTIES_PREFIX = "spring.cloud.gateway.plugin.config";
  7. public static final String GATEWAY_PLUGIN_PROPERTIES_PREFIX_LOG_REQUEST = GATEWAY_PLUGIN_PROPERTIES_PREFIX + ".logRequest";
  8. public static final String GATEWAY_PLUGIN_PROPERTIES_PREFIX_SQL_INJECTION = GATEWAY_PLUGIN_PROPERTIES_PREFIX + ".sqlInjection";
  9. public static final String GATEWAY_PLUGIN_PROPERTIES_PREFIX_XSS_INJECTION = GATEWAY_PLUGIN_PROPERTIES_PREFIX + ".xssInjection";
  10. /**
  11. * Enable Or Disable
  12. */
  13. private Boolean enable = false;
  14. /**
  15. * LogProperties
  16. */
  17. private LogProperties logRequest;
  18. /**
  19. * SqlInjectionProperties
  20. */
  21. private SqlInjectionProperties sqlInjection;
  22. /**
  23. * XssInjectionProperties
  24. */
  25. private XssInjectionProperties xssInjection;
  26. @Override
  27. public void afterPropertiesSet() {
  28. log.info("Gateway plugin logRequest enable:", logRequest.enable);
  29. log.info("Gateway plugin sqlInjection enable:", sqlInjection.enable);
  30. log.info("Gateway plugin xssInjection enable:", xssInjection.enable);
  31. }
  32. /**
  33. * 日志记录相关配置
  34. */
  35. @Getter
  36. @Setter
  37. @ToString
  38. public static class LogProperties implements InitializingBean{
  39. /**
  40. * Enable Or Disable Log Request Detail
  41. */
  42. private Boolean enable = false;
  43. /**
  44. * Enable Or Disable Read Request Data
  45. */
  46. private Boolean requestLog = false;
  47. /**
  48. * Enable Or Disable Read Response Data
  49. */
  50. private Boolean responseLog = false;
  51. /**
  52. * logType
  53. * all: 所有日志
  54. * configure:serviceId和pathList交集
  55. * serviceId: 只记录serviceId配置列表
  56. * pathList:只记录pathList配置列表
  57. */
  58. private String logType = "all";
  59. /**
  60. * Enable Read Request Data When use discover route by serviceId
  61. */
  62. private List<String> serviceIdList = Collections.emptyList();
  63. /**
  64. * Enable Read Request Data by specific path
  65. */
  66. private List<String> pathList = Collections.emptyList();
  67. @Override
  68. public void afterPropertiesSet() throws Exception {
  69. if(!CollectionUtils.isEmpty(serviceIdList)){
  70. serviceIdList = serviceIdList.stream().map(String::toLowerCase).collect(Collectors.toList());
  71. }
  72. if(!CollectionUtils.isEmpty(pathList)){
  73. pathList = pathList.stream().map(String::toLowerCase).collect(Collectors.toList());
  74. }
  75. }
  76. }
  77. /**
  78. * sql注入拦截相关配置
  79. */
  80. @Getter
  81. @Setter
  82. @ToString
  83. public static class SqlInjectionProperties implements InitializingBean{
  84. /**
  85. * Enable Or Disable
  86. */
  87. private Boolean enable = false;
  88. /**
  89. * Enable Read Request Data When use discover route by serviceId
  90. */
  91. private List<String> serviceIdList = Collections.emptyList();
  92. /**
  93. * Enable Read Request Data by specific path
  94. */
  95. private List<String> pathList = Collections.emptyList();
  96. @Override
  97. public void afterPropertiesSet() {
  98. if(!CollectionUtils.isEmpty(serviceIdList)){
  99. serviceIdList = serviceIdList.stream().map(String::toLowerCase).collect(Collectors.toList());
  100. }
  101. if(!CollectionUtils.isEmpty(pathList)){
  102. pathList = pathList.stream().map(String::toLowerCase).collect(Collectors.toList());
  103. }
  104. }
  105. }
  106. /**
  107. * xss注入拦截相关配置
  108. */
  109. @Getter
  110. @Setter
  111. @ToString
  112. public static class XssInjectionProperties implements InitializingBean{
  113. /**
  114. * Enable Or Disable
  115. */
  116. private Boolean enable = false;
  117. /**
  118. * Enable Read Request Data When use discover route by serviceId
  119. */
  120. private List<String> serviceIdList = Collections.emptyList();
  121. /**
  122. * Enable Read Request Data by specific path
  123. */
  124. private List<String> pathList = Collections.emptyList();
  125. @Override
  126. public void afterPropertiesSet() {
  127. if(!CollectionUtils.isEmpty(serviceIdList)){
  128. serviceIdList = serviceIdList.stream().map(String::toLowerCase).collect(Collectors.toList());
  129. }
  130. if(!CollectionUtils.isEmpty(pathList)){
  131. pathList = pathList.stream().map(String::toLowerCase).collect(Collectors.toList());
  132. }
  133. }
  134. }
  135. }

5、GatewayPluginConfig 配置过滤器在启动时动态判断是否启用某些Gateway插件。在这里我们将新增的SQL注入拦截插件和XSS攻击拦截插件配置进来,可以根据配置文件动态判断是否启用SQL注入拦截插件和XSS攻击拦截插件。

  1. @Slf4j
  2. @Configuration
  3. @ConditionalOnProperty(prefix = GatewayPluginProperties.GATEWAY_PLUGIN_PROPERTIES_PREFIX, value = { "enable"}, havingValue = "true")
  4. public class GatewayPluginConfig {
  5. /**
  6. * Gateway插件是否生效
  7. * @return
  8. */
  9. @Bean
  10. @ConditionalOnMissingBean(GatewayPluginProperties.class)
  11. @ConfigurationProperties(GatewayPluginProperties.GATEWAY_PLUGIN_PROPERTIES_PREFIX)
  12. public GatewayPluginProperties gatewayPluginProperties(){
  13. return new GatewayPluginProperties();
  14. }
  15. ......
  16. /**
  17. * sql注入拦截插件
  18. * @return
  19. */
  20. @Bean
  21. @ConditionalOnMissingBean(SqlInjectionFilter.class)
  22. @ConditionalOnProperty(prefix = GatewayPluginProperties.GATEWAY_PLUGIN_PROPERTIES_PREFIX, value = { "sqlInjection.enable" },havingValue = "true")
  23. public SqlInjectionFilter sqlInjectionFilter(@Autowired GatewayPluginProperties gatewayPluginProperties){
  24. SqlInjectionFilter sqlInjectionFilter = new SqlInjectionFilter(gatewayPluginProperties);
  25. log.debug("Load SQL Injection Filter Config Bean");
  26. return sqlInjectionFilter;
  27. }
  28. /**
  29. * xss注入拦截插件
  30. * @return
  31. */
  32. @Bean
  33. @ConditionalOnMissingBean(XssInjectionFilter.class)
  34. @ConditionalOnProperty(prefix = GatewayPluginProperties.GATEWAY_PLUGIN_PROPERTIES_PREFIX, value = { "xssInjection.enable" },havingValue = "true")
  35. public XssInjectionFilter xssInjectionFilter(@Autowired GatewayPluginProperties gatewayPluginProperties){
  36. XssInjectionFilter xssInjectionFilter = new XssInjectionFilter(gatewayPluginProperties);
  37. log.debug("Load XSS Injection Filter Config Bean");
  38. return xssInjectionFilter;
  39. }
  40. ......
  41. }

  在日常开发过程中很多业务需求都不会从前端传入SQL脚本和XSS脚本,所以很多的开发框架都不去识别前端参数是否有安全风险,然后直接禁止掉所有前端传入的的脚本,这样就强制规避了SQL注入和XSS攻击的风险。但是在某些特殊业务情况下,尤其是传统行业系统,需要通过前端配置执行脚本,然后由业务系统去执行这些配置的脚本,这个时候就需要通过配置来进行识别和判断,然后对容易引起安全性风险的脚本进转换和配置,在保证业务正常运行的情况下完成脚本配置。

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号