ppkarwasz commented on code in PR #44: URL: https://github.com/apache/commons-xml/pull/44#discussion_r3856273887
########## src/main/java/org/apache/commons/xml/HardeningXPathFactory.java: ########## @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.xml; + +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathFactory; +import javax.xml.xpath.XPathFactoryConfigurationException; +import javax.xml.xpath.XPathFunctionResolver; +import javax.xml.xpath.XPathVariableResolver; + +/** + * {@link XPathFactory} wrapper that returns a {@link HardeningXPath} from {@link #newXPath()}. + * + * <p>Required because {@link javax.xml.XMLConstants#FEATURE_SECURE_PROCESSING} on the factory governs only the XPath engine: the stock JDK and Apache Xalan + * implement the {@link org.xml.sax.InputSource}-taking {@code evaluate} entry points by provisioning an internal document parser the feature does not reach. + * The wrapper performs that document build itself through a hardened parser instead; see {@link HardeningXPath}.</p> + */ +final class HardeningXPathFactory extends XPathFactory { + + private final XPathFactory delegate; + + HardeningXPathFactory(final XPathFactory delegate) { + this.delegate = delegate; + } + + @Override + public XPath newXPath() { + final XPath xpath = delegate.newXPath(); + return xpath == null ? null : new HardeningXPath(xpath); + } + + // <editor-fold defaultstate="collapsed" desc="Trivial delegation"> + @Override + public boolean getFeature(final String name) throws XPathFactoryConfigurationException { + return delegate.getFeature(name); + } + + @Override + public boolean isObjectModelSupported(final String objectModel) { + return delegate.isObjectModelSupported(objectModel); + } + + @Override + public void setFeature(final String name, final boolean value) throws XPathFactoryConfigurationException { + delegate.setFeature(name, value); + } + + @Override + public void setXPathFunctionResolver(final XPathFunctionResolver resolver) { + delegate.setXPathFunctionResolver(resolver); + } + + @Override + public void setXPathVariableResolver(final XPathVariableResolver resolver) { + delegate.setXPathVariableResolver(resolver); + } + // </editor-fold> Review Comment: Fixed in https://github.com/apache/commons-xml/pull/44/commits/98125dc2ef0a2657554786aa72b4b36430fb11fc -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
