backend-common: added test to ensure malicious zip archives are handled
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Binary file not shown.
@@ -28,6 +28,9 @@ const archiveDataCorrupted = fs.readFileSync(
|
||||
const archiveDataWithExtraDir = fs.readFileSync(
|
||||
resolvePath(__filename, '../../__fixtures__/mock-with-extra-root-dir.zip'),
|
||||
);
|
||||
const archiveWithMaliciousEntry = fs.readFileSync(
|
||||
resolvePath(__filename, '../../__fixtures__/mallory.zip'),
|
||||
);
|
||||
|
||||
describe('ZipArchiveResponse', () => {
|
||||
beforeEach(() => {
|
||||
@@ -35,6 +38,7 @@ describe('ZipArchiveResponse', () => {
|
||||
'/test-archive.zip': archiveData,
|
||||
'/test-archive-with-extra-root-dir.zip': archiveDataWithExtraDir,
|
||||
'/test-archive-corrupted.zip': archiveDataCorrupted,
|
||||
'/test-archive-malicious.zip': archiveWithMaliciousEntry,
|
||||
'/tmp': mockFs.directory(),
|
||||
});
|
||||
});
|
||||
@@ -167,4 +171,22 @@ describe('ZipArchiveResponse', () => {
|
||||
'invalid comment length. expected: 55. found: 0',
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw on entries with a path outside the destination dir', async () => {
|
||||
const stream = fs.createReadStream('/test-archive-malicious.zip');
|
||||
|
||||
const res = new ZipArchiveResponse(stream, '', '/tmp', 'etag');
|
||||
await expect(res.files()).rejects.toThrow(
|
||||
'invalid relative path: ../side.txt',
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw on entries that attempt to write outside destination dir', async () => {
|
||||
const stream = fs.createReadStream('/test-archive-malicious.zip');
|
||||
|
||||
const res = new ZipArchiveResponse(stream, '', '/tmp', 'etag');
|
||||
await expect(res.dir()).rejects.toThrow(
|
||||
'invalid relative path: ../side.txt',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user