日期:2014-05-16  浏览次数:20749 次

htmlparser的一处危险用法
   最近通过同事的一次测试,正好发现了htmlparser的一处危险用法。姑且记录在博客里面,如果你恰好也用到了htmlpaser,可以检查一下自己的代码。
        htmlparser(主页地址)是一个用的比较广泛的java解析html的库。
        如下的代码使用会带来问题:
      
 import org.htmlparser.Parser;
        ......
        Parser parser = newParser(content);
        ......

        使用parser的string参数类型的构造函数,如果其中的content可以被用户或者外界手工指定时,
当用户传入"../../...../etc/passwd"时就有可能读出其中的内容。
        具体原因在于htmlparser调用了ConnectionManager这个类,其中
       
public URLConnection openConnection (String string)
        throws
            ParserException
    {
        final String prefix = "file://localhost";
        ......

      给出了读本地文件的能力。