T09 · Insecure Skill Coding Practices
- Location
core.py:70- Finding
Path Traversal Through Unsanitized Project and Character Names
- Content
View full analysis
dict: """加载记忆上下文""" context_file = self.project_dir / "meta" / "context.json" if context_file.exists(): with open(context_file, 'r', encoding='utf-8') as f: ctx = json.load(f) logger.info(f"Loaded context for: {self.novel_title}") return ctx def _save_context(self): """保存记忆上下文""" context_file = self.project_dir / "meta" / "context.json" context_file.parent.mkdir(parents=True, exist_ok=True) self.context["updated_at"] = datetime.now().isoformat() with open(context_file, 'w', encoding='utf-8') as f: json.dump(self.context, f, ensure_ascii=False, indent=2) def _init_project_dir(self): """初始化项目目录""" dirs = ["characters", "world", "outline", "chapters", "meta"] for d in dirs: (self.project_dir / d).mkdir(parents=True, exist_ok=True) config_file = self.project_dir / "config.json" if not config_file.exists(): with open(config_file, 'w', encoding='utf-8') as f: json.dump({ "title": self.novel_title, "style": self.context["style"], "created_at": datetime.now().isoformat() }, f, ensure_ascii=False, indent=2) def set_character(self, name: str, profile: str) -> str: """设定人物""" self.context["characters"][name] = profile self._save_context() char_file = self.project_dir / "characters" / f"{ ...[truncated 2387 chars]- Remediation
View remediation
Path: if not name or Path(name).is_absolute(): raise ValueError("Invalid path component") destination = (base / name).resolve() resolved_base = base.resolve() if destination != resolved_base and resolved_base not in destination.parents: raise ValueError("Path escapes the permitted directory") return destination ``` 4. Perform the containment check again on complete file destinations, including character and outline filenames. 5. Consider rejecting symbolic links within project storage or opening files with operating-system protections against symlink following. 6. Run the application under a dedicated, unprivileged account with write access limited to the intended working directory. 7. Add tests covering absolute paths, nested traversal, mixed separators, symbolic links, and platform-specific path forms. ]]>
