Skip to content

Commit

Permalink
Optimize the regex parser for InvalidResponse
Browse files Browse the repository at this point in the history
Rather than using a backtracking pattern which could have performance
impact, switch to using explict character ranges which work for json
path seperated with periods.

Mitigates sonar lint rule java:S5852 [1]

- [1] https://rules.sonarsource.com/java/RSPEC-5852/?search=Using%20slow%20regular%20expressions%20is%20security-sensitive

Signed-off-by: Peter Nied <[email protected]>
  • Loading branch information
peternied committed Sep 30, 2024
1 parent d5f5be6 commit 39e67ae
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

@Slf4j
public class InvalidResponse extends RfsException {
private static final Pattern UNKNOWN_SETTING = Pattern.compile("unknown setting \\[(.+?)\\].+");
private static final Pattern UNKNOWN_SETTING = Pattern.compile("unknown setting \\[([a-zA-Z0-9_.-]+)\\].+");
private static final ObjectMapper objectMapper = new ObjectMapper();
private final transient HttpResponse response;

Expand Down

0 comments on commit 39e67ae

Please sign in to comment.