Skip to content

Commit

Permalink
Rebase, add TODOs
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <[email protected]>
  • Loading branch information
dbwiddis committed Feb 23, 2024
1 parent 6a169a8 commit 8b2c8fe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ public PlainActionFuture<WorkflowData> execute(
String currentNodeId,
WorkflowData currentNodeInputs,
Map<String, WorkflowData> outputs,
Map<String, String> previousNodeInputs
Map<String, String> previousNodeInputs,
Map<String, String> params
) {
Set<String> requiredKeys = Set.of(SCHEME_FIELD, HOSTNAME_FIELD, PORT_FIELD);
// TODO Possibly add credentials fields here
// See ML Commons MLConnectorInput class and its usage
Set<String> optionalKeys = Collections.emptySet();

try {
Expand All @@ -51,11 +54,12 @@ public PlainActionFuture<WorkflowData> execute(
optionalKeys,
currentNodeInputs,
outputs,
previousNodeInputs
previousNodeInputs,
params
);

String scheme = validScheme(inputs.get(SCHEME_FIELD));
String hostname = inputs.get(HOSTNAME_FIELD).toString();
String hostname = validHostName(inputs.get(HOSTNAME_FIELD));
int port = validPort(inputs.get(PORT_FIELD));

HttpHost httpHost = new HttpHost(scheme, hostname, port);
Expand Down Expand Up @@ -84,6 +88,14 @@ private String validScheme(Object o) {
throw new FlowFrameworkException("http_host scheme must be http or https", RestStatus.BAD_REQUEST);
}

private String validHostName(Object o) {
// TODO Add validation:
// Prevent use of localhost or private IP address ranges
// See ML Commons MLHttpClientFactory.java methods for examples
// Possibly consider an allowlist of addresses
return o.toString();
}

private int validPort(Object o) {
try {
int port = Integer.parseInt(o.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void testHttpHost() throws InterruptedException, ExecutionException {
inputData.getNodeId(),
inputData,
Collections.emptyMap(),
Collections.emptyMap(),
Collections.emptyMap()
);

Expand All @@ -62,6 +63,7 @@ public void testBadScheme() {
badSchemeData.getNodeId(),
badSchemeData,
Collections.emptyMap(),
Collections.emptyMap(),
Collections.emptyMap()
);

Expand All @@ -84,6 +86,7 @@ public void testBadPort() {
badPortData.getNodeId(),
badPortData,
Collections.emptyMap(),
Collections.emptyMap(),
Collections.emptyMap()
);

Expand All @@ -106,6 +109,7 @@ public void testNoParsePort() {
noParsePortData.getNodeId(),
noParsePortData,
Collections.emptyMap(),
Collections.emptyMap(),
Collections.emptyMap()
);

Expand Down

0 comments on commit 8b2c8fe

Please sign in to comment.