fix(workflow): prevent prototype traversal and inherited CLI authorization
This commit is contained in:
1 parent
fac81b08e8
commit
d2e0d564ca
6 files changed
+62
-31
No files matched your search
@@ -21,6 +21,9 @@ function pathParts(path: string): string[] {
|
||||
.map((part) => part.trim())
|
||||
.filter(Boolean);
|
||||
if (!parts.length) throw new ValidationError("工作流配置路径不能为空");
|
||||
if (parts.some(part => ["__proto__", "constructor", "prototype"].includes(part))) {
|
||||
throw new ValidationError("工作流配置路径禁止访问对象原型");
|
||||
}
|
||||
if (parts.some((part) => !/^[A-Za-z_$][\w$-]*$/.test(part) && !/^\d+$/.test(part))) {
|
||||
throw new ValidationError(`工作流配置路径非法: ${path}`);
|
||||
}
|
||||
@@ -40,7 +43,7 @@ export function applyWorkflowPathPatch(
|
||||
const patched = structuredClone(workflow) as Record<string, any>;
|
||||
let cursor: any = patched;
|
||||
for (const part of parts.slice(0, -1)) {
|
||||
if (cursor === null || typeof cursor !== "object" || !(part in cursor)) {
|
||||
if (cursor === null || typeof cursor !== "object" || !Object.hasOwn(cursor, part)) {
|
||||
throw new NotFoundError(`工作流配置路径不存在: ${path}`);
|
||||
}
|
||||
cursor = cursor[part];
|
||||
|
||||
Reference in new issue
Block a user