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 nesting level to yaml constructor #286

Merged
merged 3 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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