Skip to content

Commit 1b166af

Browse files
committed
fix(channelTopicPattern): SonarS5852 vulnerability
Most of the regular expression engines use backtracking to try all possible execution paths of the regular expression when evaluating an input, in some cases it can cause performance issues, called catastrophic backtracking situations. In the worst case, the complexity of the regular expression is exponential in the size of the input, this means that a small carefully-crafted input (like 20 chars) can trigger catastrophic backtracking and cause a denial of service of the application. Super-linear regex complexity can lead to the same impact too with, in this case, a large carefully-crafted input (thousands chars). Signed-off-by: Chris Sdogkos <work@chris-sdogkos.com>
1 parent 806feb2 commit 1b166af

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

application/src/main/java/org/togetherjava/tjbot/features/dynamicvc/DynamicVoiceListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public class DynamicVoiceListener extends VoiceReceiverAdapter {
4848
private final Logger logger = LoggerFactory.getLogger(DynamicVoiceListener.class);
4949

5050
private final Map<String, Predicate<String>> channelPredicates = new HashMap<>();
51-
private static final Pattern channelTopicPattern = Pattern.compile("(\\s+\\d+)$");
51+
52+
private static final Pattern channelTopicPattern = Pattern.compile("(\\s{1,100}\\d+)$");
5253

5354
/** Map of event queues for each channel topic. */
5455
private final Map<String, Queue<GuildVoiceUpdateEvent>> eventQueues = new HashMap<>();

0 commit comments

Comments
 (0)