File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
grails-web-common/src/main/groovy/org/grails/web/json Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments