Ignore:
Timestamp:
2015-04-28T01:11:18+02:00 (9 years ago)
Author:
Don-vip
Message:

fix findsecbugs:XXE_SAXPARSER - "Security - XML Parsing Vulnerable to XXE (SAXParser)"

Location:
trunk/src/org/openstreetmap/josm/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r7894 r8287  
    5050import java.util.zip.ZipInputStream;
    5151
     52import javax.xml.XMLConstants;
     53import javax.xml.parsers.ParserConfigurationException;
     54import javax.xml.parsers.SAXParser;
     55import javax.xml.parsers.SAXParserFactory;
     56
    5257import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
    5358import org.openstreetmap.josm.Main;
    5459import org.openstreetmap.josm.data.Version;
     60import org.xml.sax.SAXException;
    5561
    5662/**
     
    11641170        return null;
    11651171    }
     1172
     1173    /**
     1174     * Returns a new secure SAX parser, supporting XML namespaces.
     1175     * @return a new secure SAX parser, supporting XML namespaces
     1176     * @throws ParserConfigurationException if a parser cannot be created which satisfies the requested configuration.
     1177     * @throws SAXException for SAX errors.
     1178     * @since 8287
     1179     */
     1180    public static SAXParser newSafeSAXParser() throws ParserConfigurationException, SAXException {
     1181        SAXParserFactory parserFactory = SAXParserFactory.newInstance();
     1182        parserFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
     1183        parserFactory.setNamespaceAware(true);
     1184        return parserFactory.newSAXParser();
     1185    }
    11661186}
  • trunk/src/org/openstreetmap/josm/tools/XmlObjectParser.java

    r8285 r8287  
    2020import javax.xml.XMLConstants;
    2121import javax.xml.parsers.ParserConfigurationException;
    22 import javax.xml.parsers.SAXParser;
    23 import javax.xml.parsers.SAXParserFactory;
    2422import javax.xml.transform.stream.StreamSource;
    2523import javax.xml.validation.Schema;
     
    250248    private Iterable<Object> start(final Reader in, final ContentHandler contentHandler) throws SAXException, IOException {
    251249        try {
    252             SAXParserFactory parserFactory = SAXParserFactory.newInstance();
    253             parserFactory.setNamespaceAware(true);
    254             SAXParser saxParser = parserFactory.newSAXParser();
    255             XMLReader reader = saxParser.getXMLReader();
     250            XMLReader reader = Utils.newSafeSAXParser().getXMLReader();
    256251            reader.setContentHandler(contentHandler);
    257252            try {
Note: See TracChangeset for help on using the changeset viewer.