Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[master] Issue 467 #501

Merged
merged 2 commits into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ protected void initDocumentParser() throws ParserConfigurationException {

docBuilderFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", resolveSchemaSource());

docBuilderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
docBuilderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
docBuilderFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
docBuilderFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
docBuilderFactory.setXIncludeAware(false);
docBuilderFactory.setExpandEntityReferences(false);

docBuilder = docBuilderFactory.newDocumentBuilder();

docBuilder.setErrorHandler(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.quartz.simpl.SimpleThreadPool;
import org.quartz.spi.ClassLoadHelper;
import org.quartz.utils.DBConnectionManager;
import org.xml.sax.SAXParseException;

/**
* Unit test for XMLSchedulingDataProcessor.
Expand Down Expand Up @@ -356,6 +357,31 @@ public void testOverwriteJobClassNotFound() throws Exception {
}
}

public void testXmlParserConfiguration() throws Exception {
Scheduler scheduler = null;
try {
StdSchedulerFactory factory = new StdSchedulerFactory("org/quartz/xml/quartz-test.properties");
scheduler = factory.getScheduler();
ClassLoadHelper clhelper = new CascadingClassLoadHelper();
clhelper.initialize();
XMLSchedulingDataProcessor processor = new XMLSchedulingDataProcessor(clhelper);
processor.processFileAndScheduleJobs("org/quartz/xml/bad-job-config.xml", scheduler);


final JobKey jobKey = scheduler.getJobKeys(GroupMatcher.jobGroupEquals("native")).iterator().next();
final JobDetail jobDetail = scheduler.getJobDetail(jobKey);
final String description = jobDetail.getDescription();


fail("Expected parser configuration to block DOCTYPE. The following was injected into the job description field: " + description);
} catch (SAXParseException e) {
assertTrue(e.getMessage().contains("DOCTYPE is disallowed"));
} finally {
if (scheduler != null)
scheduler.shutdown();
}
}

private void modifyStoredJobClassName() throws Exception {
String DB_NAME = "XmlDeleteNonExistsJobTestDatasase";
Connection conn = DBConnectionManager.getInstance().getConnection(DB_NAME);
Expand Down
15 changes: 15 additions & 0 deletions quartz-core/src/test/resources/org/quartz/xml/bad-job-config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [<!ELEMENT foo ANY >
<!ENTITY xxe SYSTEM "/" >]>
<job-scheduling-data xmlns="http://www.quartz-scheduler.org/xml/JobSchedulingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.quartz-scheduler.org/xml/JobSchedulingData http://www.quartz-scheduler.org/xml/job_scheduling_data_2_0.xsd" version="2.0">
<schedule>
<job>
<name>xxe</name>
<group>native</group>
<description>&xxe;</description>
<job-class>org.quartz.xml.XMLSchedulingDataProcessorTest$MyJob</job-class>
<durability>true</durability>
<recover>false</recover>
</job>
</schedule>
</job-scheduling-data>