T09 · Insecure Skill Coding Practices
- Location
scripts/sorftime_walmart_product_analysis.py:256- Finding
Path Traversal Through Unvalidated SESSION_ID Enables Writes Outside the Intended Output Directory
- Content
View full analysis
str: """优先 env SESSION_ID;缺省按 HHMMSS-<6 hex> 生成(同一进程内稳定)。""" env = os.environ.get("SESSION_ID") if env: return env.strip() if "_auto" not in _SESSION_CACHE: _SESSION_CACHE["_auto"] = ( time.strftime("%H%M%S", time.localtime(ts)) + "-" + secrets.token_hex(3) ) return _SESSION_CACHE["_auto"] def _ensure_session(ts: float) -> tuple[str, str]: """返回 (linkfox_root, session_dir);session_dir 一定存在。""" date_str = time.strftime("%Y-%m-%d", time.localtime(ts)) sid = _session_id(ts) root = _linkfox_root() session_dir = os.path.join(root, date_str, sid) os.makedirs(session_dir, exist_ok=True) _ensure_meta(root, session_dir, date_str, sid, ts) return root, session_dir ``` The resulting path is later used for response output: ```python def resolve_data_path(slug: str, ts: float, ext: str = "json") -> str: """普通 skill 的原始数据落到 /data/-.。""" _, session_dir = _ensure_session(ts) sub = os.path.join(session_dir, "data") os.makedirs(sub, exist_ok=True) out = os.path.join(sub, f"{slug}-{int(ts * 1_000_000)}.{ext}") _update_meta(session_dir, skill=slug, kind="data", file_rel=os.path.relpath(out, session_dir), ts=ts) return out def _resolve_output_path(ts): """落到 /linkfox/<日期>//data/-.json,按 SESSION_ID 聚合到同一会话。""" sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "_shared")) return resolve_data_path(SLUG, ts) ``` From `scripts/onboarding.py`: ```python def session_dir() -> str: ts = time.time() sid = (os ...[truncated 2625 chars]- Remediation
View remediation
