# Bug OP-20919 - DDOS VULNERABILITY - Typeahead filter and search filter

Project: OpenProject
Status: confirmed
URL: https://community.openproject.org/work_packages/OP-20919

## Open points

_No work packages_

## Details

| Attribute | Value |
| --- | --- |
| Date |  |
| Priority | Medium |
| Module | DevSecOps / Security, Modules and project features / Search |
| Target versions |  |
| Observed in versions | 18.0.0, 17.9.7 |
| Sprint |  |
| Backlog bucket |  |
| Bug found in version (deprecated) |  |
| Found in mobile app version |  |
| Follow-up feedback e-mail |  |
| Requires doc change | No |
| Accessibility | No |
| Pull preview |  |
| List |  |
| Labels |  |

## People

| Attribute | Value |
| --- | --- |
| Assignee |  |
| Accountable |  |
| Product manager |  |
| Developers |  |
| Designer |  |
| Ordered by |  |
| Signed off by |  |
| Interest by |  |

## Planning

| Attribute | Value |
| --- | --- |
| Relevance |  |

## Costs

| Attribute | Value |
| --- | --- |
| Votes |  |
| Work |  |
| Labor costs |  |

## Description

### Steps to reproduce

_Please write down the steps to reproduce. Try to write down all necessary preconditions (what permissions do you have, are other users involved?). Example:_

1.  Login as a user with access to a large number of work packages (like an admin)
    
2.  Click into the search bar at the top of the page
    
3.  Paste in several hundred words of text
    
4.  Depending on site configuration this may crash out all users due to the database connection pool being exhausted
    
5.  Check the logs for the &quot;user=XXXX Encountered slow SQL (2982.1921 ms): SELECT &quot;work\_packages&quot;.&quot;id&quot; AS t0\_r0, &quot;work\_packages&quot;.&quot;type\_id&quot; AS t0\_r1, &quot;work\_packages&quot;.&quot;project\_id&quot; AS t0\_r2, &quot;work\_packages&quot;.&quot;subject&quot; AS t0\_r3, &quot;work\_packages&quot;.&quot;description&quot; AS t0\_r4, &quot; type messages and look at the where statement
    

### What is the buggy behavior?

*   May exhaust the entire connection pool and cause a short (1 to 3 minute) outage for all users
    

### What is the expected behavior?

/app/controllers/search\_controller.rb &nbsp;has `tokens.slice! 5..-1 if tokens.size > 5` to limit the number of words used to generate the where clause

/app/models/queries/projects/filters/typeahead\_filter.rb and /app/models/queries/work\_packages/filter/search\_filter.rb  should implement similar logic.

Perhaps

```ruby
MAX_WORDS = 10
# Unicode letter and number classes.
HAS_LETTER_OR_DIGIT = /[\p{L}\p{N}]/

def values=(new_values)
  words = Array(new_values).flat_map { |value| value.to_s.split }
  return super(new_values) if words.empty?

  meaningful = words.grep(HAS_LETTER_OR_DIGIT)
  kept = (meaningful.presence || words).uniq(&:downcase).first(MAX_WORDS)
  super([kept.join(" ")])
end
```

<br>

<br>

### **Logs**

<br>

### Environment information

_Please check and fill out the following details to help us identify in what versions and distributions of OpenProject the error occurs_

**OpenProject installation type**

*   [ ] Cloud edition
*   [ ] On-Premise
*   [ ] Packaged installation
*   [x] Docker All-in-one container
*   [ ] Docker-compose installation
*   [ ] Other (please specify)

**OpenProject version**

v17.9.7

Code has not been modified up into the current v18 release branch

<br>

**Browser**

*   [x] Chrome
*   [ ] Firefox
*   [ ] Safari
*   [ ] Mobile Safari
*   [ ] Other (please specify)

**Operating System**

*   [ ] Windows
*   [ ] Mac OS X
*   [ ] Mobile iOS
*   [ ] Mobile Android
*   [ ] Linux (please specify distro)
*   [ ] Chrome OS
*   [ ] Other (please specify)

**Language**

*   [x] English
*   [ ] German
*   [ ] Other:
