Skip to content

Commit 710995a

Browse files
fuweng11wakefu
andauthored
[INLONG-12133][Manager] Fix the security vulnerability in /api/cluster/testConnection (apache#12134)
Co-authored-by: wakefu <wakefu@tencent.com>
1 parent 3af0ea9 commit 710995a

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/InlongClusterServiceImpl.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.inlong.manager.common.exceptions.BusinessException;
3838
import org.apache.inlong.manager.common.util.CommonBeanUtils;
3939
import org.apache.inlong.manager.common.util.Preconditions;
40+
import org.apache.inlong.manager.common.util.UrlVerificationUtils;
4041
import org.apache.inlong.manager.dao.entity.InlongClusterEntity;
4142
import org.apache.inlong.manager.dao.entity.InlongClusterNodeEntity;
4243
import org.apache.inlong.manager.dao.entity.InlongClusterTagEntity;
@@ -940,6 +941,17 @@ public String getManagerSSHPublicKey() {
940941

941942
@Override
942943
public Boolean testSSHConnection(ClusterNodeRequest request) {
944+
// Validate IP to prevent SSRF attacks
945+
String ip = request.getIp();
946+
if (StringUtils.isNotBlank(ip)) {
947+
try {
948+
UrlVerificationUtils.validateHostNotInternal(ip);
949+
} catch (Exception e) {
950+
throw new BusinessException(ErrorCodeEnum.INVALID_PARAMETER,
951+
"SSRF protection: " + e.getMessage());
952+
}
953+
}
954+
943955
AgentClusterNodeRequest nodeRequest = (AgentClusterNodeRequest) request;
944956
try {
945957
CommandResult commandResult = commandExecutor.execRemote(nodeRequest, "ls");
@@ -1271,6 +1283,17 @@ public AuditConfig getAuditConfig(String clusterTag) {
12711283
public Boolean testConnection(ClusterRequest request) {
12721284
LOGGER.info("begin test connection for: {}", request);
12731285

1286+
// Validate URL to prevent SSRF attacks
1287+
String url = request.getUrl();
1288+
if (StringUtils.isNotBlank(url)) {
1289+
try {
1290+
UrlVerificationUtils.validateUrlNotInternal(url);
1291+
} catch (Exception e) {
1292+
throw new BusinessException(ErrorCodeEnum.INVALID_PARAMETER,
1293+
"SSRF protection: " + e.getMessage());
1294+
}
1295+
}
1296+
12741297
// according to the data node type, test connection
12751298
InlongClusterOperator clusterOperator = clusterOperatorFactory.getInstance(request.getType());
12761299
Boolean result = clusterOperator.testConnection(request);

inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongClusterController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,14 @@ public Response<String> getManagerSSHPublicKey() {
305305

306306
@PostMapping("/cluster/node/testSSHConnection")
307307
@ApiOperation(value = "Test SSH connection for inlong cluster node")
308+
@RequiresRoles(logical = Logical.OR, value = {UserRoleCode.INLONG_ADMIN, UserRoleCode.TENANT_ADMIN})
308309
public Response<Boolean> testSSHConnection(@RequestBody ClusterNodeRequest request) {
309310
return Response.success(clusterService.testSSHConnection(request));
310311
}
311312

312313
@PostMapping("/cluster/testConnection")
313314
@ApiOperation(value = "Test connection for inlong cluster")
315+
@RequiresRoles(logical = Logical.OR, value = {UserRoleCode.INLONG_ADMIN, UserRoleCode.TENANT_ADMIN})
314316
public Response<Boolean> testConnection(@Validated @RequestBody ClusterRequest request) {
315317
return Response.success(clusterService.testConnection(request));
316318
}

0 commit comments

Comments
 (0)