fix: Allow path segments to start with 2 or more dots

This commit is contained in:
Joachim Van Herwegen 2024-03-25 09:32:53 +01:00
parent 33e9ae4191
commit 6fe6b6ec89
4 changed files with 11 additions and 7 deletions

View File

@ -205,9 +205,9 @@ export class BaseFileIdentifierMapper implements FileIdentifierMapper {
throw new BadRequestHttpError('URL needs a / after the base');
}
if (path.includes('/..')) {
this.logger.warn(`Disallowed /.. segment in URL ${identifier.path}.`);
throw new BadRequestHttpError('Disallowed /.. segment in URL');
if (path.includes('/../') || path.endsWith('/..')) {
this.logger.warn(`Disallowed /../ segment in URL ${identifier.path}.`);
throw new BadRequestHttpError('Disallowed /../ segment in URL');
}
}

View File

@ -22,9 +22,13 @@ describe('An BaseFileIdentifierMapper', (): void => {
});
it('throws 400 if the input path contains relative parts.', async(): Promise<void> => {
const result = mapper.mapUrlToFilePath({ path: `${base}test/../test2` }, false);
let result = mapper.mapUrlToFilePath({ path: `${base}test/../test2` }, false);
await expect(result).rejects.toThrow(BadRequestHttpError);
await expect(result).rejects.toThrow('Disallowed /.. segment in URL');
await expect(result).rejects.toThrow('Disallowed /../ segment in URL');
result = mapper.mapUrlToFilePath({ path: `${base}test/..` }, false);
await expect(result).rejects.toThrow(BadRequestHttpError);
await expect(result).rejects.toThrow('Disallowed /../ segment in URL');
});
it('returns the corresponding file path for container identifiers.', async(): Promise<void> => {

View File

@ -38,7 +38,7 @@ describe('An ExtensionBasedMapper', (): void => {
it('throws 400 if the input path contains relative parts.', async(): Promise<void> => {
const result = mapper.mapUrlToFilePath({ path: `${base}test/../test2` }, false);
await expect(result).rejects.toThrow(BadRequestHttpError);
await expect(result).rejects.toThrow('Disallowed /.. segment in URL');
await expect(result).rejects.toThrow('Disallowed /../ segment in URL');
});
it('returns the corresponding file path for container identifiers.', async(): Promise<void> => {

View File

@ -25,7 +25,7 @@ describe('An FixedContentTypeMapper', (): void => {
it('throws 400 if the input path contains relative parts.', async(): Promise<void> => {
const result = mapper.mapUrlToFilePath({ path: `${base}test/../test2` }, false);
await expect(result).rejects.toThrow(BadRequestHttpError);
await expect(result).rejects.toThrow('Disallowed /.. segment in URL');
await expect(result).rejects.toThrow('Disallowed /../ segment in URL');
});
it('returns the corresponding file path for container identifiers.', async(): Promise<void> => {