修改目的:struts-1.2.9 有CVE-2014-0114漏洞:http://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=commons,
各方面原因替换mvc框架不现实,因此计划维护自己的struts分支修复该漏洞
本次只记录struts-1.2.9源码修改包名包路径过程
升级步骤
1、准备2个包:通过maven获取struts源码包(struts-1.2.9-sources.jar)和编译后的jar包(struts-1.2.9.jar)
2、修改struts源码org/apache/struts目录为com/hhfclub/struts目录并放置到原项目根目录下
3、从struts-1.2.9.jar的META-INF中取出tlds标签库模板放置到原项目的WEB-INF下(源码包中没有这些tld标签库)
4、从struts-1.2.9.jar的org/apache/struts/中复制resources目录到com/hhfclub/struts/下(源码中没有该目录,目录下存放的是dtd约束文件)
5、删除原项目pom文件中对struts的依赖
6、全局搜索org/apache/struts替换为com/hhfclub/struts , 包括xml,tld,java,jsp文件
7、解决部分项目编译错误
8、启动试试
遇到的问题:
1、jar包里有struts路径引用的需先获取jar包源码,然后尝试修改覆盖
2、升级commons-logging 从1.1.1到1.2
3、升级commons-beanutils 1.8.3到1.9.3后,项目启动时struts使用commons-Digester解析xml配置文件时会有无限等待的情况(如下图),暂未解决,commons-beanutils版本回退到1.8.3后问题消失
com.hhfclub.struts.action.ActionServlet.parseModuleConfigFile(ActionServlet.java:739)相关源码:
/**
* <p>Parses one module config file.</p>
*
* @param digester Digester instance that does the parsing
* @param path The path to the config file to parse.
*
* @throws UnavailableException if file cannot be read or parsed
* @since Struts 1.2
*/
protected void parseModuleConfigFile(Digester digester, String path)
throws UnavailableException {
InputStream input = null;
try {
URL url = getServletContext().getResource(path);
// If the config isn't in the servlet context, try the class loader
// which allows the config files to be stored in a jar
if (url == null) {
url = getClass().getResource(path);
}
if (url == null) {
String msg = internal.getMessage("configMissing", path);
log.error(msg);
throw new UnavailableException(msg);
}
InputSource is = new InputSource(url.toExternalForm());
input = url.openStream();
is.setByteStream(input);
log.info("Parsing struts config file:"+path);
digester.parse(is);
} catch (MalformedURLException e) {
handleConfigException(path, e);
} catch (IOException e) {
handleConfigException(path, e);
} catch (SAXException e) {
handleConfigException(path, e);
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
throw new UnavailableException(e.getMessage());
}
}
}
}
如需重新打个新的struts包只需把以上的struts源码和其依赖的jar包放到一个单独的maven项目环境下通过maven打包即可
struts依赖包可以从struts-1.2.9.jar包里的META-INF/MANIFEST.MF文件查看,但需要注意依赖包的版本问题,可以参考
https://mvnrepository.com/artifact/struts/struts/1.2.9
以下贴出我项目依赖的版本号
依赖包 | 版本号 |
---|---|
commons-beanutils.jar | 1.8.3 |
commons-digester.jar | 1.8 |
commons-fileupload.jar | 1.4 |
commons-logging.jar | 1.2 |
commons-validator.jar | 1.4 |