MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / isUnsafeAbsolutePath

Function isUnsafeAbsolutePath

src/lib/installPlugin.js:372–389  ·  view source on GitHub ↗

* Detects unsafe absolute paths in zip entries that should be ignored. * Treats leading '/' as absolute, Windows drive roots like 'C:/' as absolute, * and common Android/Linux device roots like '/data', '/root', '/system'. * @param {string} p

(p)

Source from the content-addressed store, hash-verified

370 * @param {string} p
371 */
372function isUnsafeAbsolutePath(p) {
373 if (!p) return false;
374 const s = String(p);
375 if (/^[A-Za-z]:[\\\/]/.test(s)) return true; // Windows drive root
376 if (s.startsWith("//")) return true; // network path
377 if (s.startsWith("/")) {
378 return (
379 s.startsWith("/data") ||
380 s.startsWith("/system") ||
381 s.startsWith("/vendor") ||
382 s.startsWith("/storage") ||
383 s.startsWith("/sdcard") ||
384 s.startsWith("/root") ||
385 true // any leading slash is unsafe
386 );
387 }
388 return false;
389}
390
391/**
392 * Resolves Dependencies Manifest with given ids.

Callers 1

processFileFunction · 0.85

Calls 1

StringInterface · 0.85

Tested by

no test coverage detected