1. 关于Log的问题(Log Forging),整个系统中,对于Log的问题最多,可以采用以下方式进行解决。
解决方案如下:
1) 只输出必要的日志,功能上线前屏蔽大多数的调试日志。
2) 过滤掉非法字符:
2. 关于创建File(Path Manipulation)的问题。
Fortify扫描遇到了Path Manipulation问题,定位代码如下:
1. File publisFile = null;
2. File publisFileDir = new File(OSSFileUtils.getDeploy()+"/"+corpPK);
涉及到安全性问题,在文件目录下,没有限制文件目录,可能存在的问题是:可以退回上一级目录,继而访问上一级内容,
解决办法:
step1增加工具方法对文件目录的特殊字符进行处理
step2.引用工具方法
1. String temp;
2. temp = FileSwitch.validFilePath(OSSFileUtils.getProduct_package());
3. File f = new File(temp, p.getFileName());
3. 关于Double转换(Parse Double)的问题
详见:http://blog.csdn.net/onerasp/article/details/50033711
可采用重封装的新方法:
public classConvertDouble {
privatefinalstaticPattern NUMBER_PATTERN
= Pattern.compile("^([+-]?\\d*\\.?\\d*([eE][+-]?)?\\d*).*");
publicstaticdoubleparseDouble(String value) {
String normalString = normalizeDoubleString(value);
int offset = normalString.indexOf('E');
BigDecimal base;
int exponent;
if (offset == -1) {
base = new BigDecimal(value);
exponent = 0;
} else {
base = new BigDecimal(normalString.substring(0,offset));
exponent = Integer.parseInt(normalString.charAt(offset+ 1) == '+'?
normalString.substring(offset +2) :
normalString.substring(offset +1));
}
returnbase.scaleByPowerOfTen(exponent).doubleValue();
}
publicstaticString normalizeDoubleString(String strValue) {
// Clean-up string representation so that it could be understood
// by Java's BigDecimal. Not terribly efficient for now.
// 1. MRI allows d and D as exponent separators
strValue = strValue.replaceFirst("[edD]","E");
// 2. MRI allows underscores anywhere
strValue = strValue.replaceAll("_", "");
// 3. MRI ignores the trailing junk
strValue = NUMBER_PATTERN.matcher(strValue).replaceFirst("$1");
return strValue;
}
4. 关于密码的问题(Privacy Violation)
关于密码的,建议对密码进行加密,在使用时对密码进行解密,并且在使用时,定义的变量中不要包含PASSWORD以及password 的敏感字段