解决方案:

增加一个过滤器,当请求头Referer中包含扫描里的http://bogus.referer.hcl.com时,禁止访问

/*******************************************************************************

* @(#)CSRFilter.java 2020/4/7

*

* Copyright 2020 emrubik Group Ltd. All rights reserved.

* EMRubik PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.

*******************************************************************************/

package com.emrubik.emp.uc.portal.common.communicate;

import java.io.IOException;

import javax.servlet.*;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

/**

* @author hongcq

* @version 1.0 $ 2020/4/7 13:03

*/

public class CsrFilter implements Filter {

/**

* log

*/

private Logger log = LoggerFactory.getLogger(CsrFilter.class);

/**

* referer

*/

private String[] verifyReferer = null;

/**

* Called by the web container to indicate to a filter that it is being placed into service.

*

* The servlet container calls the init method exactly once after instantiating the filter. The init

* method must complete successfully before the filter is asked to do any filtering work.

*

* The web container cannot place the filter into service if the init method either

*

*

Throws a ServletException

*

Does not return within a time period defined by the web container

*

*

* @param filterConfig

* filterConfig

*/

@Override

public void init(FilterConfig filterConfig) throws ServletException {

String referer = filterConfig.getInitParameter("referer");

this.verifyReferer = referer.split(",");

}

/**

* The doFilter method of the Filter is called by the container each time a

* request/response pair is passed through the chain due to a client request for a resource at the

* end of the chain. The FilterChain passed in to this method allows the Filter to pass on the

* request and response to the next entity in the chain.

*

* A typical implementation of this method would follow the following pattern:

*

*

Examine the request

*

Optionally wrap the request object with a custom implementation to filter content or headers

* for input filtering

*

Optionally wrap the response object with a custom implementation to filter content or headers

* for output filtering

*

*

*

Either invoke the next entity in the chain using the FilterChain object

* (chain.doFilter()),

*

or not pass on the request/response pair to the next entity in the filter

* chain to block the request processing

*

*

Directly set headers on the response after invocation of the next entity in the filter chain.

*

*

* @param request

* 请求

* @param response

* 响应

* @param chain

* 链

*/

@Override

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)

throws IOException, ServletException {

String referer = ((HttpServletRequest) request).getHeader("Referer");

boolean b = false;

for (String vReferer : verifyReferer) {

if (null == referer || !referer.trim().equalsIgnoreCase(vReferer)) {

b = true;

chain.doFilter(request, response);

break;

}

}

if (!b) {

log.info("疑似遭到CSRF攻击,referer:" + referer);

}

}

/**

* Called by the web container to indicate to a filter that it is being taken out of service.

*

* This method is only called once all threads within the filter's doFilter method have exited or

* after a timeout period has passed. After the web container calls this method, it will not call

* the doFilter method again on this instance of the filter.

*

* This method gives the filter an opportunity to clean up any resources that are being held (for

* example, memory, file handles, threads) and make sure that any persistent state is synchronized

* with the filter's current state in memory.

*/

@Override

public void destroy() {

}

}

CsrFilter

com.emrubik.emp.uc.portal.common.communicate.CsrFilter

referer

http://bogus.referer.hcl.com

CsrFilter

