Repository navigation
fix(search): find standard sections written as CWE-79 or ASVS V2.1.1 #1237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2735,6 +2735,8 @@ def text_search(self, text: str) -> List[Optional[cre_defs.Document]]: | |
| all entries of <name> and optionally, section/subsection | ||
| '\d\d\d-\d\d\d' (two sets of 3 digits) will first try to match | ||
| CRE ids before it performs a free text search | ||
| '<name> <sectionID>', e.g. 'CWE-79', 'CWE 79' or 'ASVS V2.1.1', will | ||
| search for that section of the node called <name> | ||
| Anything else will be a case insensitive LIKE query in the database | ||
| """ | ||
| search_terms = self._expand_text_search_aliases(text) | ||
|
|
@@ -2745,6 +2747,10 @@ def text_search(self, text: str) -> List[Optional[cre_defs.Document]]: | |
| cre_id_search = r"CRE(:| )(?P<id>\d+-\d+)" | ||
| cre_naked_id_search = r"\d\d\d-\d\d\d" | ||
| cre_name_search = r"CRE(:| )(?P<name>\w+)" | ||
| name_section_id_search = ( | ||
| r"(?P<name>[A-Za-z][\w.()&+/]*(?: [A-Za-z][\w.()&+/]*)*?)" | ||
| r"(?: *[:-] *| +)(?P<id>[A-Za-z]{0,3}\d[\w.-]*)" | ||
| ) | ||
| types = "|".join([v.value for v in cre_defs.Credoctypes]) | ||
| node_search = ( | ||
| r"(Node|(?P<ntype>" | ||
|
|
@@ -2791,6 +2797,18 @@ def text_search(self, text: str) -> List[Optional[cre_defs.Document]]: | |
| results.extend(nodes) | ||
| if results: | ||
| return list(set(results)) | ||
| # "<name> <sectionID>", the way people write e.g. "CWE-79" or "ASVS V2.1.1". | ||
| # The length check keeps the pattern cheap on long free text. | ||
| if len(text) <= 100: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try the named section before the naked CRE-ID shortcut. For Place the named-section lookup before that shortcut. Keep the existing CRE lookup when no named section matches.
|
||
| match = re.fullmatch(name_section_id_search, text) | ||
| if match: | ||
| nodes = self.get_nodes( | ||
| name=match.group("name"), | ||
| sectionID=match.group("id"), | ||
| ntype=None, # type: ignore | ||
| ) | ||
| if nodes: | ||
| return nodes | ||
| # fuzzy matches second | ||
| results = {} | ||
| for search_term in search_terms: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allow numeric and hyphenated tokens in standard names.
For a stored standard named
NIST 800-53 v5with section IDAC-1, the queryNIST 800-53 v5 AC-1cannot match this pattern. Each name token must start with a letter, and name tokens cannot contain hyphens. Free-text fallback also misses when no individual field contains the complete query.Support these standard names and add this case to the database test.