Skip to content

Commit 93d1f49

Browse files
AmateurECEfrantuma
authored andcommitted
Allow user to override the Code Point Limit required by SnakeYaml
With this patch, a user may set the system property 'maxYamlCodePoints' in order to override the default 3MiB limit configured in the org.yaml.snakeyaml package by default. This limit was implemented to prevent certain Denial-of-Service (DOS) attacks, but users should be given the opportunity to override this value for valid configurations which exceed the limit, such as the Redfish OpenAPI specification (developed by DMTF), which weighs in at 4.9MiB. This patch was tested to work with openapi-generator-cli v6.3.0. Signed-off-by: Ethan D. Twardy <[email protected]>
1 parent 3574a63 commit 93d1f49

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/DeserializationUtils.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static class Options {
4040
private Long maxYamlReferences = System.getProperty("maxYamlReferences") == null ? 10000000L : Long.valueOf(System.getProperty("maxYamlReferences"));
4141
private boolean validateYamlInput = System.getProperty("validateYamlInput") == null ? true : Boolean.valueOf(System.getProperty("validateYamlInput"));
4242
private boolean yamlCycleCheck = System.getProperty("yamlCycleCheck") == null ? true : Boolean.valueOf(System.getProperty("yamlCycleCheck"));
43-
43+
private Integer maxYamlCodePoints = System.getProperty("maxYamlCodePoints") == null ? 3 * 1024 * 1024 : Integer.valueOf(System.getProperty("maxYamlCodePoints"));
4444

4545
private Integer maxYamlAliasesForCollections = System.getProperty("maxYamlAliasesForCollections") == null ? Integer.MAX_VALUE : Integer.valueOf(System.getProperty("maxYamlAliasesForCollections"));
4646
private boolean yamlAllowRecursiveKeys = System.getProperty("yamlAllowRecursiveKeys") == null ? true : Boolean.valueOf(System.getProperty("yamlAllowRecursiveKeys"));
@@ -74,6 +74,8 @@ public boolean isYamlCycleCheck() {
7474
return yamlCycleCheck;
7575
}
7676

77+
public Integer getMaxYamlCodePoints() { return maxYamlCodePoints; }
78+
7779
public void setYamlCycleCheck(boolean yamlCycleCheck) {
7880
this.yamlCycleCheck = yamlCycleCheck;
7981
}
@@ -261,6 +263,8 @@ public static org.yaml.snakeyaml.Yaml buildSnakeYaml(BaseConstructor constructor
261263
method.invoke(loaderOptions, options.isYamlAllowRecursiveKeys());
262264
method = LoaderOptions.class.getMethod("setAllowDuplicateKeys", boolean.class);
263265
method.invoke(loaderOptions, false);
266+
method = LoaderOptions.class.getMethod("setCodePointLimit", int.class);
267+
method.invoke(loaderOptions, options.getMaxYamlCodePoints());
264268
org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml(constructor, new Representer(), new DumperOptions(), loaderOptions, new CustomResolver());
265269
return yaml;
266270
} catch (ReflectiveOperationException e) {

0 commit comments

Comments
 (0)