text_search: one-letter or wildcard queries load almost the whole database (90s+), and the search box doesn't encode the term
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 70/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python, react, typescript
- Domain
- backend, frontend, performance
Research direction
Start in application/database/db.py at Node_collection.text_search(), where the term is interpolated into a LIKE pattern six times; add escaping for % and _, a minimum length for the fuzzy part and a row limit. Then fix the client in SearchBar.tsx and Search.tsx, wrapping the term in encodeURIComponent before history.push. Confirm by timing /rest/v1/text_search for session, e, % and _ and checking that /search/C%23 reaches the backend intact. The issue leaves the choice of fixes open, so agree the approach with a maintainer first.
Written by the indexing model from the issue text.
Description
Problem
A very short search makes /rest/v1/text_search return almost everything in the database and takes minutes.
Tested on my local setup (staging at d9514e52, full upstream sync: 522 CREs, 2841 nodes):
| Request | Time | Response |
|---|---|---|
text_search?text=session |
2.3 s | 215 KB |
text_search?text=e |
89 s | 8.4 MB, 3311 of 3363 rows |
text_search?text=% |
no response after 180 s | - |
text_search?text=_ |
no response after 180 s | - |
In the UI, searching for e loads for a long time and then shows "The document could not be loaded".
I did not test this on opencre.org on purpose, so I don't load the live server.
Cause
In Node_collection.text_search() (application/database/db.py), the fuzzy search does:
args = [f"%{search_term}%", "", "", "", "", ""]
- The term is used directly in
LIKE, so%and_are not escaped.text=%becomes%%%and matches every row. - There is no limit on results, so a common letter like
ematches almost all nodes and CREs. - The 6 permutations run one query per column (name, section, subsection, link, description, sectionID), and each one loads all of its matches.
Because /rest/v1/text_search is public, a few of these requests can keep the server busy.
Related: the search box doesn't encode the term
SearchBar.tsx and Search.tsx do:
history.push(`${SEARCH}/${term}`);
The term is not passed through encodeURIComponent, so:
%throwsUncaught URIError: Pathname "/search/%" could not be decodedand nothing happensC#becomes/search/C#, so it searches forC, which triggers the slow one-letter search above
Possible fixes
- Escape
%and_in the search term before building theLIKEpattern - Require a minimum length for the fuzzy part (for example 2 or 3 characters)
- Limit the number of fuzzy results
- Encode the term in the search box with
encodeURIComponent
I'm happy to work on this. Which of these would you like, and should the PR target main or staging?
- Dominant language
- Python
- Stars
- 216
- Forks
- 173
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 21
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from OWASP/OpenCRE
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
OWASP/OpenCRE#1232 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
OWASP/OpenCRE#1228 · 1 comment ·
Maintainers usually reply within 1 day
-
Incorrect inverse relationship type in CRE internal-link exportMay be free again @saicharan-r02 claimed this 8 days ago, and no pull request is open. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OWASP/OpenCRE#1215 · 3 comments ·
Maintainers usually reply within 1 day
-
Map Analysis continues polling after a background job failsPossibly taken @abhi2005-bit claimed this 10 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
OWASP/OpenCRE#1211 · 2 comments ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
marketcalls/openalgo#2502 ·
Maintainers usually reply within 1 day
-
test_a_503_raises_unavailable_error fails on macOS about one run in sixPossibly taken @naman-modi claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Deltakit/deltakit-compile#27 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
vllm-project/vllm#69791 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100