Improve nested path detection across app
This commit is contained in:
parent
57d206a344
commit
f8fc23a7a3
5 changed files with 169 additions and 12 deletions
|
@ -26,6 +26,7 @@ import { Dialogs } from '../types/Dialogs';
|
|||
// @ts-ignore
|
||||
import * as packageJson from '../../package.json';
|
||||
import { getSignatureFileName } from './signature';
|
||||
import { isPathInside } from '../util/isPathInside';
|
||||
|
||||
import { LocaleType } from '../types/I18N';
|
||||
import { LoggerType } from '../types/Logging';
|
||||
|
@ -71,7 +72,7 @@ export async function checkForUpdates(
|
|||
export function validatePath(basePath: string, targetPath: string) {
|
||||
const normalized = normalize(targetPath);
|
||||
|
||||
if (!normalized.startsWith(basePath)) {
|
||||
if (!isPathInside(normalized, basePath)) {
|
||||
throw new Error(
|
||||
`validatePath: Path ${normalized} is not under base path ${basePath}`
|
||||
);
|
||||
|
@ -352,7 +353,7 @@ export async function deleteTempDir(targetDir: string) {
|
|||
}
|
||||
|
||||
const baseTempDir = getBaseTempDir();
|
||||
if (!targetDir.startsWith(baseTempDir)) {
|
||||
if (!isPathInside(targetDir, baseTempDir)) {
|
||||
throw new Error(
|
||||
`deleteTempDir: Cannot delete path '${targetDir}' since it is not within base temp dir`
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue