Skip to content

Commit 14e602f

Browse files
committed
Disallow loading DTDs, etc. in protocol tests
1 parent 29c1aa1 commit 14e602f

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

smithy-protocol-test-traits/src/main/java/software/amazon/smithy/protocoltests/traits/ProtocolTestCaseValidator.java

+11
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ abstract class ProtocolTestCaseValidator<T extends Trait> extends AbstractValida
6666
this.traitClass = traitClass;
6767
this.descriptor = descriptor;
6868
documentBuilderFactory = DocumentBuilderFactory.newInstance();
69+
70+
// Disallow loading DTDs and more for protocol test contents.
71+
try {
72+
documentBuilderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
73+
documentBuilderFactory.setXIncludeAware(false);
74+
documentBuilderFactory.setExpandEntityReferences(false);
75+
documentBuilderFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
76+
documentBuilderFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
77+
} catch (ParserConfigurationException e) {
78+
throw new RuntimeException(e);
79+
}
6980
}
7081

7182
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[DANGER] smithy.example#SayHello: Invalid application/xml content in `smithy.test#httpRequestTests` protocol test case `foo1` | HttpRequestTestsInput
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
namespace smithy.example
2+
3+
use smithy.test#httpRequestTests
4+
5+
@trait
6+
@protocolDefinition
7+
structure testProtocol {}
8+
9+
@http(method: "POST", uri: "/")
10+
@httpRequestTests([
11+
{
12+
id: "foo1",
13+
protocol: testProtocol,
14+
method: "POST",
15+
uri: "/",
16+
params: {
17+
type: true
18+
},
19+
bodyMediaType: "application/xml",
20+
body: """
21+
<!DOCTYPE root [
22+
<!ENTITY hifi "hifi">
23+
<!ENTITY hifi1 "&hifi;&hifi;&hifi;">
24+
<!ENTITY hifi2 "&hifi1;&hifi1;&hifi1;">
25+
<!ENTITY hifi3 "&hifi2;&hifi2;&hifi2;">
26+
]>
27+
<XmlNamespacesResponse xmlns="https://example.com/">
28+
<nested>
29+
<foo xmlns:baz="http://baz.com">Foo</foo>
30+
<values xmlns="http://qux.com">
31+
<member xmlns="http://bux.com">Bar</member>
32+
<member xmlns="http://bux.com">Baz</member>
33+
</values>
34+
</nested>
35+
<RequestId>requestid</RequestId>
36+
</XmlNamespacesResponse>
37+
"""
38+
}
39+
])
40+
operation SayHello {
41+
input: SayHelloInput
42+
}
43+
44+
structure SayHelloInput {
45+
type: Boolean
46+
}

0 commit comments

Comments
 (0)