MCPcopy Create free account
hub / github.com/chhoumann/quickadd / assertSafeInstancePath

Function assertSafeInstancePath

scripts/stop-obsidian-e2e-instance.mjs:172–200  ·  view source on GitHub ↗
(instancePath, profileRoot)

Source from the content-addressed store, hash-verified

170}
171
172function assertSafeInstancePath(instancePath, profileRoot) {
173 if (!instancePath || !path.isAbsolute(instancePath)) {
174 throw new Error(
175 `Refusing to remove non-absolute instance path: ${instancePath}`,
176 );
177 }
178 const base = path.basename(instancePath);
179 if (!INSTANCE_DIR_PATTERN.test(base)) {
180 throw new Error(
181 `Refusing to remove ${instancePath}: not an Obsidian E2E instance directory.`,
182 );
183 }
184 // A real instance dir is several levels deep (e.g. /tmp/quickadd-obsidian-e2e/<id>);
185 // reject anything shallow enough to be a system root.
186 if (instancePath.split(path.sep).filter(Boolean).length < 2) {
187 throw new Error(`Refusing to remove shallow path: ${instancePath}`);
188 }
189 // Containment guard: when the caller knows the profile root, the dir we remove
190 // must be a direct child of it. Real callers always do, so a bad --profile-root
191 // can never make us rm a path outside the e2e profile tree.
192 if (
193 profileRoot &&
194 path.resolve(path.dirname(instancePath)) !== path.resolve(profileRoot)
195 ) {
196 throw new Error(
197 `Refusing to remove ${instancePath}: not a direct child of profile root ${profileRoot}.`,
198 );
199 }
200}
201
202async function defaultRunPs() {
203 const { stdout } = await execFileAsync(

Callers 1

stopInstanceFunction · 0.85

Calls 3

isAbsoluteMethod · 0.80
dirnameMethod · 0.80
resolveMethod · 0.45

Tested by

no test coverage detected