forked from Luohuayu/CatServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[紧急安全更新 Emergency-Security-Update] Fix log4j2 3201 bug
- Loading branch information
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/catserver/server/utils/Log4j2_3201_Fixer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package catserver.server.utils; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
public class Log4j2_3201_Fixer { | ||
private final static Pattern REGEX = Pattern.compile("\\$\\{jndi:.*}"); | ||
|
||
public static boolean match(String message) { | ||
return REGEX.matcher(message).find(); | ||
} | ||
|
||
public static void matchThrowException(String message) throws RuntimeException { | ||
if (match(message)) { | ||
throw new RuntimeException("Detected log4j2 3201 bug! Message: " + message.replace("$", "\\u0024")); | ||
} | ||
} | ||
|
||
public static boolean matchPrintException(String message) throws RuntimeException { | ||
if (match(message)) { | ||
new RuntimeException("Detected log4j2 3201 bug! Message: " + message.replace("$", "\\u0024")).printStackTrace(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters