Skip to content
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

Add throw for empty strings in rules with modifier contains, startwith, and endswith #860

Merged
merged 4 commits into from
Mar 6, 2024

Conversation

jowg-amazon
Copy link
Collaborator

@jowg-amazon jowg-amazon commented Feb 16, 2024

Description

Currently an array out of bounds exception is thrown when a rule tries to be created on an empty string when modifiers contains, startswith and endswith are used. This PR checks for this condition and throws a more descriptive and user friendly error to the front end.

Issues Resolved

[List any issues this PR will resolve]

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link

codecov bot commented Feb 16, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (e3362f6) 24.83% compared to head (b1bf251) 24.84%.
Report is 2 commits behind head on main.

Files Patch % Lines
...ityanalytics/rules/objects/SigmaDetectionItem.java 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main     #860   +/-   ##
=========================================
  Coverage     24.83%   24.84%           
- Complexity     1030     1035    +5     
=========================================
  Files           277      277           
  Lines         12713    12721    +8     
  Branches       1401     1403    +2     
=========================================
+ Hits           3157     3160    +3     
- Misses         9292     9296    +4     
- Partials        264      265    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jowg-amazon jowg-amazon changed the title Add validation for empty strings in rules Add throw for empty strings in rules with modifier contains, startwith, and endswith Feb 17, 2024
Signed-off-by: Joanne Wang <[email protected]>
SigmaType sigmaType = SigmaTypeFacade.sigmaType(v);
// throws an error if sigmaType is an empty string and the modifier is "contains" or "startswith" or "endswith"
boolean invalidModifierWithEmptyString = modifierIds.contains("contains") || modifierIds.contains("startswith") || modifierIds.contains("endswith");
if (sigmaType.getClass().equals(SigmaString.class) && v.toString().isEmpty() && invalidModifierWithEmptyString) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen to the other values? Should we skip the empty strings and use values which are present in the list?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We decided to throw an exception instead of skipping the empty string here because if we allowed the rule creation to go through, the empty string would still appear in the rule itself but could not be turned into a meaningful/correct query.

Instead we added additional parsing logic on the front end to ensure that empty strings get parsed out when creating a rule from the UI. This PR is an additional check if the rule gets created from the API directly.

