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

Disallow loading DTDs, etc. in protocol tests #835

Merged
merged 1 commit into from
Jun 15, 2021
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 @@ -66,6 +66,17 @@ abstract class ProtocolTestCaseValidator<T extends Trait> extends AbstractValida
this.traitClass = traitClass;
this.descriptor = descriptor;
documentBuilderFactory = DocumentBuilderFactory.newInstance();

// Disallow loading DTDs and more for protocol test contents.
try {
documentBuilderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
documentBuilderFactory.setXIncludeAware(false);
documentBuilderFactory.setExpandEntityReferences(false);
documentBuilderFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
documentBuilderFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[DANGER] smithy.example#SayHello: Invalid application/xml content in `smithy.test#httpRequestTests` protocol test case `foo1` | HttpRequestTestsInput
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
namespace smithy.example

use smithy.test#httpRequestTests

@trait
@protocolDefinition
structure testProtocol {}

@http(method: "POST", uri: "/")
@httpRequestTests([
{
id: "foo1",
protocol: testProtocol,
method: "POST",
uri: "/",
params: {
type: true
},
bodyMediaType: "application/xml",
body: """
<!DOCTYPE root [
<!ENTITY hifi "hifi">
<!ENTITY hifi1 "&hifi;&hifi;&hifi;">
<!ENTITY hifi2 "&hifi1;&hifi1;&hifi1;">
<!ENTITY hifi3 "&hifi2;&hifi2;&hifi2;">
]>
<XmlNamespacesResponse xmlns="https://example.com/">
<nested>
<foo xmlns:baz="http://baz.com">Foo</foo>
<values xmlns="http://qux.com">
<member xmlns="http://bux.com">Bar</member>
<member xmlns="http://bux.com">Baz</member>
</values>
</nested>
<RequestId>requestid</RequestId>
</XmlNamespacesResponse>
"""
}
])
operation SayHello {
input: SayHelloInput
}

structure SayHelloInput {
type: Boolean
}