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

feat: 面板目录禁止删除 #7029

Merged
merged 1 commit into from
Nov 13, 2024
Merged

feat: 面板目录禁止删除 #7029

merged 1 commit into from
Nov 13, 2024

Conversation

lan-yonghui
Copy link
Contributor

Refs #7008

Copy link

f2c-ci-robot bot commented Nov 13, 2024

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

return;
}
}

pros.push(DeleteFile({ path: s['path'], isDir: s['isDir'], forceDelete: forceDelete.value }));
}
loading.value = true;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此段代码在一些地方存在问题。

import { DeleteFile, GetRecycleStatus } from '@/api/modules/files';

需要使用的是@/api/models/download/接口,即:

await deleteFn(params)
export default {
   namespace: 'download',
   state: {
      ...,
      dataList: [],
      total: 0
   },
    actions: {
       async doAction({ commit }, options) {}

...
// @ts-ignore
import { LoadConfig } from "@/modules/config"
await exportFn(config)

建议先进行相关接口和文件路径的修改。

excludeDir := global.CONF.System.DataDir
if strings.Contains(op.Path, ".1panel_clash") || op.Path == excludeDir {
return buserr.New(constant.ErrPathNotDelete)
}
fo := files.NewFileOp()
recycleBinStatus, _ := settingRepo.Get(settingRepo.WithByKey("FileRecycleBin"))
if recycleBinStatus.Value == "disable" {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个代码在当前时间(2024年11月13日)上是合规且没有明显问题的。
不过,从最近一次更新来看,它可能不再被推荐使用。

  • 文件创建功能需要更精细地控制文件路径和删除操作来预防垃圾导入到磁盘错误

我将对这些方面提供一些改进建议:

优化文件逻辑:

确保只允许非目录结构的完整文件名来防止意外的乱码或错误行为。这通常有助于提高文件安全性并避免将来引入麻烦。

建议添加验证条件以排除特定的路径如系统数据目录。这样可以保证文件安全。

总结起来就是,根据最新的编程实践和设计规范,改进代码中存在的一些不足之处。

维护最新技术和最佳实践:

由于你提到的代码已经过时了,并且不符合现在的标准,请参考以下示例:

// 假设这里有一个名为FileService的方法:
func (service *FileService) Upload(filePath string, file *multipart.FileHeader){
    // 程序可能会在这里处理上传文件的过程...

    if os.IsNotExist(err){   // 检查是否存在该文件... 可以为file.Name()返回值...
        return http.StatusInternalServerError, errors.New(filepath.WouldBlockError{})     // 在必要时处理此情况....
    }

    // 此处应进一步进行验证和限制
}

在这个替代方案下,os.IsExist()函数会被一个适当的检查替换,而不是简单的filepath.WouldBlock()。同时,在filePath != "" && filePath ==".1panel_clash"之后执行额外的操作变得显而易见,例如删除任何与用户不想共享内容相关联的内容。

以上是我提供的改进建议及解决方案的解释,希望能帮助您解决您的具体问题!

@@ -100,6 +100,7 @@ var (
ErrFileDownloadDir = "ErrFileDownloadDir"
ErrCmdNotFound = "ErrCmdNotFound"
ErrFavoriteExist = "ErrFavoriteExist"
ErrPathNotDelete = "ErrPathNotDelete"
)

// mysql

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段代码中存在一个逻辑错误,它试图引入两个具有相同名称的方法(ErrPathNotDelete)和字段 err_path_not_delete。我建议将第二个方法和字段更改为一致。

这是一个优化的例子:

var (
   ErrFileDownloadDir = ""
   ErrCmdNotFound    = ""
   ErrFavoriteExist  = ""

这样可以避免重复定义,并且在其他地方不需要额外地指明哪个是优先使用的版本。

// mysql
var(
.err_path_not_deleted = ""
)

Copy link

sonarcloud bot commented Nov 13, 2024

Copy link
Member

@wanghe-fit2cloud wanghe-fit2cloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@wanghe-fit2cloud
Copy link
Member

/approve

Copy link

f2c-ci-robot bot commented Nov 13, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wanghe-fit2cloud

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@f2c-ci-robot f2c-ci-robot bot merged commit 0b87025 into dev Nov 13, 2024
6 checks passed
@f2c-ci-robot f2c-ci-robot bot deleted the pr@dev@feat_panel_dir branch November 13, 2024 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants