User.toJson() builds JSON by string concatenation without escaping any of the values:
public String toJson() {
String strTemp = "\"%s\"";
return "{" +
"\"Id\":" + id + "," +
"\"Username\":" + String.format(strTemp, getUsername()) + "," +
"\"Password\":" + String.format(strTemp, getPassword()) + "," +
"\"Email\":" + String.format(strTemp, getEmail()) + "," +
...
}
It just wraps each value in quotes. If any field contains a double-quote, backslash, or newline, the produced JSON is broken. Username is charset-limited so it's safe, but Password is not, passwords are allowed to contain punctuation (only "at least one letter and one number" is enforced). So a user whose password contains a " or \ produces malformed JSON here.
Wherever toJson() feeds a request (registration is the obvious one), that means users with those characters in their password get a broken payload and can't register/login through this path, and in the worst case the unescaped value could inject extra JSON fields.
This should use a real JSON builder (org.json's JSONObject, which the codebase already uses elsewhere) instead of hand-concatenating, so values get escaped properly. Bonus: it'd stop serializing the plaintext Password/Email into a string that can end up in logs.
File: core/src/com/focus/kingdom/network/dto/User.java, toJson, around line 370-386.
User.toJson()builds JSON by string concatenation without escaping any of the values:It just wraps each value in quotes. If any field contains a double-quote, backslash, or newline, the produced JSON is broken. Username is charset-limited so it's safe, but Password is not, passwords are allowed to contain punctuation (only "at least one letter and one number" is enforced). So a user whose password contains a
"or\produces malformed JSON here.Wherever toJson() feeds a request (registration is the obvious one), that means users with those characters in their password get a broken payload and can't register/login through this path, and in the worst case the unescaped value could inject extra JSON fields.
This should use a real JSON builder (org.json's JSONObject, which the codebase already uses elsewhere) instead of hand-concatenating, so values get escaped properly. Bonus: it'd stop serializing the plaintext Password/Email into a string that can end up in logs.
File:
core/src/com/focus/kingdom/network/dto/User.java, toJson, around line 370-386.