Skip to content
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 @@ -563,18 +563,33 @@ public long getTotalMaxUncommittedExceededCount() {
return safeGetBroker().getDestinationStatistics().getMaxUncommittedExceededCount().getCount();
}


// Validate the Url does not contain VM transport
private static void validateAllowedUrl(String uriString) throws URISyntaxException {
URI uri = new URI(uriString);
validateAllowedUri(new URI(uriString), 0);
}

// Validate the URI does not contain VM transport
private static void validateAllowedUri(URI uri, int depth) throws URISyntaxException {
// Don't allow more than 5 nested URIs to prevent blowing the stack
if (depth > 5) {
throw new IllegalArgumentException("URI can't contain more than 5 nested composite URIs");
}

// First check the main URI scheme
validateAllowedScheme(uri.getScheme());

// If composite, also check all schemes for each component
// If composite, iterate and check each of the composite URIs
if (URISupport.isCompositeURI(uri)) {
URISupport.CompositeData data = URISupport.parseComposite(uri);
depth++;
for (URI component : data.getComponents()) {
validateAllowedScheme(component.getScheme());
// Each URI could be a nested composite URI so call validateAllowedUri()
// to validate it. This check if composite first so we don't add to
// the recursive stack depth if there's a lot of URIs that are not composite
if (URISupport.isCompositeURI(uri)) {
validateAllowedUri(component, depth);
} else {
validateAllowedScheme(uri.getScheme());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import org.apache.activemq.util.JMXSupport;
import org.apache.activemq.util.URISupport;
import org.apache.activemq.util.Wait;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -2067,17 +2068,36 @@ public void testAddVmConnectorBlockedBrokerView() throws Exception {

try {
brokerView.addConnector("vm://localhost");
fail("Should have failed trying to add vm connector bridge");
fail("Should have failed trying to add vm connector");
} catch (IllegalArgumentException e) {
assertEquals("VM scheme is not allowed", e.getMessage());
}

try {
// verify any composite URI is blocked as well
brokerView.addConnector("failover:(tcp://0.0.0.0:0,vm://" + brokerName + ")");
fail("Should have failed trying to add vm connector bridge");
fail("Should have failed trying to add vm connector");
} catch (IllegalArgumentException e) {
assertEquals("VM scheme is not allowed", e.getMessage());
}

try {
// verify nested composite URI is blocked
brokerView.addConnector("failover:(failover:(failover:(vm://localhost)))");
fail("Should have failed trying to add vm connector");
} catch (IllegalArgumentException e) {
assertEquals("VM scheme is not allowed", e.getMessage());
}

try {
// verify nested composite URI with more than 5 levels is blocked
brokerView.addConnector(
"static:(failover:(failover:(failover:(failover:(failover:(tcp://localhost:0))))))");
fail("Should have failed trying to add vm connector bridge");
} catch (IllegalArgumentException e) {
assertEquals("URI can't contain more than 5 nested composite URIs", e.getMessage());
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,25 @@ public void testVmBridgeBlocked() throws Exception {
} catch (IllegalArgumentException e) {
assertEquals("VM scheme is not allowed", e.getMessage());
}

try {
// verify nested composite URI is blocked
proxy.addNetworkConnector("static:(failover:(failover:(tcp://localhost:0,vm://localhost)))");
fail("Should have failed trying to add vm connector bridge");
} catch (IllegalArgumentException e) {
assertEquals("VM scheme is not allowed", e.getMessage());
}
}

@Test
public void testAddNetworkConnectorMaxComposite() throws Exception {
try {
// verify nested composite URI with more than 5 levels is blocked
proxy.addNetworkConnector(
"static:(failover:(failover:(failover:(failover:(failover:(tcp://localhost:0))))))");
fail("Should have failed trying to add vm connector bridge");
} catch (IllegalArgumentException e) {
assertEquals("URI can't contain more than 5 nested composite URIs", e.getMessage());
}
}
}