(path: string)
| 865 | let p = input.replace(/\/+$/, ""); |
| 866 | if (!p.endsWith("/openlist")) p = `${p}/openlist`; |
| 867 | return p; |
| 868 | } |
| 869 | |
| 870 | /** |
| 871 | * 校验并归一化用户传入的安装目录。 |
| 872 | * 安装目录会被直接拼接进双引号包裹的 shell 字符串中执行, |
| 873 | * 若不过滤会导致命令注入(如传入 `"; rm -rf / #` 或包含 `"` `` `$` `\` 等字符)。 |
| 874 | * 仅允许绝对路径、白名单字符(字母/数字/./-/_),且不允许 `..` 路径穿越。 |
| 875 | */ |
| 876 | private sanitizeInstallPath(input: string | undefined): { ok: true; path: string } | { ok: false; reason: string } { |
| 877 | if (!input || !input.trim()) { |
| 878 | return { ok: true, path: "/opt/openlist" }; |
| 879 | } |
no outgoing calls
no test coverage detected