@@ -59,9 +59,9 @@ public class MetricsCollectorFilter implements Filter {
59
59
private static final String DEBUG = "debug" ;
60
60
private static final String APPLICATION_VERSION = "application-version" ;
61
61
private static final String DEFAULT_FILTER_REGEX = "^([a-zA-z0-9 ]{0,120})" ;
62
- private static final String FILTER_REGEX_PARAM = "filter -regex" ;
63
- private static final String FILTER_GROUP_INDEX_PARAM = "filter -index" ;
64
- private static final String FILTER_MAX_SIZE_PARAM = "filter -max-size" ;
62
+ private static final String FILTER_REGEX_PARAM = "error-message -regex" ;
63
+ private static final String FILTER_GROUP_INDEX_PARAM = "error-message-regex -index" ;
64
+ private static final String FILTER_MAX_SIZE_PARAM = "error-message -max-size" ;
65
65
private final List <String > exclusions = new ArrayList <String >();
66
66
private int filter_group_index = 0 ;
67
67
private int filter_max_size = 120 ;
@@ -244,18 +244,22 @@ private String getErrorMessage(HttpServletRequest httpRequest) {
244
244
return result ;
245
245
}
246
246
247
- // filter Error Message with regex
248
- if (filter_regex .length () > 0 ) {
249
- final Pattern pattern = Pattern .compile (filter_regex );
250
- final Matcher matcher = pattern .matcher (errorMessage );
251
-
252
- if (matcher .find ()) {
253
- result = matcher .group (filter_group_index );
247
+ try {
248
+ // filter Error Message with regex
249
+ if (filter_regex .length () > 0 ) {
250
+ final Pattern pattern = Pattern .compile (filter_regex );
251
+ final Matcher matcher = pattern .matcher (errorMessage );
252
+ if (matcher .find ()) {
253
+ result = matcher .group (filter_group_index );
254
+ }
254
255
}
255
- }
256
- // create limit size of the error message
257
- if (result .length () > filter_max_size ) {
258
- result = result .substring (0 , filter_max_size );
256
+ // create limit size of the error message
257
+ if (result .length () > filter_max_size ) {
258
+ result = result .substring (0 , filter_max_size );
259
+ }
260
+ } catch (Exception e ) {
261
+ // avoid invalid regex or invalid matcher group index
262
+ result = "" ;
259
263
}
260
264
return result ;
261
265
}
0 commit comments