Limit/validate string lengths for various identifiers to prevent DoS from large objects
Change-Id: Ib7c34ddf8bd161efdf8d00a50f3378f9b7366188
diff --git a/core/api/src/main/java/org/onosproject/net/key/DeviceKeyId.java b/core/api/src/main/java/org/onosproject/net/key/DeviceKeyId.java
index ad401a1..6339e38 100644
--- a/core/api/src/main/java/org/onosproject/net/key/DeviceKeyId.java
+++ b/core/api/src/main/java/org/onosproject/net/key/DeviceKeyId.java
@@ -18,11 +18,15 @@
import org.onlab.util.Identifier;
+import static com.google.common.base.Preconditions.checkArgument;
+
/**
* Device key identifier backed by a string value.
*/
public final class DeviceKeyId extends Identifier<String> {
+ private static final int ID_MAX_LENGTH = 1024;
+
/**
* Constructor for serialization.
*/
@@ -46,6 +50,9 @@
* @return device key identifier
*/
public static DeviceKeyId deviceKeyId(String id) {
+ if (id != null) {
+ checkArgument(id.length() <= ID_MAX_LENGTH, "id exceeds maximum length " + ID_MAX_LENGTH);
+ }
return new DeviceKeyId(id);
}