Skip to content

Commit 9857f51

Browse files
authored
Merge pull request #739 from marklogic/feature/21542-more-polaris
MLE-21542 More Polaris fixes
2 parents ba41cab + 024d2b2 commit 9857f51

File tree

13 files changed

+59
-37
lines changed

13 files changed

+59
-37
lines changed

ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/forests/ForestBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public ForestBuilder(ForestNamingStrategy forestNamingStrategy) {
5555
* @param appConfig
5656
* @return
5757
*/
58-
public List<Forest> buildForests(ForestPlan forestPlan, AppConfig appConfig) {
58+
public List<Forest> buildForests(ForestPlan forestPlan, final AppConfig appConfig) {
5959
final String databaseName = forestPlan.getDatabaseName();
6060
Objects.requireNonNull(databaseName);
6161
Objects.requireNonNull(appConfig);
@@ -85,6 +85,7 @@ public List<Forest> buildForests(ForestPlan forestPlan, AppConfig appConfig) {
8585
for (int i = 0; i < forestsToCreate; i++) {
8686
forestCounter++;
8787
Forest forest = newForest(forestPlan);
88+
Objects.requireNonNull(forest);
8889
forest.setForestName(getForestName(databaseName, forestCounter, appConfig));
8990
forest.setHost(hostName);
9091
forest.setDatabase(databaseName);

ml-app-deployer/src/main/java/com/marklogic/mgmt/resource/forests/ForestManager.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
import com.marklogic.mgmt.resource.AbstractResourceManager;
2727
import com.marklogic.rest.util.Fragment;
2828
import com.marklogic.rest.util.XPathUtil;
29-
import org.springframework.http.HttpMethod;
30-
import org.springframework.web.util.UriComponentsBuilder;
3129

3230
import java.util.ArrayList;
3331
import java.util.HashMap;

ml-app-deployer/src/main/java/com/marklogic/mgmt/resource/security/AmpManager.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import com.marklogic.rest.util.XPathUtil;
2525
import org.springframework.http.ResponseEntity;
2626

27-
import javax.xml.xpath.XPath;
2827
import java.util.ArrayList;
2928
import java.util.List;
3029

ml-app-deployer/src/main/java/com/marklogic/rest/util/Fragment.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,15 @@
1515
*/
1616
package com.marklogic.rest.util;
1717

18+
import com.marklogic.client.ext.util.XmlUtil;
1819
import org.jdom2.Document;
1920
import org.jdom2.Element;
2021
import org.jdom2.Namespace;
2122
import org.jdom2.filter.Filters;
22-
import org.jdom2.input.SAXBuilder;
23-
import org.jdom2.input.sax.XMLReaders;
2423
import org.jdom2.output.Format;
2524
import org.jdom2.output.XMLOutputter;
2625
import org.jdom2.xpath.XPathExpression;
2726
import org.jdom2.xpath.XPathFactory;
28-
import org.xml.sax.InputSource;
2927

3028
import java.io.StringReader;
3129
import java.util.ArrayList;
@@ -45,19 +43,7 @@ public Fragment(Fragment other) {
4543

4644
public Fragment(String xml, Namespace... namespaces) {
4745
try {
48-
SAXBuilder builder = new SAXBuilder(XMLReaders.NONVALIDATING);
49-
50-
// Prevent DTDs from being loaded
51-
builder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
52-
53-
// Disable external entities
54-
builder.setFeature("http://xml.org/sax/features/external-general-entities", false);
55-
builder.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
56-
57-
// Set a no-op EntityResolver to block external DTDs
58-
builder.setEntityResolver((publicId, systemId) -> new InputSource(new StringReader("")));
59-
60-
internalDoc = builder.build(new StringReader(xml));
46+
internalDoc = XmlUtil.newSAXBuilder().build(new StringReader(xml));
6147
List<Namespace> list = new ArrayList<>();
6248
list.add(Namespace.getNamespace("arp", "http://marklogic.com/manage/alert-rule/properties"));
6349
list.add(Namespace.getNamespace("c", "http://marklogic.com/manage/clusters"));

ml-app-deployer/src/main/java/com/marklogic/rest/util/XPathUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ public abstract class XPathUtil {
1212
* @return
1313
*/
1414
public static String sanitizeValueForXPathExpression(String resourceIdOrName) {
15-
// MarkLogic generally the following characters in a resource name, and we know an ID will never have them.
16-
// Removing them avoids issues with XPath queries.
15+
// MarkLogic generally prohibits the following characters in a resource name, and we know an ID will never
16+
// have them. Removing them avoids issues with XPath injection attacks.
1717
return resourceIdOrName != null ?
1818
resourceIdOrName.replace("'", "").replace("\"", "").replace("[", "").replace("]", "") :
1919
null;

ml-app-deployer/src/test/java/com/marklogic/junit/Fragment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
*/
1616
package com.marklogic.junit;
1717

18+
import com.marklogic.client.ext.util.XmlUtil;
1819
import org.jdom2.Document;
1920
import org.jdom2.Element;
2021
import org.jdom2.Namespace;
2122
import org.jdom2.filter.Filters;
22-
import org.jdom2.input.SAXBuilder;
2323
import org.jdom2.output.Format;
2424
import org.jdom2.output.XMLOutputter;
2525
import org.jdom2.xpath.XPathExpression;
@@ -51,7 +51,7 @@ public Fragment(Document doc) {
5151

5252
public Fragment(String xml, Namespace... namespaces) {
5353
try {
54-
internalDoc = new SAXBuilder().build(new StringReader(xml));
54+
internalDoc = XmlUtil.newSAXBuilder().build(new StringReader(xml));
5555
this.namespaces = namespaces;
5656
} catch (Exception e) {
5757
throw new RuntimeException(e);

ml-javaclient-util/src/main/java/com/marklogic/client/ext/es/EntityServicesManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818
import com.marklogic.client.DatabaseClient;
1919
import com.marklogic.client.document.GenericDocumentManager;
20+
import com.marklogic.client.ext.util.XmlUtil;
2021
import com.marklogic.client.io.BytesHandle;
2122
import com.marklogic.client.io.DocumentMetadataHandle;
2223
import org.jdom2.Element;
2324
import org.jdom2.Namespace;
24-
import org.jdom2.input.SAXBuilder;
2525

2626
import java.io.StringReader;
2727
import java.util.Objects;
@@ -93,7 +93,7 @@ protected GeneratedCode initializeGeneratedCode(String modelUri) {
9393
Objects.requireNonNull(output);
9494
Element root;
9595
try {
96-
root = new SAXBuilder().build(new StringReader(output)).getRootElement();
96+
root = XmlUtil.newSAXBuilder().build(new StringReader(output)).getRootElement();
9797
} catch (Exception e) {
9898
throw new RuntimeException("Unable to parse model XML: " + e.getMessage(), e);
9999
}

ml-javaclient-util/src/main/java/com/marklogic/client/ext/modulesloader/impl/DefaultExtensionMetadataProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import com.marklogic.client.ext.helper.LoggingObject;
2424
import com.marklogic.client.ext.modulesloader.ExtensionMetadataAndParams;
2525
import com.marklogic.client.ext.modulesloader.ExtensionMetadataProvider;
26+
import com.marklogic.client.ext.util.XmlUtil;
2627
import org.jdom2.Element;
27-
import org.jdom2.input.SAXBuilder;
2828
import org.jdom2.output.XMLOutputter;
2929
import org.springframework.core.io.Resource;
3030
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
@@ -62,7 +62,7 @@ public ExtensionMetadataAndParams provideExtensionMetadataAndParams(Resource r)
6262
Resource metadataResource = resolver.getResource(metadataFile);
6363
if (metadataResource != null) {
6464
try {
65-
Element root = new SAXBuilder().build(metadataResource.getInputStream()).getRootElement();
65+
Element root = XmlUtil.newSAXBuilder().build(metadataResource.getInputStream()).getRootElement();
6666
m.setTitle(root.getChildText("title"));
6767
Element desc = root.getChild("description");
6868
if (desc != null && desc.getChildren() != null && desc.getChildren().size() == 1) {

ml-javaclient-util/src/main/java/com/marklogic/client/ext/modulesloader/impl/DefaultModulesLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
import com.marklogic.client.ext.helper.LoggingObject;
2929
import com.marklogic.client.ext.modulesloader.*;
3030
import com.marklogic.client.ext.tokenreplacer.TokenReplacer;
31+
import com.marklogic.client.ext.util.XmlUtil;
3132
import com.marklogic.client.io.Format;
3233
import com.marklogic.client.io.StringHandle;
3334
import org.jdom2.Element;
34-
import org.jdom2.input.SAXBuilder;
3535
import org.springframework.beans.factory.DisposableBean;
3636
import org.springframework.core.io.Resource;
3737
import org.springframework.core.task.SyncTaskExecutor;
@@ -319,7 +319,7 @@ protected void applyJsonProperties(ServerConfigurationManager mgr, Resource r, F
319319
protected void applyXmlProperties(ServerConfigurationManager mgr, Resource r, File file) {
320320
Element root;
321321
try {
322-
root = new SAXBuilder().build(r.getInputStream()).getRootElement();
322+
root = XmlUtil.newSAXBuilder().build(r.getInputStream()).getRootElement();
323323
} catch (Exception e) {
324324
throw new RuntimeException("Unable to read XML REST properties file: " + file.getAbsolutePath(), e);
325325
}

ml-javaclient-util/src/main/java/com/marklogic/client/ext/schemasloader/impl/QbvDocumentFileProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
import com.marklogic.client.ext.file.DocumentFileProcessor;
2323
import com.marklogic.client.ext.helper.FilenameUtil;
2424
import com.marklogic.client.ext.helper.LoggingObject;
25+
import com.marklogic.client.ext.util.XmlUtil;
2526
import com.marklogic.client.extra.jdom.JDOMHandle;
2627
import com.marklogic.client.io.Format;
2728
import com.marklogic.client.io.StringHandle;
2829
import org.jdom2.Document;
2930
import org.jdom2.Element;
30-
import org.jdom2.input.SAXBuilder;
3131
import org.springframework.util.FileCopyUtils;
3232

3333
import java.io.File;
@@ -99,7 +99,7 @@ private void processQbvFile(DocumentFile qbvFile) {
9999
if (Format.XML.equals(handleString.getFormat())) {
100100
Document xmlDocument;
101101
try {
102-
xmlDocument = new SAXBuilder().build(new StringReader(handleString.get()));
102+
xmlDocument = XmlUtil.newSAXBuilder().build(new StringReader(handleString.get()));
103103
} catch (Exception e) {
104104
throw new RuntimeException(format("Query-Based View generation failed for file: %s; cause: %s", qbvFile.getFile().getAbsolutePath(), e.getMessage()));
105105
}

0 commit comments

Comments
 (0)