Update the regex for received fields to improve performance
What does this MR do and why?
Update the regex for received fields to improve performance.
Addresses https://gitlab.com/gitlab-org/gitlab/-/issues/416610
Before
If you add the spec, but leave out the code change:
Failures:
1) Gitlab::Email::Receiver when the received field is malformed mail_metadata has no ReDos issue
Failure/Error: received.filter_map { |header| header.value[RECEIVED_HEADER_REGEX, 1] }
Timeout::Error:
execution expired
# ./lib/gitlab/email/receiver.rb:180:in `[]'
# ./lib/gitlab/email/receiver.rb:180:in `block (2 levels) in recipients_from_received_headers'
# ./lib/gitlab/email/receiver.rb:180:in `each'
# ./lib/gitlab/email/receiver.rb:180:in `filter_map'
After
All the specs in spec/lib/gitlab/email/receiver_spec.rb
are back to passing.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Before | After |
---|---|
How to set up and validate locally
- Check out master
- Perform https://gitlab.com/gitlab-org/gitlab/-/issues/416610#poc
- Check out this branch
- Observe that the regex now performs well
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Nick Malcolm