Skip to content

Commit 2a67932

Browse files
author
rvanderwerf
committed
issue-11271
1 parent 888f0a1 commit 2a67932

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

grails-web-common/src/main/groovy/org/grails/web/json/JSONTokener.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,19 @@ public JSONException syntaxError(String message) {
478478
*/
479479
@Override
480480
public String toString() {
481-
return " at character " + this.myIndex + " of " + this.mySource;
481+
int endIndex = mySource.length();
482+
boolean appendDots = false;
483+
if (endIndex > 20) {
484+
// only show first 20 characters of source to prevent reDOS attacks, especially in Java 8 regexp engine
485+
// see https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS for more info
486+
endIndex = 19;
487+
appendDots = true;
488+
}
489+
StringBuffer output = new StringBuffer(" at character " + this.myIndex + " of " + this.mySource.substring(0, endIndex));
490+
if (appendDots) {
491+
output.append("...");
492+
}
493+
return Matcher.quoteReplacement(output.toString());
494+
482495
}
483496
}

0 commit comments

Comments
 (0)