Skip to content

Commit b6ed986

Browse files
committed
Make sure DocTypes are disallowed
1 parent 84b4d31 commit b6ed986

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

plugins/core/src/main/java/org/apache/cxf/fediz/core/util/DOMUtils.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,15 @@
6262
*/
6363
public final class DOMUtils {
6464
private static final Logger LOG = LoggerFactory.getLogger(DOMUtils.class);
65-
65+
6666
private static final String XMLNAMESPACE = "xmlns";
6767

6868
private static final DocumentBuilderFactory DBF = DocumentBuilderFactory.newInstance();
69-
69+
7070
static {
7171
try {
7272
DBF.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
73+
DBF.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
7374

7475
DBF.setValidating(false);
7576
DBF.setIgnoringComments(false);

systests/idp/src/test/java/org/apache/cxf/fediz/systests/idp/IdpTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,47 @@ public void testEntityExpansionWReq() throws Exception {
433433
webClient.close();
434434
}
435435

436+
// Send an entity expansion attack for the wreq value
437+
@org.junit.Test
438+
public void testEntityExpansionWReq2() throws Exception {
439+
String url = "https://localhost:" + getIdpHttpsPort() + "/fediz-idp/federation?";
440+
url += "wa=wsignin1.0";
441+
url += "&whr=urn:org:apache:cxf:fediz:idp:realm-A";
442+
url += "&wtrealm=urn:org:apache:cxf:fediz:fedizhelloworld";
443+
String wreply = "https://localhost:" + getRpHttpsPort() + "/" + getServletContextName() + "/secure/fedservlet";
444+
url += "&wreply=" + wreply;
445+
446+
InputStream is = this.getClass().getClassLoader().getResource("entity_wreq2.xml").openStream();
447+
String entity = IOUtils.toString(is, "UTF-8");
448+
is.close();
449+
String validWreq =
450+
"<RequestSecurityToken xmlns=\"http://docs.oasis-open.org/ws-sx/ws-trust/200512\">"
451+
+ "<TokenType>&m;http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0</TokenType>"
452+
+ "</RequestSecurityToken>";
453+
454+
url += "&wreq=" + URLEncoder.encode(entity + validWreq, "UTF-8");
455+
456+
String user = "alice";
457+
String password = "ecila";
458+
459+
final WebClient webClient = new WebClient();
460+
webClient.getOptions().setUseInsecureSSL(true);
461+
webClient.getCredentialsProvider().setCredentials(
462+
new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())),
463+
new UsernamePasswordCredentials(user, password));
464+
465+
webClient.getOptions().setJavaScriptEnabled(false);
466+
467+
try {
468+
webClient.getPage(url);
469+
Assert.fail("Failure expected on a bad wreq value");
470+
} catch (FailingHttpStatusCodeException ex) {
471+
Assert.assertEquals(ex.getStatusCode(), 400);
472+
}
473+
474+
webClient.close();
475+
}
476+
436477
// Send an malformed wreq value
437478
@org.junit.Test
438479
public void testMalformedWReq() throws Exception {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE RequestSecurityTokenResponseCollection [<!ENTITY m SYSTEM "/etc/hosts">]>

0 commit comments

Comments
 (0)