-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugin-ext: validate path when unpacking archives
Fix zip-slip by validating where a given file will be unpacked. If the expected path is outside of the destination folder: log a warning and ignore the file. This commit includes an archive that will trigger the exploit by writing a file to `/tmp/slipped.txt`. This comes from kevva/decompress#71 (comment) Fixes #7319 Signed-off-by: Paul Maréchal <paul.marechal@ericsson.com>
- Loading branch information
1 parent
07a2616
commit 94fbe5b
Showing
4 changed files
with
98 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
packages/plugin-ext/src/main/node/plugin-deployer-file-handler-context-impl.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2020 Ericsson and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
/* eslint-disable no-unused-expressions */ | ||
|
||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import rimraf = require('rimraf'); | ||
import { expect } from 'chai'; | ||
import { PluginDeployerFileHandlerContextImpl } from './plugin-deployer-file-handler-context-impl'; | ||
|
||
const testDataPath = path.join(__dirname, '../../../src/main/node/test-data'); | ||
|
||
describe('PluginDeployerFileHandlerContextImpl', () => { | ||
|
||
/** | ||
* Clean resources after a test. | ||
*/ | ||
const finalizers: Array<() => void> = []; | ||
|
||
beforeEach(() => { | ||
finalizers.length = 0; | ||
}); | ||
|
||
afterEach(() => { | ||
for (const finalize of finalizers) { | ||
try { | ||
finalize(); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} | ||
}); | ||
|
||
it('should prevent zip-slip', async function (): Promise<void> { | ||
if (process.platform === 'win32') { | ||
this.skip(); // Test will not work on Windows (because of the /tmp path) | ||
} | ||
|
||
const dest = fs.mkdtempSync('/tmp/plugin-ext-test'); | ||
finalizers.push(() => rimraf.sync(dest)); | ||
|
||
const zipSlipArchivePath = path.join(testDataPath, 'slip.tar.gz'); | ||
const slippedFilePath = '/tmp/slipped.txt'; | ||
|
||
finalizers.push(() => rimraf.sync(slippedFilePath)); | ||
rimraf.sync(slippedFilePath); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const pluginDeployerFileHandlerContext = new PluginDeployerFileHandlerContextImpl(undefined as any); | ||
await pluginDeployerFileHandlerContext.unzip(zipSlipArchivePath, dest); | ||
|
||
expect(fs.existsSync(slippedFilePath)).false; | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.