logo
18
3
WeChat Login

feat: 新增侧边栏常驻cnb入口,新增关闭环境、文件漫游、文档说明等功能#46

Merged
created 1 weeks ago
main
feature/huiminlu_0130
Edit
OverviewCommits
7
Files changed
9
AttachmentsTAPD

以下内容由 AI 生成

新增 CNB 开发面板及关闭环境功能,优化 API 与常量支持

  1. 在 package.json 添加活动栏视图容器与 webview 侧边栏
  2. 新增关闭环境 API 及相关常量、导入
  3. 实现侧边栏 Provider 与管理逻辑,支持文件漫游等交互
approved
NPC
reviewed
src/common/util.ts

问题: ## 路径遍历漏洞

loadDirectoryChildren 函数接收任意路径参数 dirPath,没有任何验证或路径限制。攻击者可以通过 webview 发送恶意路径(如 ../../../etc/passwd)读取系统敏感文件。

调用链:

  • sidebar-manage.ts:39-41 - webview 消息 data.path 直接传递
  • sidebar-manage.ts:41 - 调用 loadDirectoryChildren(data.path)

攻击者可在 webview 中执行:

vscode.postMessage({
    type: 'loadDirectoryChildren',
    path: '/etc/passwd'
});

建议: ## 修复建议

添加路径验证,确保只能访问预期的目录:

const ALLOWED_BASE_DIR = '/run/.userdata/';

export function loadDirectoryChildren(dirPath: string): any[] {
    const fs = require('fs');
    const path = require('path');
    
    // 路径规范化并验证
    const normalizedPath = path.normalize(dirPath);
    if (!normalizedPath.startsWith(ALLOWED_BASE_DIR)) {
        console.error('Invalid path access attempt:', dirPath);
        return [];
    }
    
    // ... 其余代码
}
src/common/sidebar-manage.ts

问题: ## 路径遍历漏洞 - 入口点

webview 消息处理中,data.path 来自不可信来源(webview),直接传递给 loadDirectoryChildren 而未验证。这是上述路径遍历漏洞的入口点。
建议: ## 修复建议

在调用 loadDirectoryChildren 前验证路径:

case 'loadDirectoryChildren':
    // 验证路径合法性
    if (!data.path || typeof data.path !== 'string') {
        return;
    }
    const children = loadDirectoryChildren(data.path);
    // ...
src/sidebar/sidebar.js

问题: ## CSS 选择器注入风险

使用用户可控数据构建 CSS 选择器:

const folderPath = expandHint.getAttribute('data-expand-hint');
const folderItem = document.querySelector(`[data-path="${folderPath}"]`);

如果 folderPath 包含双引号 ",选择器会被提前终止,可能导致:

  1. 选择器解析错误
  2. 意外选中其他元素

同样的问题存在于第 62、137-138 行。
建议: ## 修复建议

使用 CSS 转义或通过属性选择器转义:

function escapeCssSelector(value) {
    return value.replace(/["'\\]/g, '\\$&');
}

const folderPath = expandHint.getAttribute('data-expand-hint');
const folderItem = document.querySelector(`[data-path="${escapeCssSelector(folderPath)}"]`);

或使用 document.evaluate / dataset 查询方式避免字符串拼接。

cnb-548-1jljbfrieis using the squash method to merge intoe84810a7
feat: 新增侧边栏和左边栏

Successfully merged and closed

branch can be safely deleted
Reviewer
(folger)
(晶晶)
Assignee
None yet
Label
None yet
Participant