The Unified and Autonomous Development Platform
Update httpclient and snakeyaml to avoid potential security vulnerabilities
Robin Shenef1f85b0951f
diff --git a/pom.xml b/pom.xmlindex b57749ca47..f932c2b98d 100644--- a/pom.xml+++ b/pom.xml@@ -307,7 +307,7 @@<dependency><groupId>org.apache.httpcomponents</groupId><artifactId>httpclient</artifactId>- <version>4.5.6</version>+ <version>4.5.13</version></dependency><dependency><groupId>org.glassfish.hk2</groupId>@@ -347,7 +347,7 @@<dependency><groupId>org.yaml</groupId><artifactId>snakeyaml</artifactId>- <version>1.21</version>+ <version>1.26</version></dependency><dependency><groupId>org.bouncycastle</groupId>diff --git a/server-core/src/main/java/org/yaml/snakeyaml/constructor/BaseConstructor.java b/server-core/src/main/java/org/yaml/snakeyaml/constructor/BaseConstructor.javaindex 8e00a0e33f..ede242b04f 100644--- a/server-core/src/main/java/org/yaml/snakeyaml/constructor/BaseConstructor.java+++ b/server-core/src/main/java/org/yaml/snakeyaml/constructor/BaseConstructor.java@@ -27,12 +27,14 @@ import java.util.LinkedHashMap;import java.util.LinkedHashSet;import java.util.List;import java.util.Map;+import java.util.NoSuchElementException;import java.util.Set;import java.util.SortedMap;import java.util.SortedSet;import java.util.TreeMap;import java.util.TreeSet;+import org.yaml.snakeyaml.LoaderOptions;import org.yaml.snakeyaml.TypeDescription;import org.yaml.snakeyaml.composer.Composer;import org.yaml.snakeyaml.composer.ComposerException;@@ -82,10 +84,18 @@ public abstract class BaseConstructor {private boolean explicitPropertyUtils;private boolean allowDuplicateKeys = true;+ private boolean wrappedToRootException = false;+protected final Map<Class<? extends Object>, TypeDescription> typeDefinitions;protected final Map<Tag, Class<? extends Object>> typeTags;+ protected LoaderOptions loadingConfig;+public BaseConstructor() {+ this(new LoaderOptions());+ }++ public BaseConstructor(LoaderOptions loadingConfig) {constructedObjects = new HashMap<Node, Object>();recursiveObjects = new HashSet<Node>();maps2fill = new ArrayList<RecursiveTuple<Map<Object, Object>, RecursiveTuple<Object, Object>>>();@@ -100,6 +110,7 @@ public abstract class BaseConstructor {TreeMap.class));typeDefinitions.put(SortedSet.class, new TypeDescription(SortedSet.class, Tag.SET,TreeSet.class));+ this.loadingConfig = loadingConfig;}public void setComposer(Composer composer) {@@ -121,9 +132,9 @@ public abstract class BaseConstructor {** @return constructed instance*/- public Object getData() {+ public Object getData() throws NoSuchElementException {// Construct and return the next document.- composer.checkNode();+ if (!composer.checkNode()) throw new NoSuchElementException("No document is available.");Node node = composer.getNode();if (rootTag != null) {node.setTag(rootTag);@@ -140,7 +151,7 @@ public abstract class BaseConstructor {*/public Object getSingleData(Class<?> type) {// Ensure that the stream contains a single document and construct it- Node node = composer.getSingleNode();+ final Node node = composer.getSingleNode();if (node != null && !Tag.NULL.equals(node.getTag())) {if (Object.class != type) {node.setTag(new Tag(type));@@ -148,8 +159,10 @@ public abstract class BaseConstructor {node.setTag(rootTag);}return constructDocument(node);+ } else {+ Construct construct = yamlConstructors.get(Tag.NULL);+ return construct.construct(node);}- return null;}/**@@ -160,13 +173,26 @@ public abstract class BaseConstructor {* @return Java instance*/protected final Object constructDocument(Node node) {- Object data = constructObject(node);- fillRecursive();- constructedObjects.clear();- recursiveObjects.clear();- return data;+ try {+ Object data = constructObject(node);+ fillRecursive();+ return data;+ } catch (RuntimeException e) {+ if (wrappedToRootException && !(e instanceof YAMLException)) {+ throw new YAMLException(e);+ } else {+ throw e;+ }+ } finally {+ //clean up resources+ constructedObjects.clear();+ recursiveObjects.clear();+ }}+ /**+ * Fill the recursive structures and clean the internal collections+ */private void fillRecursive() {if (!maps2fill.isEmpty()) {for (RecursiveTuple<Map<Object, Object>, RecursiveTuple<Object, Object>> entry : maps2fill) {@@ -472,21 +498,28 @@ public abstract class BaseConstructor {}Object value = constructObject(valueNode);if (keyNode.isTwoStepsConstruction()) {- /*- * if keyObject is created it 2 steps we should postpone putting- * it in map because it may have different hash after- * initialization compared to clean just created one. And map of- * course does not observe key hashCode changes.- */- maps2fill.add(0,- new RecursiveTuple<Map<Object, Object>, RecursiveTuple<Object, Object>>(- mapping, new RecursiveTuple<Object, Object>(key, value)));+ if (loadingConfig.getAllowRecursiveKeys()) {+ postponeMapFilling(mapping, key, value);+ } else {+ throw new YAMLException("Recursive key for mapping is detected but it is not configured to be allowed.");+ }} else {mapping.put(key, value);}}}+ /*+ * if keyObject is created it 2 steps we should postpone putting+ * it in map because it may have different hash after+ * initialization compared to clean just created one. And map of+ * course does not observe key hashCode changes.+ */+ @SuppressWarnings({ "rawtypes", "unchecked" })+ protected void postponeMapFilling(Map<Object, Object> mapping, Object key, Object value) {+ maps2fill.add(0, new RecursiveTuple(mapping, new RecursiveTuple(key, value)));+ }+protected void constructSet2ndStep(MappingNode node, Set<Object> set) {List<NodeTuple> nodeValue = node.getValue();for (NodeTuple tuple : nodeValue) {@@ -501,19 +534,23 @@ public abstract class BaseConstructor {}}if (keyNode.isTwoStepsConstruction()) {- /*- * if keyObject is created it 2 steps we should postpone putting- * it into the set because it may have different hash after- * initialization compared to clean just created one. And set of- * course does not observe value hashCode changes.- */- sets2fill.add(0, new RecursiveTuple<Set<Object>, Object>(set, key));+ postponeSetFilling(set, key);} else {set.add(key);}}}+ /*+ * if keyObject is created it 2 steps we should postpone putting+ * it into the set because it may have different hash after+ * initialization compared to clean just created one. And set of+ * course does not observe value hashCode changes.+ */+ protected void postponeSetFilling(Set<Object> set, Object key) {+ sets2fill.add(0, new RecursiveTuple<Set<Object>, Object>(set, key));+ }+// <<<< Costruct => NEW, 2ndStep(filling)// TODO protected List<Object[]> constructPairs(MappingNode node) {@@ -592,4 +629,12 @@ public abstract class BaseConstructor {public void setAllowDuplicateKeys(boolean allowDuplicateKeys) {this.allowDuplicateKeys = allowDuplicateKeys;}++ public boolean isWrappedToRootException() {+ return wrappedToRootException;+ }++ public void setWrappedToRootException(boolean wrappedToRootException) {+ this.wrappedToRootException = wrappedToRootException;+ }}diff --git a/server-core/src/main/java/org/yaml/snakeyaml/nodes/ScalarNode.java b/server-core/src/main/java/org/yaml/snakeyaml/nodes/ScalarNode.javaindex 2dc1de1318..a45526afe9 100644--- a/server-core/src/main/java/org/yaml/snakeyaml/nodes/ScalarNode.java+++ b/server-core/src/main/java/org/yaml/snakeyaml/nodes/ScalarNode.java@@ -49,6 +49,41 @@ public class ScalarNode extends Node {this.resolved = resolved;}+ /*+ * Existed in older versions but replaced with {@link DumperOptions.ScalarStyle}-based constructor.+ * Restored in v1.22 for backwards compatibility.+ * @deprecated Since restored in v1.22. Use {@link ScalarNode#ScalarNode(Tag, String, Mark, Mark, org.yaml.snakeyaml.DumperOptions.ScalarStyle) }.+ */+ @Deprecated+ public ScalarNode(Tag tag, String value, Mark startMark, Mark endMark, Character style) {+ this(tag, value, startMark, endMark, DumperOptions.ScalarStyle.createStyle(style));+ }++ /*+ * Existed in older versions but replaced with {@link DumperOptions.ScalarStyle}-based constructor.+ * Restored in v1.22 for backwards compatibility.+ * @deprecated Since restored in v1.22. Use {@link ScalarNode#ScalarNode(Tag, boolean, String, Mark, Mark, org.yaml.snakeyaml.DumperOptions.ScalarStyle) }.+ */+ @Deprecated+ public ScalarNode(Tag tag, boolean resolved, String value, Mark startMark, Mark endMark,+ Character style) {+ this(tag, resolved, value, startMark, endMark, DumperOptions.ScalarStyle.createStyle(style));+ }++ /**+ * Get scalar style of this node.+ *+ * @see org.yaml.snakeyaml.events.ScalarEvent+ * @see <a href="http://yaml.org/spec/1.1/#id903915">Chapter 9. Scalar+ * Styles</a>+ * @return style of this scalar node+ * @deprecated use getScalarStyle instead+ */+ @Deprecated+ public Character getStyle() {+ return style.getChar();+ }+/*** Get scalar style of this node.*@@ -57,7 +92,7 @@ public class ScalarNode extends Node {* Styles</a>* @return style of this scalar node*/- public DumperOptions.ScalarStyle getStyle() {+ public DumperOptions.ScalarStyle getScalarStyle() {return style;}diff --git a/server-core/src/main/java/org/yaml/snakeyaml/representer/Representer.java b/server-core/src/main/java/org/yaml/snakeyaml/representer/Representer.javaindex 42eb415642..b786dbcea2 100644--- a/server-core/src/main/java/org/yaml/snakeyaml/representer/Representer.java+++ b/server-core/src/main/java/org/yaml/snakeyaml/representer/Representer.java@@ -50,6 +50,11 @@ public class Representer extends SafeRepresenter {this.representers.put(null, new RepresentJavaBean());}+ public Representer(DumperOptions options) {+ super(options);+ this.representers.put(null, new RepresentJavaBean());+ }+public TypeDescription addTypeDescription(TypeDescription td) {if (Collections.EMPTY_MAP == typeDefinitions) {typeDefinitions = new HashMap<Class<? extends Object>, TypeDescription>();@@ -151,7 +156,8 @@ public class Representer extends SafeRepresenter {NodeId nodeId = nodeValue.getNodeId();if (customTag == null) {if (nodeId == NodeId.scalar) {- if (property.getType() == propertyValue.getClass()) {+ //generic Enum requires the full tag+ if (property.getType() != java.lang.Enum.class) {if (propertyValue instanceof Enum<?>) {nodeValue.setTag(Tag.STR);}