/*

项目web.xml中增加如上配置

来源:oschina

链接:https://my.oschina.net/u/4170983/blog/3225278

java如何解决跨站点请求伪造_AppScan漏洞扫描之-跨站点请求伪造相关推荐

  1. 【安全牛学习笔记】CSRF跨站请求伪造攻击漏洞的原理及解决办法

    CSRF跨站请求伪造攻击漏洞的原理及解决办法 CSRF,夸张请求伪造漏洞 漏洞的原理及修复方法 1.常见的触发场景 2.漏洞原理:浏览器同源策略 3.DEMO 4.漏洞危害 5.如何避免&修复 ...

  2. Java后台解决跨域问题

    Java后台解决跨域问题 参考文章: (1)Java后台解决跨域问题 (2)https://www.cnblogs.com/qinyuanyuan/p/11380379.html 备忘一下.

  3. 前后端分离,解决Spring Cloud GateWay + Nacos使用lb请求报503错误以及403跨域问题

    在使用前后端分离时,前端请求gateway接口,gateway使用lb负载均衡请求目标服务. 如下: spring:cloud:gateway:routes:- id: test-demouri: l ...

  4. Java后端解决前后端跨域的3种方法

    1.在方法上使用@CrocsOrigin注解 2.在配置类包内添加一个返回值为CorsFilter过滤器的配置类 package com.example.springboot.config;impor ...

  5. java api 测试工具_Java 实现在线HTTP接口测试 - HTTP GET/POST模拟请求测试工具

    本站工具,在线HTTP接口测试 - HTTP GET/POST模拟请求测试工具后台所有实现代码.支持的请求协议有:Post.GetDelete.Put.Trace.Head.Options.特色是加了 ...

  6. CORS 请求未能成功_当遇到跨域开发时, 我们如何处理好前后端配置和请求库封装(koa/axios版)...

    我们知道很多大型项目都或多或少的采用跨域的模式开发, 以达到服务和资源的解耦和高效利用. 在大前端盛行的今天更为如此, 前端工程师可以通过nodejs或者Nginx轻松搭建起web服务器.这个时候我们 ...

  7. http :请求响应报文-web服务-ajax-cors跨域

    node:http 协议:请求响应报文-web服务-url与对象的转化-ajax-cors跨域 1 梳理重点 1.1搭建服务 注意: ① 站点创建完成后,需要通过node命令启动 ② 创建站点的代码如 ...

  8. 【burpsuite安全练兵场-服务端9】服务端请求伪造SSRF漏洞-7个实验(全)

    前言: 介绍: 博主:网络安全领域狂热爱好者(承诺在CSDN永久无偿分享文章). 殊荣:CSDN网络安全领域优质创作者,2022年双十一业务安全保卫战-某厂第一名,某厂特邀数字业务安全研究员,edus ...

  9. corspost请求失败_vue项目CORS跨域请求500错误,post请求变options请求

    vue项目CORS跨域请求500,post请求变options请求,到底是什么情况. 提示:以下内容是一个非专业开发的我对跨域的理解,并不10分准确. 一.先介绍为什么明明发送的是Post请求,为什么 ...

最新文章

  1. TEE综述:植物—土壤反馈(PSF):自然和农业科学间的桥梁
  2. 实验二matlab数值,实验二MATLAB数值计算
  3. Skype for TV停止支持 三星确认今年6月移除该应用
  4. [mybatis]缓存_一级缓存_一级缓存失效的四种情况
  5. Arduino_esp32_WiFi代码
  6. Neo4j:Cypher – Neo.ClientError.Statement.TypeError:不知道如何添加Double和String
  7. java禁止js获取cookie_JS里面如何防止浏览器COOKIES溢出
  8. LL1分析构造法_行测技巧:比较构造法两步轻松解决方程题
  9. 深度学习课程笔记(十三)深度强化学习 --- 策略梯度方法(Policy Gradient Methods)...
  10. 超赞!墙裂推荐一个 MySQL 自动化运维工具!
  11. 中国能源消费结构(2003-2019年)
  12. gini指数与cart 决策树
  13. Java使用jfreechart画饼图_JFreeChart饼图
  14. Python编程:从入门到实践(课后习题:第6章 字典)
  15. mysql(day03)
  16. Axure如何实现全选、全不选功能
  17. 全球及中国浆液阀行业市场深度分析及发展战略咨询报告2022-2028年
  18. 计算机一级计算机应用试题及答案,计算机一级考试模拟题及答案
  19. 考研概率论与数理统计
  20. 丁亥年戊申月戊戌日为朋友的工作,占得一震为雷 (六冲)卦。

热门文章

  1. 从用户反馈的可解释性提升推荐模型
  2. 说实话,你的API接口在高并发面前不堪一击!
  3. 一个古帝国做产品的故事
  4. Redis和mysql数据怎么保持数据一致的?
  5. hbase实践之写流程拾遗
  6. SpringOne 2017:与Pivotal聊大会、Spring、Reactor、WebFlux及其他
  7. 迅速掌握Unix编程
  8. C#使用ICSharpCode.SharpZipLib压缩后进行web批量下载文件
  9. 1.2 Name That Number
  10. 我的第一个CCIE-ccie6961