Skip to content

Commit d4d596e

Browse files
committed
Trim tokens in error messages to 256 byte to prevent attacks
1 parent c207264 commit d4d596e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3510,7 +3510,8 @@ protected void _reportInvalidToken(String matchedPart, String msg) throws IOExce
35103510
* regular Java identifier character rules. It's just a heuristic,
35113511
* nothing fancy here (nor fast).
35123512
*/
3513-
while (true) {
3513+
final int maxTokenLength = 256;
3514+
while (sb.length() < maxTokenLength) {
35143515
if (_inputPtr >= _inputEnd && !_loadMore()) {
35153516
break;
35163517
}
@@ -3521,6 +3522,9 @@ protected void _reportInvalidToken(String matchedPart, String msg) throws IOExce
35213522
}
35223523
sb.append(c);
35233524
}
3525+
if (sb.length() == maxTokenLength) {
3526+
sb.append("...");
3527+
}
35243528
_reportError("Unrecognized token '"+sb.toString()+"': was expecting "+msg);
35253529
}
35263530

0 commit comments

Comments
 (0)