• 记一次网安安全漏洞整改


    这里网安使用的扫描软件是Acunetix,总共扫描出1个中等漏洞,2个低等漏洞,3个提示。

     

     1.Medium,Vulnerable Javascript library 易受攻击的javascript库

     

     解决,升级到最新版本即可。

    2.Low, OPTIONS method is enabled 允许options类型请求方式

     

     解决方法:禁用不安全的http请求方式(SpringBoot)

    import org.apache.catalina.Context;
    import org.apache.tomcat.util.descriptor.web.SecurityCollection;
    import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
    import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
    import org.springframework.boot.context.embedded.tomcat.TomcatContextCustomizer;
    import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    
    /**
     * @Author: SimonHu
     * @Date: 2019/9/27 15:36
     * @Description:过滤不安全http方法
     */
    @Configuration
    public class CustomCORSConfiguration  {
        @Bean
        public EmbeddedServletContainerFactory servletContainer() {
            TomcatEmbeddedServletContainerFactory tomcatServletContainerFactory = new TomcatEmbeddedServletContainerFactory();
            tomcatServletContainerFactory.addContextCustomizers(new TomcatContextCustomizer(){
                
                @Override
                public void customize(Context context) {
                    SecurityConstraint constraint = new SecurityConstraint();
                    SecurityCollection collection = new SecurityCollection();
                    //http方法
                    collection.addMethod("PUT");
                    collection.addMethod("DELETE");
                    collection.addMethod("HEAD");
                    collection.addMethod("OPTIONS");
                    collection.addMethod("TRACE");
                    //url匹配表达式
                    collection.addPattern("/*");
                    constraint.addCollection(collection);
                    constraint.setAuthConstraint(true);
                    context.addConstraint(constraint );
                    //设置使用httpOnly
                    context.setUseHttpOnly(true);
                    
                }
            });
            return tomcatServletContainerFactory;
        }
    }

    Low, Cookie(s) without Secure flag set 没有设置安全标志的Cookie

    HTTP设置cookie时,提供了2个属性,可以增强cookie的安全性,分别是secure属性和httpOnly属性。
    
    secure属性可防止信息在传递的过程中被监听捕获后导致信息泄露,如果设置为true,可以限制只有通过https访问时,才会将浏览器保存的cookie传递到服务端,如果通过http访问,不会传递cookie。
    
    httpOnly属性可以防止程序获取cookie,如果设置为true,通过js等将无法读取到cookie,能有效的防止XSS攻击

     

     解决方法(SpringBoot):

    server:
      port: 
      contextPath: /
      session:
        cookie:
          http-only: true
          secure: true

    3.Informational, Possible username or password disclosure 存在用户名和密码泄露的可能

     

    Acunetix在扫码时会用正则匹配password,pwd等关键字来查看你js脚本中是否含有这些关键字。

    解决办法:

                                var Twd = this.loginTwd;
                                var code=this.code;
                                var showCode = this.showCode;
                                var param ={'loginName':loginName,'Twd':Twd,'code':code,'showCode':showCode};
                                this.$http.post([[@{/user/login}]], param,{emulateJSON: true}).then(function (response) {

    密码类型避免使用password,pwd关键字作为参数传给服务端。

    最后再次扫描,发现没有任何漏洞提示:

     

  • 相关阅读:
    Miller-Rabin素性测试
    ###Canny边缘检测算子
    ###SIFT特征
    建立一个免费的网站
    ###C中的extern-static-const关键词
    ###Git使用问题
    ###Fedora下安装Retext
    ###使用phpmailer自动邮件提醒
    Markdown学习
    有线和无线同时连接,选择其一上网
  • 原文地址:https://www.cnblogs.com/SimonHu1993/p/11608163.html
Copyright © 2020-2023  润新知