这种问题有主要分为两类:

1、代码中将字符转大写或小写,然后使用equals方法进行比较,这类问题一般都比较好处理,字符串不再进行大小写转换,直接使用equalsIgnoreCase()方法替换equals方法即可;

如下为存在漏洞的代码

String srt1 = "http";
String srt2 = "HTTP";
srt1.toUpperCase().equals(srt2);//存在漏洞

修改后的代码

String srt1 = "http";
String srt2 = "HTTP";
srt1.equalsIgnoreCase(srt2);//漏洞解决

2、代码中需要判断字符串是以什么开头或者以什么结尾,此时equalsIgnoreCase()方法没有办法直接使用,所以,可以将字符串先进行截取,然后再使用equalsIgnoreCase()比较;

如下为存在漏洞的代码

String srt1 = "https://www.baidu";
String srt2 = "https";
srt1.startsWith(srt2);//存在漏洞

修改后的代码

String srt1 = "https://www.baidu";
String srt2 = "https";
if(srt1 != null && srt1.length() > 5) {
    srt1 = srt1.substring(0, 5);
    srt1.equalsIgnoreCase(srt2);//漏洞解决
}

更多推荐

Fortify漏洞Portability Flaw: Locale Dependent Comparison