{"record":{"id":"b59011cfa7431a8e","repo":"Hmbown/CodeWhale","slug":"unsafe-bundle-path-relative","errorCode":null,"errorMessage":"unsafe bundle path: {relative}","messagePattern":"unsafe bundle path: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/sync-marketplace.py","lineNumber":28,"sourceCode":"import subprocess\n\nROOT = Path(__file__).resolve().parents[1]\nREPOSITORY = \"https://github.com/Hmbown/codewhale-plugin-marketplace\"\nparser = argparse.ArgumentParser(description=__doc__)\nparser.add_argument(\"--marketplace\", type=Path, default=ROOT.parent / \"codewhale-plugin-marketplace\")\nparser.add_argument(\"--check\", action=\"store_true\")\nargs = parser.parse_args()\nsource = args.marketplace.resolve()\nraw = subprocess.check_output([\"git\", \"show\", \"HEAD:marketplace.json\"], cwd=source)\nrevision = subprocess.check_output([\"git\", \"rev-parse\", \"HEAD\"], cwd=source, text=True).strip()\ncatalog = json.loads(raw)\nfor candidate in catalog[\"plugins\"]:\n    spec = candidate[\"source\"]\n    if not spec.startswith(\"path:\"):\n        raise SystemExit(f\"unexpected first-party source: {spec}\")\n    relative = spec[5:]\n    if any(part in (\"\", \".\", \"..\") or not all(c.isascii() and (c.isalnum() or c in \"-_.\") for c in part) for part in relative.split(\"/\")):\n        raise SystemExit(f\"unsafe bundle path: {relative}\")\n    # Pin every install source to the reviewed marketplace revision so the\n    # bytes a user installs are the bytes this snapshot describes. Freshness\n    # comes from bumping the pin (the marketplace-sync workflow reports drift\n    # against `main` weekly); `/plugin update` re-downloads the same archive\n    # and reports no change until the pin moves.\n    candidate[\"source\"] = f\"https://codeload.github.com/Hmbown/codewhale-plugin-marketplace/tar.gz/{revision}#path={relative}\"\nsnapshot = {\"repository\": REPOSITORY, \"revision\": revision, \"catalog\": catalog}\nrendered = json.dumps(snapshot, indent=2, ensure_ascii=False) + \"\\n\"\noutput = ROOT / \"crates/tui/assets/first-party-marketplace.json\"\nif args.check:\n    if not output.exists() or output.read_text() != rendered:\n        raise SystemExit(\"First-party catalog drift: run python3 scripts/sync-marketplace.py, review, and rebuild.\")\n    print(f\"First-party catalog matches marketplace {revision}\")\nelse:\n    output.write_text(rendered)\n    print(f\"Updated {output} from marketplace {revision}\")\n","sourceCodeStart":10,"sourceCodeEnd":45,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/scripts/sync-marketplace.py#L10-L45","documentation":"After stripping the `path:` prefix, each plugin bundle path is validated segment-by-segment: every path segment must be non-empty, not `.`/`..`, and consist only of ASCII alphanumerics, `-`, `_`, `.`. This blocks path traversal and unsafe characters in the generated codeload URL fragment. Violations exit with `unsafe bundle path: {relative}`.","triggerScenarios":"A plugin source like `path:../secrets`, `path:` (empty), `path:a/../../etc`, or a path containing spaces, `~`, or other special characters.","commonSituations":"Typos in plugin paths; attempting to reference a plugin outside the marketplace directory; a path with a space or unicode character copied from a file manager.","solutions":["Move/rename the plugin directory so its path segments are plain ASCII (letters, digits, `-_.`).","Remove any `..`, `.` segments or leading/trailing slashes from the source path.","Fix whitespace or special characters in directory names.","Re-run scripts/sync-marketplace.py after correcting marketplace.json."],"exampleFix":"// before\n\"source\": \"path:../shared-plugins/x y\"\n// after\n\"source\": \"path:plugins/x-y\"","handlingStrategy":"validation","validationCode":"import re\nfor c in json.load(open('marketplace.json'))['plugins']:\n    rel = c['source'][5:]\n    assert all(re.fullmatch(r'[\\w.-]+', p) and p not in ('.','..') for p in rel.split('/')), rel","typeGuard":"def safe_rel(p): return bool(p) and all(seg not in ('','.', '..') and all(ch.isascii() and (ch.isalnum() or ch in '-_.') for ch in seg) for seg in p.split('/'))","tryCatchPattern":"try:\n    subprocess.run(['python3','scripts/sync-marketplace.py'], check=True)\nexcept SystemExit as e:\n    print('unsafe path:', e)","preventionTips":["Keep plugin directories named with plain ASCII letters, digits, -_. ","Never use .. or absolute paths in path: specs","Add a CI lint rejecting unsafe segments before the sync script runs"],"tags":["path-traversal","security","validation","marketplace"],"backgroundTag":"path-traversal-blocked","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-22T16:17:23.217Z"}