Skip to content

Commit

Permalink
add nesting level to yaml constructor (#286) (#289)
Browse files Browse the repository at this point in the history
Signed-off-by: Subhobrata Dey <[email protected]>
  • Loading branch information
opensearch-trigger-bot[bot] authored Jan 11, 2023
1 parent 4c89ba7 commit 3debc83
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
import org.opensearch.securityanalytics.rules.exceptions.SigmaLevelError;
import org.opensearch.securityanalytics.rules.exceptions.SigmaLogsourceError;
import org.opensearch.securityanalytics.rules.exceptions.SigmaStatusError;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;
import org.yaml.snakeyaml.representer.Representer;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -168,7 +171,10 @@ protected static SigmaRule fromDict(Map<String, Object> rule, boolean collectErr
}

public static SigmaRule fromYaml(String rule, boolean collectErrors) throws SigmaError {
Yaml yaml = new Yaml(new SafeConstructor());
LoaderOptions loaderOptions = new LoaderOptions();
loaderOptions.setNestingDepthLimit(10);

Yaml yaml = new Yaml(new SafeConstructor(), new Representer(), new DumperOptions(), loaderOptions);
Map<String, Object> ruleMap = yaml.load(rule);
return fromDict(ruleMap, collectErrors);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public static User randomUserEmpty() {
}

public static String randomDetectorType() {
return "TEST_WINDOWS";
return "test_windows";
}

public static DetectorInput randomDetectorInput() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,12 +585,12 @@ public void testDeletingADetector_single_ruleTopicIndex() throws IOException {
Response deleteResponse = makeRequest(client(), "DELETE", SecurityAnalyticsPlugin.DETECTOR_BASE_URI + "/" + detectorId1, Collections.emptyMap(), null);
Assert.assertEquals("Delete detector failed", RestStatus.OK, restStatus(deleteResponse));
// We deleted 1 detector, but 1 detector with same type exists, so we expect queryIndex to be present
Assert.assertTrue(doesIndexExist(String.format(Locale.getDefault(), ".opensearch-sap-%s-detectors-queries-000001", "test_windows")));
Assert.assertTrue(doesIndexExist(String.format(Locale.ROOT, ".opensearch-sap-%s-detectors-queries-000001", "test_windows")));

deleteResponse = makeRequest(client(), "DELETE", SecurityAnalyticsPlugin.DETECTOR_BASE_URI + "/" + detectorId2, Collections.emptyMap(), null);
Assert.assertEquals("Delete detector failed", RestStatus.OK, restStatus(deleteResponse));
// We deleted all detectors of type windows, so we expect that queryIndex is deleted
Assert.assertFalse(doesIndexExist(String.format(Locale.getDefault(), ".opensearch-sap-%s-detectors-queries-000001", "test_windows")));
Assert.assertFalse(doesIndexExist(String.format(Locale.ROOT, ".opensearch-sap-%s-detectors-queries-000001", "test_windows")));

request = "{\n" +
" \"query\" : {\n" +
Expand Down

0 comments on commit 3debc83

Please sign in to comment.