logstash-plugins / logstash-patterns-core

Apache License 2.0
2.17k stars 979 forks source link

Fix: UNIXPATH to avoid DoS on long paths with unmatching chars #292

Closed kares closed 3 years ago

kares commented 4 years ago

Using PATH and namely it's sub-pattern UNIXPATH can lead to DoS (due regular expression back-tracking).

Sample one line reproducer (pattern is the original expanded UNIXPATH): ruby -e '/(\/([\w_%!$@:.,+~-]+|\\\\.)*)+ /.match "/opt/abcdef/1/.22/3:3+3/foo@BAR/X-Y+Z/~Sample_l_&^_c b"'

... the important part is the non-matching &^ sequence at the end.

Currently UNIXPATH does not handle unicode chars (separate issue), this issue (100% CPU) was discovered with non-ascii chars at the end: /home/eaeaea/data/import/Sample_xyz_lé_é_c b

Also to be noted that the pattern does not interrupt properly, using a timeout, thus there isn't a good work-around except not using or redefining PATH/UNIXPATH.

resolves https://github.com/logstash-plugins/logstash-patterns-core/issues/159