我開發的JAVA程式碼在給Fortify檢測後,一直被查出有path manipulation…

上網查大都是教人用文字白名單過濾,但我有兩個path manipulation問題,

一是isr= new InputStreamReader 這行被檢出,這看似無法套用文字過濾…

二是 line = cleanString (br.readLine()); 這行,我本來想用文字過濾,但想到readline進來的網路資料的文字不會只有英文,還有中文,

我無法全都列進白名單,只能在確認它其中有success的文字後跳過。

以下的方法都無法騙過Fortify,不知版上有沒有人能給小弟幫助,謝謝。

public static void main(String[] args) {

String checkurl = "https://opendata.tw/";

URL connectto = new URL(checkurl);

HttpsURLConnection conn = (HttpsURLConnection) connectto.openConnection();

try {

conn.connect();}catch (IOException e){}

InputStreamReader isr = null;

if (conn.toString().contains("https://opendata.tw/")) {

if (cleanConn (conn.getInputStream()) != null){

isr= new InputStreamReader ( cleanConn(conn.getInputStream()),"UTF-8" );}

BufferedReader br = new BufferedReader(isr);

StringBuilder sb = new StringBuilder();

String line;

line = cleanString (br.readLine());

}

public static String cleanString(String path) {

HashMap map = new HashMap();

map.put("a", "a");

map.put("b", "b");

map.put("c", "c");

map.put("d", "d");

map.put("e", "e");

map.put("f", "f");

map.put("g", "g");

map.put("h", "h");

map.put("i", "i");

map.put("j", "j");

map.put("k", "k");

map.put("l", "l");

map.put("m", "m");

map.put("n", "n");

map.put("o", "o");

map.put("p", "p");

map.put("q", "q");

map.put("r", "r");

map.put("s", "s");

map.put("t", "t");

map.put("u", "u");

map.put("v", "v");

map.put("w", "w");

map.put("x", "x");

map.put("y", "y");

map.put("z", "z");

map.put("A", "A");

map.put("B", "B");

map.put("C", "C");

map.put("D", "D");

map.put("E", "E");

map.put("F", "F");

map.put("G", "G");

map.put("H", "H");

map.put("I", "I");

map.put("J", "J");

map.put("K", "K");

map.put("L", "L");

map.put("M", "M");

map.put("N", "N");

map.put("O", "O");

map.put("P", "P");

map.put("Q", "Q");

map.put("R", "R");

map.put("S", "S");

map.put("T", "T");

map.put("U", "U");

map.put("V", "V");

map.put("W", "W");

map.put("X", "X");

map.put("Y", "Y");

map.put("Z", "Z");

map.put(".", ".");

map.put(":", ":");

map.put("/", "/");

map.put("\\", "\\");

Character curChar = null;

Character nextChar = null;

if (path.contains("http")) {

map.put("?", "?");

map.put("-", "-");

map.put("=", "=");

map.put("0", "0");

map.put("1", "1");

map.put("2", "2");

map.put("3", "3");

map.put("4", "4");

map.put("5", "5");

map.put("6", "6");

map.put("7", "7");

map.put("8", "8");

map.put("9", "9");

//map.put(",", ",");

//map.put("\"", "\"");

//map.put("[", "[");

//map.put("]", "]");

//map.put("{", "{");

//map.put("}", "}");

}

if (path.contains("success")) {

return path;

}else {

String temp = "";

for (int i = 0; i < path.length(); i++) {

try{

curChar=path.charAt(i);

nextChar= path.charAt(i+1);

}catch (Exception e) {}

//過濾,避免有../的跳脫字元

if (map.get(path.charAt(i)+"")!=null) {

if (map.get(path.charAt(i)+"")!=null && curChar == '.' && nextChar !='.') {

temp += map.get(path.charAt(i)+"");

}else if (map.get(path.charAt(i)+"")!=null && curChar != '.') {

temp += map.get(path.charAt(i)+"");

}

}

}

return temp;

}

}

private static InputStream cleanConn(InputStream inputStream) {

// TODO Auto-generated method stub

if (inputStream.toString().contains("sun.net.www.protocol.http.HttpURLConnection")) {

return inputStream;

}

return null;

}

Java关键字fymd,JAVA程式碼一直被foritfy檢出有path manipulation相关推荐

  1. java语言语法--- Java标识符(标识符命名规则)、Java关键字、Java变量(变量的声明、赋值、使用)和常量(字符常量、字面常量)(包括Java字节码文件反汇编命令javap)

    java语言语法- Java标识符.Java关键字.Java变量和常量(包括Java字节码文件反汇编命令javap) 1.标识符 (1)读音:biao zhi fu (2)什么是标识符? (摘自百度百 ...

  2. Java关键字this、super使用总结

    2019独角兽企业重金招聘Python工程师标准>>> 一.this关键字 Java关键字this只能用于成员方法体内,它是一个系统隐含的指针且被自动附加在非静态的成员方法参数列表中 ...

  3. java关键字_Java关键字

    java关键字 Java keywords are the reserved words that are used by the Java compiler. These keywords have ...

  4. java关键字保留字_Java这个关键字

    java关键字保留字 Java中的" this"关键字是什么? (What is 'this' Keyword in Java?) Java this keyword return ...

  5. 事无巨细说Java之---Java 关键字

    Java 关键字也称为保留字. 关键字是充当代码关键的特定词. 这些是 Java 预定义的单词,因此它们不能用作变量或对象名或类名. Java 关键字列表 Java 关键字或保留字列表如下: 1,ab ...

  6. Java关键字及其作用

    一. 关键字总览: 访问控制 private protected public             类,方法和变量修饰符 abstract class extends final implemen ...

  7. Java关键字系列(public,protected,private)

    Java关键字系列(public,protected,private) public.protected和private做为java访问权限修饰词而使用. 首先要明白,java中的每个定义(定义类.字 ...

  8. 深入Java关键字instanceof

    深入Java关键字instanceof   instanceof关键字用于判断一个引用类型变量所指向的对象是否是一个类(或接口.抽象类.父类)的实例.   举个例子: public interface ...

  9. Java关键字final、static、this、super使用总结

    一.final 根据程序上下文环境,Java关键字final有"这是无法改变的"或者"终态的"含义,它可以修饰非抽象类.非抽象类成员方法和变量.你可能出于两种理 ...

最新文章

  1. js实现简单的循环打字效果(思路分享)
  2. mongodb 服务器时区设置_关于MongoDB-Balancer设置时间窗口的问题
  3. Struts Validator验证器使用指南
  4. Hash——字符串匹配(求s1在s2中出现的次数)
  5. python找色_python实现按键精灵找色点击功能教程,使用pywin32和Pillow库
  6. Django笔记---数据库设计
  7. thymeleaf 使用javascript定义数组报错
  8. luogu 1344 追查坏牛奶(最小割)
  9. EXPLAIN字段详解
  10. 中兴通讯推出全球首款Wi-Fi 7标准5G CPE
  11. 输入框中光标过长原因
  12. genymotion 前端调试
  13. 工厂供电MATLAB仿真,工厂供电课程设计---基于MATLAB的电力电子系统仿真
  14. Kerberos KDC not reachable
  15. J2EE 领域的一些技术框架结构图
  16. 大疆DJI Thermal SDK Linux libdirp.so: cannot open shared object file: No such file or directory
  17. 各类编程开发软件及资源全版本下载地址合集
  18. 启动tomcat闪退如何获取报错信息
  19. C#编写OWC11组件
  20. Kafka ISR机制

热门文章

  1. mpAndroidchart 坐标和图表距离_数据对比图表,如何让你的总结报告更具说服力!...
  2. Java基础练习之流程控制(四)
  3. 三种前端手机开发(uni-app、vant、mui)
  4. strace ltrace使用
  5. 八大排序算法总结以及python实现
  6. H264 帧、pps 、sps
  7. Android定时器AlarmManager(定时发送广播)
  8. android 4.0 蓝牙分析之二
  9. 我的.emacs(Ubuntu版)
  10. C++函数与java函数菜鸟级的对比理解