Repository navigation
Cap catalog search queries and trim words without a regex - #1501
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Catalog search trimmed the outer punctuation of every query word with
/^[^a-z0-9À-�]+|[^a-z0-9À-�]+$/g. That regex is quadratic on a long run of punctuation between two letters: 30k characters take ~300 ms, so a few hundred thousand would block the event loop for many seconds. The query comes from the shared MCP tools (search_tools), the catalog search API and the support chat, and none of them limits its length. Found by code scanning (polynomial ReDoS incatalog-search.ts).Changes
queryWordsreads at mostMAX_QUERY_LENGTH(500) characters of the query.packages/frontend/src/lib/catalog-search.tsis the same file (the spec checks that).toolPrefixFrom(File Search): runs of_are already collapsed to one, so the trim is/^_|_$/ginstead of/^_+|_+$/g. Same result; the second code scanning alert on that line was a false positive.Cloud and self-hosted behave the same: queries longer than 500 characters are matched on their first 500.
Type
Testing
New spec cases: trimming keeps inner punctuation (
s/4hana), the length cap, and an 800k-charactera!!!…aquery throughqueryWordsandsearchCatalogin under 1 s.In
packages/backend:npx jest src/adapters/catalog-search.spec.ts src/file-search/file-search-config.spec.ts --maxWorkers=2→ 104 passednpx eslinton the changed files → exit 0npx tsc --noEmit -p tsconfig.json→ exit 0In
packages/frontend:npx eslint src/lib/catalog-search.ts→ exit 0. The full suite runs in CI.Checklist
npm test)Related Issues
Code scanning alerts 655 and 656.