Skip to content

Commit c11628f

Browse files
authored
Merge pull request #152 from exexute/main
Close ISSUE #151 (remove unused code)
2 parents 0518c5f + e7aff36 commit c11628f

File tree

8 files changed

+12
-255
lines changed

8 files changed

+12
-255
lines changed

dongtai-jakarta-api/src/main/java/cn/huoxian/iast/api/RequestWrapper.java

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@
1010
import java.io.IOException;
1111
import java.io.InputStream;
1212
import java.io.InputStreamReader;
13-
import java.util.Collections;
14-
import java.util.Enumeration;
15-
import java.util.HashMap;
16-
import java.util.HashSet;
17-
import java.util.Map;
18-
import java.util.Set;
1913

2014

2115
/**
@@ -25,7 +19,6 @@ public class RequestWrapper extends HttpServletRequestWrapper {
2519

2620
private final String body;
2721
private final boolean usingBody;
28-
private final Map<String, String> customHeaders;
2922

3023
public static Object cloneRequest(Object req) {
3124
if (req instanceof HttpServletRequest) {
@@ -36,7 +29,6 @@ public static Object cloneRequest(Object req) {
3629

3730
private RequestWrapper(HttpServletRequest request) {
3831
super(request);
39-
this.customHeaders = new HashMap<String, String>();
4032
this.usingBody = ("POST".equals(request.getMethod()) && request.getContentType().contains("application/json"));
4133

4234
StringBuilder stringBuilder = new StringBuilder();
@@ -106,28 +98,6 @@ public BufferedReader getReader() throws IOException {
10698
}
10799
}
108100

109-
@Override
110-
public String getHeader(String name) {
111-
String headerValue = customHeaders.get(name);
112-
113-
if (headerValue != null) {
114-
return headerValue;
115-
}
116-
return super.getHeader(name);
117-
}
118-
119-
@Override
120-
public Enumeration<String> getHeaderNames() {
121-
Set<String> set = new HashSet<String>(customHeaders.keySet());
122-
123-
@SuppressWarnings("unchecked")
124-
Enumeration<String> headerNames = super.getHeaderNames();
125-
while (headerNames.hasMoreElements()) {
126-
set.add(headerNames.nextElement());
127-
}
128-
return Collections.enumeration(set);
129-
}
130-
131101
public String getBody() {
132102
return this.body;
133103
}

dongtai-servlet-api/src/main/java/cn/huoxian/iast/api/RequestWrapper.java

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@
55
import java.io.IOException;
66
import java.io.InputStream;
77
import java.io.InputStreamReader;
8-
import java.util.Collections;
9-
import java.util.Enumeration;
108
import java.util.HashMap;
11-
import java.util.HashSet;
129
import java.util.Map;
13-
import java.util.Set;
1410
import javax.servlet.ReadListener;
1511
import javax.servlet.ServletInputStream;
1612
import javax.servlet.http.HttpServletRequest;
@@ -23,7 +19,6 @@ public class RequestWrapper extends HttpServletRequestWrapper {
2319

2420
private final String body;
2521
private final boolean usingBody;
26-
private final Map<String, String> customHeaders;
2722

2823
public static Object cloneRequest(Object req) {
2924
if (req instanceof HttpServletRequest) {
@@ -34,7 +29,6 @@ public static Object cloneRequest(Object req) {
3429

3530
private RequestWrapper(HttpServletRequest request) {
3631
super(request);
37-
this.customHeaders = new HashMap<String, String>();
3832
this.usingBody = ("POST".equals(request.getMethod()) && request.getContentType().contains("application/json"));
3933

4034
StringBuilder stringBuilder = new StringBuilder();
@@ -104,30 +98,6 @@ public BufferedReader getReader() throws IOException {
10498
}
10599
}
106100

107-
@Override
108-
public String getHeader(String name) {
109-
String headerValue = customHeaders.get(name);
110-
111-
if (headerValue != null) {
112-
return headerValue;
113-
}
114-
return super.getHeader(name);
115-
}
116-
117-
@Override
118-
public Enumeration<String> getHeaderNames() {
119-
Set<String> set = new HashSet<String>(customHeaders.keySet());
120-
121-
@SuppressWarnings("unchecked")
122-
Enumeration<String> headerNames = super.getHeaderNames();
123-
while (headerNames.hasMoreElements()) {
124-
String n = headerNames.nextElement();
125-
set.add(n);
126-
}
127-
return Collections.enumeration(set);
128-
}
129-
130-
131101
public String getBody() {
132102
return this.body;
133103
}

iast-core/src/main/java/com/secnium/iast/core/report/AgentQueueReport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected void send() throws Exception {
4545
StringBuilder response = HttpClientUtils.sendPost(Constants.API_REPORT_UPLOAD, generateHeartBeatMsg());
4646
HttpRequestReplay.sendReplayRequest(response);
4747
} catch (Exception e) {
48-
logger.error("report error, reason: ", e);
48+
logger.error("agent queue reported failed. reason: ", e);
4949
}
5050
}
5151
}

iast-core/src/main/java/com/secnium/iast/core/report/MethodReportSender.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,31 @@
22

33
import com.secnium.iast.core.AbstractThread;
44
import com.secnium.iast.core.EngineManager;
5-
import com.secnium.iast.core.replay.HttpRequestReplay;
65
import com.secnium.iast.core.util.Constants;
76
import com.secnium.iast.core.util.HttpClientUtils;
87
import com.secnium.iast.core.util.LogUtils;
98
import org.slf4j.Logger;
109

11-
import java.util.regex.Pattern;
12-
1310
/**
1411
* 发送报告的功能实现
1512
*
1613
1714
*/
1815
public class MethodReportSender extends AbstractThread {
16+
1917
private final Logger logger = LogUtils.getLogger(MethodReportSender.class);
20-
private final Pattern PATTERN = Pattern.compile("\"type\":1}");
2118

2219
@Override
2320
protected void send() throws Exception {
24-
StringBuilder response;
2521
while (EngineManager.hasMethodReport()) {
2622
String report = EngineManager.getMethodReport();
2723
try {
2824
if (report != null && !report.isEmpty()) {
29-
response = HttpClientUtils.sendPost(Constants.API_REPORT_UPLOAD, report);
30-
if (PATTERN.matcher(report).find()) {
31-
HttpRequestReplay.sendReplayRequest(response);
32-
}
25+
HttpClientUtils.sendPost(Constants.API_REPORT_UPLOAD, report);
3326
}
3427
} catch (Exception e) {
3528
logger.info(report);
36-
throw e;
29+
logger.error("send method report error, reason: ", e);
3730
}
3831
}
3932
}

iast-core/src/main/java/com/secnium/iast/core/report/ReportSender.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
1414
*/
1515
public class ReportSender extends AbstractThread {
16+
1617
private final Logger logger = LogUtils.getLogger(ReportSender.class);
17-
// private final Pattern PATTERN = Pattern.compile("\"type\":1}");
1818

1919
@Override
2020
protected void send() throws Exception {

iast-core/src/main/java/com/secnium/iast/core/threadlocalpool/IastTaintPool.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.secnium.iast.core.EngineManager;
44
import com.secnium.iast.core.PropertyUtils;
55
import com.secnium.iast.core.handler.models.MethodEvent;
6-
76
import java.util.HashSet;
87
import java.util.Map;
98
import java.util.Set;
@@ -12,6 +11,7 @@
1211
1312
*/
1413
public class IastTaintPool extends ThreadLocal<HashSet<Object>> {
14+
1515
private static final PropertyUtils PROPERTIES = PropertyUtils.getInstance();
1616

1717
@Override
@@ -22,8 +22,7 @@ protected HashSet<Object> initialValue() {
2222
/**
2323
* 将待加入污点池中的数据插入到污点池,其中:复杂数据结构需要拆分为简单的数据结构
2424
* <p>
25-
* 检测类型,如果是复杂类型,将复杂类型转换为简单类型仅从保存
26-
* source点 获取的数据,需要将复杂类型的数据转换为简单类型进行存储
25+
* 检测类型,如果是复杂类型,将复杂类型转换为简单类型仅从保存 source点 获取的数据,需要将复杂类型的数据转换为简单类型进行存储
2726
* <p>
2827
* fixme: 后续补充所有类型
2928
*
@@ -53,12 +52,12 @@ public void addTaintToPool(Object obj, MethodEvent event, boolean isSource) {
5352
this.get().add(obj);
5453
if (isSource) {
5554
Map<String, String[]> tempMap = (Map<String, String[]>) obj;
56-
Set<Map.Entry<String, String[]>> entrys = tempMap.entrySet();
57-
for (Map.Entry<String, String[]> entry : entrys) {
55+
Set<Map.Entry<String, String[]>> entries = tempMap.entrySet();
56+
for (Map.Entry<String, String[]> entry : entries) {
5857
Object key = entry.getKey();
5958
Object value = entry.getValue();
60-
addTaintToPool(key, event, isSource);
61-
addTaintToPool(value, event, isSource);
59+
addTaintToPool(key, event, true);
60+
addTaintToPool(value, event, true);
6261
}
6362
}
6463
} else if (obj.getClass().isArray() && !obj.getClass().getComponentType().isPrimitive()) {
@@ -73,11 +72,10 @@ public void addTaintToPool(Object obj, MethodEvent event, boolean isSource) {
7372
if (obj instanceof String && PROPERTIES.isNormalMode()) {
7473
subHashCode = System.identityHashCode(obj);
7574
EngineManager.TAINT_HASH_CODES.get().add(subHashCode);
76-
event.addTargetHash(subHashCode);
7775
} else {
7876
subHashCode = obj.hashCode();
79-
event.addTargetHash(subHashCode);
8077
}
78+
event.addTargetHash(subHashCode);
8179

8280
}
8381
}

iast-core/src/main/java/com/secnium/iast/core/util/commonUtils.java

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,6 @@
66
77
*/
88
public class commonUtils {
9-
public static boolean arrayEquals(String[] source, String classname) {
10-
if (classname == null) {
11-
return false;
12-
}
13-
int i;
14-
byte index;
15-
for (i = source.length, index = 0; index < i; index++) {
16-
String sourceClassName = source[index];
17-
if (sourceClassName.equals(classname)) {
18-
return true;
19-
}
20-
}
21-
return false;
22-
}
23-
24-
public static boolean endsWith(String[] prefixs, String target) {
25-
int i;
26-
byte b;
27-
for (i = prefixs.length, b = 0; b < i; ) {
28-
String prefix = prefixs[b];
29-
if (target.endsWith(prefix)) {
30-
return true;
31-
}
32-
b++;
33-
}
34-
return false;
35-
}
369

3710

3811
public static boolean contains(String classname, String[] prexArray) {
@@ -67,37 +40,4 @@ public static boolean isEmpty(String name) {
6740
return name == null || name.length() == 0;
6841
}
6942

70-
public static int a(String fieldname, String target, int start) {
71-
return a(fieldname, target, start, -1);
72-
}
73-
74-
public static int a(String fieldname, String target, int start, int end) {
75-
if (isEmpty(target)) {
76-
return 0;
77-
}
78-
if (isEmpty(fieldname)) {
79-
return -1;
80-
}
81-
82-
int index = start;
83-
for (; index < fieldname.length() - target.length() + 1 && (end == -1 || index < end); index++) {
84-
int j = index;
85-
byte b1 = 0;
86-
while (j < fieldname.length() && b1 < target.length()) {
87-
if (fieldname.charAt(j) != target.charAt(b1) && (fieldname.charAt(j) | 0x20) != (target.charAt(b1) | 0x20)) {
88-
break;
89-
}
90-
b1++;
91-
j++;
92-
}
93-
if (b1 == target.length()) {
94-
return index;
95-
}
96-
}
97-
return -1;
98-
}
99-
100-
public static int c(String fieldname, String target) {
101-
return a(fieldname, target, 0);
102-
}
10343
}

0 commit comments

Comments
 (0)