Skip to content

Commit a1c863e

Browse files
author
‘niuerzhuang’
committed
fix: taint max length.
1 parent 562452e commit a1c863e

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

dongtai-common/src/main/java/io/dongtai/iast/common/constants/PropertyConstant.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ public class PropertyConstant {
3232
public static final String PROPERTY_UUID_PATH = "dongtai.uuid.path";
3333
public static final String PROPERTY_DISABLED_PLUGINS = "dongtai.disabled.plugins";
3434
public static final String PROPERTY_DISABLED_FEATURES = "dongtai.disabled.features";
35+
public static final String PROPERTY_TAINT_LENGTH = "dongtai.taint.length";
3536
}

dongtai-core/src/main/java/io/dongtai/iast/core/handler/hookpoint/models/MethodEvent.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.alibaba.fastjson2.JSONObject;
44
import io.dongtai.iast.core.handler.hookpoint.models.policy.TaintPosition;
55
import io.dongtai.iast.core.handler.hookpoint.models.taint.range.TaintRanges;
6+
import io.dongtai.iast.core.utils.PropertyUtils;
67
import io.dongtai.iast.core.utils.StringUtils;
78

89
import java.io.StringWriter;
@@ -286,6 +287,7 @@ public void setCallStack(StackTraceElement callStack) {
286287
}
287288

288289
public String obj2String(Object value) {
290+
int taintValueLength = PropertyUtils.getInstance().getTaintValueLength();
289291
StringBuilder sb = new StringBuilder();
290292
if (null == value) {
291293
return "";
@@ -299,27 +301,37 @@ public String obj2String(Object value) {
299301
if (taint.getClass().isArray() && !taint.getClass().getComponentType().isPrimitive()) {
300302
Object[] subTaints = (Object[]) taint;
301303
for (Object subTaint : subTaints) {
302-
sb.append(subTaint.toString()).append(" ");
304+
appendWithMaxLength(sb, subTaint.toString() + " ", taintValueLength);
303305
}
304306
} else {
305-
sb.append(taint.toString()).append(" ");
307+
appendWithMaxLength(sb, taint.toString() + " ", taintValueLength);
306308
}
307309
}
308310
}
309311
} else if (value instanceof StringWriter) {
310-
sb.append(((StringWriter) value).getBuffer().toString());
312+
appendWithMaxLength(sb, ((StringWriter) value).getBuffer().toString(), taintValueLength);
311313
} else {
312-
sb.append(value.toString());
314+
appendWithMaxLength(sb, value.toString(), taintValueLength);
313315
}
314316
} catch (Throwable e) {
315317
// org.jruby.RubyBasicObject.hashCode() may cause NullPointerException when RubyBasicObject.metaClass is null
316-
sb.append(value.getClass().getName())
317-
.append("@")
318-
.append(Integer.toHexString(System.identityHashCode(value)));
318+
String typeName = value.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(value));
319+
appendWithMaxLength(sb, typeName, taintValueLength);
319320
}
320321
return sb.toString();
321322
}
322323

324+
private void appendWithMaxLength(StringBuilder sb, String content, int maxLength) {
325+
if (sb.length() + content.length() > maxLength) {
326+
int remainingSpace = maxLength - sb.length();
327+
if (remainingSpace > 0) {
328+
sb.append(content, 0, remainingSpace);
329+
}
330+
} else {
331+
sb.append(content);
332+
}
333+
}
334+
323335
public List<Object> getStacks() {
324336
return stacks;
325337
}

dongtai-core/src/main/java/io/dongtai/iast/core/utils/PropertyUtils.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public class PropertyUtils {
3535

3636
private final String propertiesFilePath;
3737

38+
private int taintValueLength = -1;
39+
40+
3841
public static PropertyUtils getInstance(String propertiesFilePath) {
3942
if (null == instance) {
4043
instance = new PropertyUtils(propertiesFilePath);
@@ -229,4 +232,13 @@ public static Boolean isDisabledCustomModel() {
229232
public static Boolean validatedSink() {
230233
return ConfigBuilder.getInstance().get(ConfigKey.VALIDATED_SINK);
231234
}
235+
236+
public int getTaintValueLength() {
237+
if (-1 == taintValueLength) {
238+
taintValueLength = Integer
239+
.parseInt(System.getProperty(PropertyConstant.PROPERTY_TAINT_LENGTH,
240+
cfg.getProperty(PropertyConstant.PROPERTY_TAINT_LENGTH, "1024")));
241+
}
242+
return taintValueLength;
243+
}
232244
}

0 commit comments

Comments
 (0)