File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed
grails-web-common/src/main/groovy/org/grails/web/json Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -467,7 +467,8 @@ public void skipPast(String to) {
467467 * @return A JSONException object, suitable for throwing
468468 */
469469 public JSONException syntaxError (String message ) {
470- return new JSONException (message + toString ());
470+
471+ return new JSONException (message + toRegexSafeString ());
471472 }
472473
473474
@@ -480,4 +481,26 @@ public JSONException syntaxError(String message) {
480481 public String toString () {
481482 return " at character " + this .myIndex + " of " + this .mySource ;
482483 }
484+
485+ /**
486+ * Make a regex safe printable string of this JSONTokener.
487+ *
488+ * @return " at character [this.myIndex] of [this.mySource]"
489+ */
490+ public String toRegexSafeString () {
491+ int endIndex = mySource .length ();
492+ boolean appendDots = false ;
493+ if (endIndex > 20 ) {
494+ // only show first 20 characters of source to prevent reDOS attacks, especially in Java 8 regexp engine
495+ // see https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS for more info
496+ endIndex = 19 ;
497+ appendDots = true ;
498+ }
499+ StringBuffer output = new StringBuffer (" at character " + this .myIndex + " of " + this .mySource .substring (0 , endIndex ));
500+ if (appendDots ) {
501+ output .append ("..." );
502+ }
503+ return Matcher .quoteReplacement (output .toString ());
504+ }
505+
483506}
You can’t perform that action at this time.
0 commit comments