@goyamegh goyamegh merged commit f4ee7bb into opensearch-project:main Mar 6, 2024
18 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Mar 7, 2024
…h, and endswith (#860)

* add validation for empty strings with contains, startswith and endswith modifiers

Signed-off-by: Joanne Wang <[email protected]>

* throw exception if empty string with contains, startswith, or endswith

Signed-off-by: Joanne Wang <[email protected]>

* change var name

Signed-off-by: Joanne Wang <[email protected]>

* add modifiers to log

Signed-off-by: Joanne Wang <[email protected]>

---------

Signed-off-by: Joanne Wang <[email protected]>
(cherry picked from commit f4ee7bb)
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.8 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.8 2.8
# Navigate to the new working tree
cd .worktrees/backport-2.8
# Create a new branch
git switch --create backport/backport-860-to-2.8
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 f4ee7bb9118a35ff4706a9e36abb9f2b042c069f
# Push it to GitHub
git push --set-upstream origin backport/backport-860-to-2.8
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.8

Then, create a pull request where the base branch is 2.8 and the compare/head branch is backport/backport-860-to-2.8.

@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.6 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.6 2.6
# Navigate to the new working tree
cd .worktrees/backport-2.6
# Create a new branch
git switch --create backport/backport-860-to-2.6
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 f4ee7bb9118a35ff4706a9e36abb9f2b042c069f
# Push it to GitHub
git push --set-upstream origin backport/backport-860-to-2.6
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.6

Then, create a pull request where the base branch is 2.6 and the compare/head branch is backport/backport-860-to-2.6.

@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.10 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.10 2.10
# Navigate to the new working tree
cd .worktrees/backport-2.10
# Create a new branch
git switch --create backport/backport-860-to-2.10
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 f4ee7bb9118a35ff4706a9e36abb9f2b042c069f
# Push it to GitHub
git push --set-upstream origin backport/backport-860-to-2.10
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.10

Then, create a pull request where the base branch is 2.10 and the compare/head branch is backport/backport-860-to-2.10.

opensearch-trigger-bot bot pushed a commit that referenced this pull request Mar 7, 2024
…h, and endswith (#860)

* add validation for empty strings with contains, startswith and endswith modifiers

Signed-off-by: Joanne Wang <[email protected]>

* throw exception if empty string with contains, startswith, or endswith

Signed-off-by: Joanne Wang <[email protected]>

* change var name

Signed-off-by: Joanne Wang <[email protected]>

* add modifiers to log

Signed-off-by: Joanne Wang <[email protected]>

---------

Signed-off-by: Joanne Wang <[email protected]>
(cherry picked from commit f4ee7bb)
jowg-amazon added a commit to jowg-amazon/security-analytics that referenced this pull request Mar 7, 2024
…h, and endswith (opensearch-project#860)

* add validation for empty strings with contains, startswith and endswith modifiers

Signed-off-by: Joanne Wang <[email protected]>

* throw exception if empty string with contains, startswith, or endswith

Signed-off-by: Joanne Wang <[email protected]>

* change var name

Signed-off-by: Joanne Wang <[email protected]>

* add modifiers to log

Signed-off-by: Joanne Wang <[email protected]>

---------

Signed-off-by: Joanne Wang <[email protected]>
eirsep pushed a commit to eirsep/security-analytics that referenced this pull request Mar 7, 2024
…h, and endswith (opensearch-project#860)

* add validation for empty strings with contains, startswith and endswith modifiers

Signed-off-by: Joanne Wang <[email protected]>

* throw exception if empty string with contains, startswith, or endswith

Signed-off-by: Joanne Wang <[email protected]>

* change var name

Signed-off-by: Joanne Wang <[email protected]>

* add modifiers to log

Signed-off-by: Joanne Wang <[email protected]>

---------

Signed-off-by: Joanne Wang <[email protected]>
eirsep pushed a commit to eirsep/security-analytics that referenced this pull request Mar 8, 2024
…h, and endswith (opensearch-project#860)

* add validation for empty strings with contains, startswith and endswith modifiers

Signed-off-by: Joanne Wang <[email protected]>

* throw exception if empty string with contains, startswith, or endswith

Signed-off-by: Joanne Wang <[email protected]>

* change var name

Signed-off-by: Joanne Wang <[email protected]>

* add modifiers to log

Signed-off-by: Joanne Wang <[email protected]>

---------

Signed-off-by: Joanne Wang <[email protected]>
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.x 2.x
# Navigate to the new working tree
cd .worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-860-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 f4ee7bb9118a35ff4706a9e36abb9f2b042c069f
# Push it to GitHub
git push --set-upstream origin backport/backport-860-to-2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-860-to-2.x.

jowg-amazon added a commit to jowg-amazon/security-analytics that referenced this pull request Mar 8, 2024
…h, and endswith (opensearch-project#860)

* add validation for empty strings with contains, startswith and endswith modifiers

Signed-off-by: Joanne Wang <[email protected]>

* throw exception if empty string with contains, startswith, or endswith

Signed-off-by: Joanne Wang <[email protected]>

* change var name

Signed-off-by: Joanne Wang <[email protected]>

* add modifiers to log

Signed-off-by: Joanne Wang <[email protected]>

---------

Signed-off-by: Joanne Wang <[email protected]>
jowg-amazon added a commit that referenced this pull request Mar 8, 2024
…h, and endswith (#860) (#896)

* add validation for empty strings with contains, startswith and endswith modifiers



* throw exception if empty string with contains, startswith, or endswith



* change var name



* add modifiers to log



---------

Signed-off-by: Joanne Wang <[email protected]>
sbcd90 pushed a commit to sbcd90/security-analytics that referenced this pull request Mar 10, 2024
Signed-off-by: Joanne Wang <[email protected]>
(cherry picked from commit 4d4f5e3)

Co-authored-by: Joanne Wang <[email protected]>

Reduce log level for informative message (opensearch-project#203) (opensearch-project#833)

Signed-off-by: Enrico Tröger <[email protected]>
Co-authored-by: Enrico Tröger <[email protected]>

Updated alert creation following common-utils PR 584. (opensearch-project#837) (opensearch-project#839)

Signed-off-by: AWSHurneyt <[email protected]>
(cherry picked from commit 8adb9c3)

Co-authored-by: AWSHurneyt <[email protected]>

Release notes for 2.12.0 (opensearch-project#834) (opensearch-project#841)

* release notes for 2.12

Signed-off-by: Joanne Wang <[email protected]>

* update release notes

Signed-off-by: Joanne Wang <[email protected]>

* update release notes

Signed-off-by: Joanne Wang <[email protected]>

---------

Signed-off-by: Joanne Wang <[email protected]>
(cherry picked from commit 414484a)

Co-authored-by: Joanne Wang <[email protected]>

Remove blocking calls and change threat intel feed flow to event driven (opensearch-project#871) (opensearch-project#876)

* remove actionGet() and change threat intel feed flow to event driven

Signed-off-by: Surya Sashank Nistala <[email protected]>

* fix javadocs

Signed-off-by: Surya Sashank Nistala <[email protected]>

* revert try catch removals

Signed-off-by: Surya Sashank Nistala <[email protected]>

* use action listener wrap() in detector threat intel code paths

Signed-off-by: Surya Sashank Nistala <[email protected]>

* add try catch

Signed-off-by: Surya Sashank Nistala <[email protected]>

---------

Signed-off-by: Surya Sashank Nistala <[email protected]>
(cherry picked from commit 172d58d)

Co-authored-by: Surya Sashank Nistala <[email protected]>

Fail the flow the when detectot type is missing in the log types index (opensearch-project#845) (opensearch-project#857)

Signed-off-by: Megha Goyal <[email protected]>
(cherry picked from commit 8d19912)

Co-authored-by: Megha Goyal <[email protected]>

[BUG] ArrayIndexOutOfBoundsException for inconsistent detector index behavior  (opensearch-project#843) (opensearch-project#858)

* Catch ArrayIndexOutOfBoundsException when detector is missing

Signed-off-by: Megha Goyal <[email protected]>

* Add a check on SearchHits.getHits() length

Signed-off-by: Megha Goyal <[email protected]>

* Remove index out of bounds exception

Signed-off-by: Megha Goyal <[email protected]>

---------

Signed-off-by: Megha Goyal <[email protected]>
(cherry picked from commit 0ef8543)

Co-authored-by: Megha Goyal <[email protected]>

Backport opensearch-project#873 and opensearch-project#789 (opensearch-project#895)

* support object fields in aggregation based sigma rules (opensearch-project#789)

Signed-off-by: Subhobrata Dey <[email protected]>

* Pass rule field names in doc level queries during monitor/creation. Remove blocking actionGet() calls  (opensearch-project#873)

* pass query field names in doc level queries during monitor creation/updation

Signed-off-by: Surya Sashank Nistala <[email protected]>

* remove actionGet() and change get index mapping call to event driven flow

Signed-off-by: Surya Sashank Nistala <[email protected]>

* fix chained findings monitor

Signed-off-by: Surya Sashank Nistala <[email protected]>

* add finding mappings

Signed-off-by: Surya Sashank Nistala <[email protected]>

* remove test messages from logs

Signed-off-by: Surya Sashank Nistala <[email protected]>

* revert build.gradle change

Signed-off-by: Surya Sashank Nistala <[email protected]>

---------

Signed-off-by: Surya Sashank Nistala <[email protected]>

---------

Signed-off-by: Subhobrata Dey <[email protected]>
Signed-off-by: Surya Sashank Nistala <[email protected]>
Co-authored-by: Subhobrata Dey <[email protected]>

Fix duplicate ecs mappings which returns incorrect log index field in mapping view API (opensearch-project#786) (opensearch-project#788) (opensearch-project#898)

* field mapping changes

* add integ test

* turn unmappedfieldaliases as set and add integ test

* add comments

* fix integ tests

* moved logic to method for better readability

---------

Signed-off-by: Joanne Wang <[email protected]>

Add throw for empty strings in rules with modifier contains, startwith, and endswith (opensearch-project#860) (opensearch-project#896)

* add validation for empty strings with contains, startswith and endswith modifiers

* throw exception if empty string with contains, startswith, or endswith

* change var name

* add modifiers to log

---------

Signed-off-by: Joanne Wang <[email protected]>

Add an "exists" check for "not" condition in sigma rules (opensearch-project#852) (opensearch-project#897)

* test design

Signed-off-by: Joanne Wang <[email protected]>

* working version

Signed-off-by: Joanne Wang <[email protected]>

* cleaning up

Signed-off-by: Joanne Wang <[email protected]>

* testing

Signed-off-by: Joanne Wang <[email protected]>

* working version

Signed-off-by: Joanne Wang <[email protected]>

* working version

Signed-off-by: Joanne Wang <[email protected]>

* refactored querybackend

Signed-off-by: Joanne Wang <[email protected]>

* working on tests

Signed-off-by: Joanne Wang <[email protected]>

* fixed alerting and finding tests

Signed-off-by: Joanne Wang <[email protected]>

* fix correlation tests

Signed-off-by: Joanne Wang <[email protected]>

* working all tests

Signed-off-by: Joanne Wang <[email protected]>

* moved test and changed alias for adldap

Signed-off-by: Joanne Wang <[email protected]>

* added more tests

Signed-off-by: Joanne Wang <[email protected]>

* cleanup code

Signed-off-by: Joanne Wang <[email protected]>

* remove exists flag

Signed-off-by: Joanne Wang <[email protected]>

---------

Signed-off-by: Joanne Wang <[email protected]>
(cherry picked from commit 656a5fe)

Co-authored-by: Joanne Wang <[email protected]>

Add goyamegh as a maintainer (opensearch-project#868) (opensearch-project#899)

Signed-off-by: Megha Goyal <[email protected]>

Refactor invocation of Action listeners in correlations (opensearch-project#880) (opensearch-project#900)

* Refactor invocation of Action listeners in correlations

* Close hanging tasks in correlations workflow

* Logging finding id and monitor id in error logs

---------

Signed-off-by: Megha Goyal <[email protected]>

Add search request timeouts for correlations workflows (opensearch-project#893) (opensearch-project#901)

* Reinstating more leaks plugged-in for correlations workflows

Signed-off-by: Megha Goyal <[email protected]>

* Add search timeouts to all correlation searches

Signed-off-by: Megha Goyal <[email protected]>

* Fix logging and exception messages

Signed-off-by: Megha Goyal <[email protected]>

* Change search timeout to 30 seconds

Signed-off-by: Megha Goyal <[email protected]>

---------

Signed-off-by: Megha Goyal <[email protected]>
(cherry picked from commit 75c4429)

Co-authored-by: Megha Goyal <[email protected]>
opensearch-trigger-bot bot pushed a commit that referenced this pull request Mar 11, 2024
…h, and endswith (#860)

* add validation for empty strings with contains, startswith and endswith modifiers

Signed-off-by: Joanne Wang <[email protected]>

* throw exception if empty string with contains, startswith, or endswith

Signed-off-by: Joanne Wang <[email protected]>

* change var name

Signed-off-by: Joanne Wang <[email protected]>

* add modifiers to log

Signed-off-by: Joanne Wang <[email protected]>

---------

Signed-off-by: Joanne Wang <[email protected]>
(cherry picked from commit f4ee7bb)
opensearch-trigger-bot bot pushed a commit that referenced this pull request Mar 11, 2024
…h, and endswith (#860)

* add validation for empty strings with contains, startswith and endswith modifiers

Signed-off-by: Joanne Wang <[email protected]>

* throw exception if empty string with contains, startswith, or endswith

Signed-off-by: Joanne Wang <[email protected]>

* change var name

Signed-off-by: Joanne Wang <[email protected]>

* add modifiers to log

Signed-off-by: Joanne Wang <[email protected]>

---------

Signed-off-by: Joanne Wang <[email protected]>
(cherry picked from commit f4ee7bb)
jowg-amazon added a commit that referenced this pull request Mar 12, 2024
…h, and endswith (#860) (#885)

* add validation for empty strings with contains, startswith and endswith modifiers

Signed-off-by: Joanne Wang <[email protected]>

* throw exception if empty string with contains, startswith, or endswith

Signed-off-by: Joanne Wang <[email protected]>

* change var name

Signed-off-by: Joanne Wang <[email protected]>

* add modifiers to log

Signed-off-by: Joanne Wang <[email protected]>

---------

Signed-off-by: Joanne Wang <[email protected]>
(cherry picked from commit f4ee7bb)

Co-authored-by: Joanne Wang <[email protected]>
jowg-amazon added a commit that referenced this pull request Mar 12, 2024
…h, and endswith (#860) (#886)

* add validation for empty strings with contains, startswith and endswith modifiers

Signed-off-by: Joanne Wang <[email protected]>

* throw exception if empty string with contains, startswith, or endswith

Signed-off-by: Joanne Wang <[email protected]>

* change var name

Signed-off-by: Joanne Wang <[email protected]>

* add modifiers to log

Signed-off-by: Joanne Wang <[email protected]>

---------

Signed-off-by: Joanne Wang <[email protected]>
(cherry picked from commit f4ee7bb)

Co-authored-by: Joanne Wang <[email protected]>
jowg-amazon added a commit that referenced this pull request Mar 12, 2024
…h, and endswith (#860) (#911)

* add validation for empty strings with contains, startswith and endswith modifiers

Signed-off-by: Joanne Wang <[email protected]>

* throw exception if empty string with contains, startswith, or endswith

Signed-off-by: Joanne Wang <[email protected]>

* change var name

Signed-off-by: Joanne Wang <[email protected]>

* add modifiers to log

Signed-off-by: Joanne Wang <[email protected]>

---------

Signed-off-by: Joanne Wang <[email protected]>
(cherry picked from commit f4ee7bb)

Co-authored-by: Joanne Wang <[email protected]>
jowg-amazon added a commit that referenced this pull request Mar 12, 2024
…h, and endswith (#860) (#912)

* add validation for empty strings with contains, startswith and endswith modifiers

Signed-off-by: Joanne Wang <[email protected]>

* throw exception if empty string with contains, startswith, or endswith

Signed-off-by: Joanne Wang <[email protected]>

* change var name

Signed-off-by: Joanne Wang <[email protected]>

* add modifiers to log

Signed-off-by: Joanne Wang <[email protected]>

---------

Signed-off-by: Joanne Wang <[email protected]>
(cherry picked from commit f4ee7bb)

Co-authored-by: Joanne Wang <[email protected]>
opensearch-trigger-bot bot added a commit that referenced this pull request Mar 14, 2024
…h, and endswith (#860) (#885)

* add validation for empty strings with contains, startswith and endswith modifiers

Signed-off-by: Joanne Wang <[email protected]>

* throw exception if empty string with contains, startswith, or endswith

Signed-off-by: Joanne Wang <[email protected]>

* change var name

Signed-off-by: Joanne Wang <[email protected]>

* add modifiers to log

Signed-off-by: Joanne Wang <[email protected]>

---------

Signed-off-by: Joanne Wang <[email protected]>
(cherry picked from commit f4ee7bb)

Co-authored-by: Joanne Wang <[email protected]>
(cherry picked from commit efade2c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants