Resolve attachments folder before using it
This commit is contained in:
parent
50100906f3
commit
b7f0ec61b9
2 changed files with 36 additions and 17 deletions
|
@ -9,6 +9,15 @@ import type {
|
||||||
|
|
||||||
import { isAbsolute, normalize } from 'path';
|
import { isAbsolute, normalize } from 'path';
|
||||||
import { existsSync, realpathSync } from 'fs';
|
import { existsSync, realpathSync } from 'fs';
|
||||||
|
import {
|
||||||
|
getAvatarsPath,
|
||||||
|
getBadgesPath,
|
||||||
|
getDraftPath,
|
||||||
|
getPath,
|
||||||
|
getStickersPath,
|
||||||
|
getTempPath,
|
||||||
|
getUpdateCachePath,
|
||||||
|
} from '../ts/util/attachments';
|
||||||
|
|
||||||
type CallbackType = (response: string | ProtocolResponse) => void;
|
type CallbackType = (response: string | ProtocolResponse) => void;
|
||||||
|
|
||||||
|
@ -51,6 +60,17 @@ function _createFileHandler({
|
||||||
installPath: string;
|
installPath: string;
|
||||||
isWindows: boolean;
|
isWindows: boolean;
|
||||||
}) {
|
}) {
|
||||||
|
const allowedRoots = [
|
||||||
|
userDataPath,
|
||||||
|
installPath,
|
||||||
|
getAvatarsPath(userDataPath),
|
||||||
|
getBadgesPath(userDataPath),
|
||||||
|
getDraftPath(userDataPath),
|
||||||
|
getPath(userDataPath),
|
||||||
|
getStickersPath(userDataPath),
|
||||||
|
getTempPath(userDataPath),
|
||||||
|
getUpdateCachePath(userDataPath),
|
||||||
|
];
|
||||||
return (request: ProtocolRequest, callback: CallbackType): void => {
|
return (request: ProtocolRequest, callback: CallbackType): void => {
|
||||||
let targetPath;
|
let targetPath;
|
||||||
|
|
||||||
|
@ -95,24 +115,17 @@ function _createFileHandler({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
for (const root of allowedRoots) {
|
||||||
!properCasing.startsWith(
|
if (properCasing.startsWith(isWindows ? root.toLowerCase() : root)) {
|
||||||
isWindows ? userDataPath.toLowerCase() : userDataPath
|
callback({ path: realPath });
|
||||||
) &&
|
return;
|
||||||
!properCasing.startsWith(
|
}
|
||||||
isWindows ? installPath.toLowerCase() : installPath
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
console.log(
|
|
||||||
`Warning: denying request to path '${realPath}' (userDataPath: '${userDataPath}', installPath: '${installPath}')`
|
|
||||||
);
|
|
||||||
callback({ error: -10 });
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
callback({
|
console.log(
|
||||||
path: realPath,
|
`Warning: denying request to path '${realPath}' (allowedRoots: '${allowedRoots}')`
|
||||||
});
|
);
|
||||||
|
callback({ error: -10 });
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,13 @@ const createPathGetter =
|
||||||
if (!isString(userDataPath)) {
|
if (!isString(userDataPath)) {
|
||||||
throw new TypeError("'userDataPath' must be a string");
|
throw new TypeError("'userDataPath' must be a string");
|
||||||
}
|
}
|
||||||
return join(userDataPath, subpath);
|
|
||||||
|
const maybeSymlink = join(userDataPath, subpath);
|
||||||
|
if (fse.pathExistsSync(maybeSymlink)) {
|
||||||
|
return fse.realpathSync(maybeSymlink);
|
||||||
|
}
|
||||||
|
|
||||||
|
return maybeSymlink;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getAvatarsPath = createPathGetter(AVATAR_PATH);
|
export const getAvatarsPath = createPathGetter(AVATAR_PATH);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue