luoluoyuyu commented on code in PR #17741:
URL: https://github.com/apache/iotdb/pull/17741#discussion_r3309325964
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/protocol/legacy/IoTDBLegacyPipeReceiverAgent.java:
##########
@@ -337,6 +350,23 @@ public TSStatus transportFile(final TSyncTransportMetaInfo
metaInfo, final ByteB
return RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS, "");
}
+ private static File resolveFileInFileDataDir(final String fileDir, final
String fileName)
+ throws IOException {
+ if (StringUtils.isEmpty(fileName)) {
+ throw new
IOException(String.format(PipeMessages.ILLEGAL_FILENAME_PATH_TRAVERSAL,
fileName));
+ }
+
+ final String illegalError = FileUtils.getIllegalError4Directory(fileName);
+ if (Objects.nonNull(illegalError)) {
+ throw new IOException(
+ String.format(PipeMessages.ILLEGAL_FILENAME_PATH_TRAVERSAL, fileName)
+ + ", "
+ + illegalError);
+ }
+
+ return PipeReceiverFilePathUtils.resolveFilePath(Paths.get(fileDir),
fileName).toFile();
Review Comment:
👍 使用 `PipeReceiverFilePathUtils.resolveFilePath` 替代 `new File(fileDir,
fileName)` 是正确的修复。
**建议补 IT**(可 follow-up):
- `transportFile` 传入 `../../../etc/passwd` 类 fileName → 期望 `SYNC_FILE_ERROR`
- 正常 tsFile 名仍可续传
同时确认 `getIllegalError4Directory` 对 `foo/bar`(子路径)与 `..` 的覆盖与 thrift 协议文档一致。
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/impl/ClientRPCServiceImpl.java:
##########
@@ -3398,24 +3399,58 @@ public TSStatus
createTimeseriesUsingSchemaTemplate(TCreateTimeseriesUsingSchema
@Override
public TSStatus handshake(final TSyncIdentityInfo info) throws TException {
- return PipeDataNodeAgent.receiver()
- .legacy()
- .handshake(
- info,
- SESSION_MANAGER.getCurrSession().getClientAddress(),
- partitionFetcher,
- schemaFetcher);
+ try {
+ final TSStatus status = checkLegacyPipeReceiverPermission();
+ if (status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+ return status;
+ }
+ return PipeDataNodeAgent.receiver()
+ .legacy()
+ .handshake(
+ info,
+ SESSION_MANAGER.getCurrSession().getClientAddress(),
+ partitionFetcher,
+ schemaFetcher);
+ } finally {
+ SESSION_MANAGER.updateIdleTime();
+ }
}
@Override
public TSStatus sendPipeData(final ByteBuffer buff) throws TException {
- return PipeDataNodeAgent.receiver().legacy().transportPipeData(buff);
+ try {
+ final TSStatus status = checkLegacyPipeReceiverPermission();
+ if (status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+ return status;
+ }
+ return PipeDataNodeAgent.receiver().legacy().transportPipeData(buff);
+ } finally {
+ SESSION_MANAGER.updateIdleTime();
+ }
}
@Override
public TSStatus sendFile(final TSyncTransportMetaInfo metaInfo, final
ByteBuffer buff)
throws TException {
- return PipeDataNodeAgent.receiver().legacy().transportFile(metaInfo, buff);
+ try {
+ final TSStatus status = checkLegacyPipeReceiverPermission();
+ if (status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+ return status;
+ }
+ return PipeDataNodeAgent.receiver().legacy().transportFile(metaInfo,
buff);
+ } finally {
+ SESSION_MANAGER.updateIdleTime();
+ }
+ }
+
+ private TSStatus checkLegacyPipeReceiverPermission() {
+ final IClientSession clientSession =
SESSION_MANAGER.getCurrSessionAndUpdateIdleTime();
+ if (!SESSION_MANAGER.checkLogin(clientSession)) {
+ return getNotLoggedInStatus();
+ }
+ return AuthorityChecker.getTSStatus(
+ AuthorityChecker.checkSystemPermission(clientSession.getUsername(),
PrivilegeType.USE_PIPE),
Review Comment:
👍 `checkLegacyPipeReceiverPermission` 要求已登录 + `USE_PIPE` system 权限,堵住未授权
legacy pipe 文件写入。
**兼容性提醒**:升级后旧版 sink(未 `openSession`)会在 handshake 失败。PR 已在
`IoTDBLegacyPipeSink.openClientSession()` 处理发送侧,需确保 **source/target 0.14+
成对升级** 或 release note 标明 breaking change。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]