Merge remote-tracking branch 'origin/master' into task-action-idempotency

Signed-off-by: bnechyporenko <bnechyporenko@bol.com>
This commit is contained in:
bnechyporenko
2024-02-23 08:51:40 +01:00
3 changed files with 16 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-common': patch
---
Resolve the `basePath` before constructing the target path
@@ -59,5 +59,11 @@ describe('paths', () => {
'Relative path is not allowed to refer to a directory outside its parent',
);
});
it('should not throw an error when a folder is referenced that doesnt already exist', () => {
expect(resolveSafeChildPath(workspacePath, 'template')).toEqual(
`${workspacePath}/template`,
);
});
});
});
+5 -3
View File
@@ -63,15 +63,17 @@ export function resolvePackagePath(name: string, ...paths: string[]) {
* @returns A path that is guaranteed to point to or within the base path.
*/
export function resolveSafeChildPath(base: string, path: string): string {
const targetPath = resolvePath(base, path);
const resolvedBasePath = resolveRealPath(base);
const targetPath = resolvePath(resolvedBasePath, path);
if (!isChildPath(resolveRealPath(base), resolveRealPath(targetPath))) {
if (!isChildPath(resolvedBasePath, resolveRealPath(targetPath))) {
throw new NotAllowedError(
'Relative path is not allowed to refer to a directory outside its parent',
);
}
return targetPath;
// Don't return the resolved path as the original could be a symlink
return resolvePath(base, path);
}
function resolveRealPath(path: string): string {