Skip to content

Feature/api xml properties#464

Closed
apeiris wants to merge 3 commits into
OpenAS2:masterfrom
apeiris:feature/api-xml-properties
Closed

Feature/api xml properties#464
apeiris wants to merge 3 commits into
OpenAS2:masterfrom
apeiris:feature/api-xml-properties

Conversation

@apeiris

@apeiris apeiris commented Aug 21, 2025

Copy link
Copy Markdown
Contributor

Summary

  • Added /getPropertyList endpoint to return application properties as JSON
  • Added /getXml endpoint to query XML files with XPath and return results
  • Refactored imports in ApiResource.java for cleanup and consistency

Testing

  • Verified new endpoints return expected JSON/XML responses

- Added XXE protection by disabling DOCTYPE, external entities, and DTD loading.
- Added logging for XML parsing errors instead of silently returning null.
File file = new File(xmlFileName);
Document document = db.parse(file);

XPathExpression xPathExpr = XPathFactory.newInstance().newXPath().compile(xpathExpression);

Check failure

Code scanning / CodeQL

XPath injection Critical

XPath expression depends on a
user-provided value
.

@uhurusurfa uhurusurfa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be helpful if you could provide the use case for retrieving an XML document. In the case of the config.xml, it contains sensitive information and not sure what the benefit is for the app user.

Comment thread .gitignore
Comment on lines +15 to +18
/Server/src/config/config.xml
/Server/src/test/resources/config/
/Server/s.bat
/Server/src/bin/c.bat

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please roll back the changes here. Those ignored entries are your own files which will not be accepted into the OpenAS2 package.

Comment thread Server/src/bin/c.bat

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this file

Comment thread Server/s.bat

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please restore this file.

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import jakarta.ws.rs.*;

@uhurusurfa uhurusurfa Aug 21, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not use asterisk imports, import every class specifically.
If you want to know why I prefer this way, do an internet search "using wildcard import in java".

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.*;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above about asterisk imports

@Produces(MediaType.APPLICATION_XML)
public Response getXml(@QueryParam("filename") String filename, @QueryParam("xpath") String xpathExpression) {
Session session = getProcessor().getSession();
String filePath = session.getBaseDirectory() + '\\' + filename;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You must use a forward slash and leave Java to make the change if you run on Windows which it will normally gracefully handle for you or use File.SEPARATOR

Comment on lines +250 to +266
try {
NodeList nodeList = getNodes(filePath, xpathExpression);
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document resultDocument = db.newDocument();
for (int i = 0; i < nodeList.getLength(); i++) {
Node importedNode = resultDocument.importNode(nodeList.item(i), true);
resultDocument.appendChild(importedNode);
}
StringWriter stringWriter = new StringWriter(); // Convert the XML document to a string
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.transform(new DOMSource(resultDocument), new StreamResult(stringWriter));
String xmlContent = stringWriter.toString();
return Response.ok(xmlContent, MediaType.APPLICATION_XML).build();
} catch (Exception exception) {
return Response.serverError().entity("error").type(MediaType.APPLICATION_JSON).build();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will have to remove (or overwrite with random text ) any sensitive information from this extract such as passwords.

@apeiris

apeiris commented Aug 25, 2025

Copy link
Copy Markdown
Contributor Author

Closing this pull request as the current changes include sensitive information that needs to be sanitized. I will create a new pull request with the corrected and cleaned version shortly

@apeiris apeiris closed this Aug 25, 2025
@apeiris apeiris deleted the feature/api-xml-properties branch August 29, 2025 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants