-
Notifications
You must be signed in to change notification settings - Fork 232
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
escaping not working properly for regex #1339
Comments
I test I think this occurs since any string needs to escape The rule of string escaping of STIX pattern is a little unclear to me:
It only rules I started a vote in the kestrel channel for users to throw their opinions. |
Seeing this issue as well, if an apostrophe is in the indicator it will crash. Example pattern: But this results in I have tried 1 - 6 escapes, and no go Thanks! |
@MaxwellDPS I think you find another issue, related. After some digging, I realize the issue I posted here is actually a design, not a bug. One can think the value string in STIX pattern the same grammar as Python string (with same escaping rules), so one really need to use
So we cannot do anything to improve the situation unless STIX pattern redefines value string not as escaped string. I am considering to provide that (non-escaped string) as default Kestrel value string to make it simpler for users. The problem you found is a real bug in stix-shifter implementation. Basically stix-shifter failed to parse escaped single quote (which is supposed to work with STIX pattern standard):
|
Escaping is complicated; each module needs to implement the escaping rules of the data source they will query. E.g. for elasticsearch:
See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_reserved_characters |
The earlier implementation might have missed some constraints. Escaping values needs to be fixed in query constructor based on the datasource query constraints that @pcoccoli mentioned: stix-shifter/stix_shifter_modules/elastic_ecs/stix_translation/query_constructor.py Line 69 in 8fed1fa
|
Add raw string support in Kestrel to resolve the four baskslash issue opencybersecurityalliance/kestrel-lang#329 . However, the |
Describe the bug
stix-shifter v4.6.0 requires 4 backslash chars to match 1 backslash char in data for regex, which should not be expected.
To Reproduce
Add the two test cases in
stix_shifter_modules/elastic_ecs/tests/stix_translation/test_elastic_ecs_stix_to_query.py
:Expected behavior
Both tests passed.
Error
The first passed, but not the second:
If you uncomment the line
It will work, which indicate one needs to use 4 backslashes to represent 1 backslash in data.
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: