(instancePath, profileRoot)
| 170 | } |
| 171 | |
| 172 | function 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 | |
| 202 | async function defaultRunPs() { |
| 203 | const { stdout } = await execFileAsync( |
no test coverage detected