mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
fix: zip extraction validation (#1753)
* fix: zip extraction validation * fix
This commit is contained in:
@@ -103,6 +103,14 @@ function extractZipInternal(
|
|||||||
zipfile.on('entry', (entry) => {
|
zipfile.on('entry', (entry) => {
|
||||||
const name = entry.fileName.toString('utf8');
|
const name = entry.fileName.toString('utf8');
|
||||||
const safe = name.replace(/^\/+/, '');
|
const safe = name.replace(/^\/+/, '');
|
||||||
|
|
||||||
|
const validationError = yauzl.validateFileName(safe);
|
||||||
|
if (validationError) {
|
||||||
|
console.warn(`Skipping invalid entry (${validationError})`);
|
||||||
|
zipfile.readEntry();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (safe.startsWith('__MACOSX/')) {
|
if (safe.startsWith('__MACOSX/')) {
|
||||||
zipfile.readEntry();
|
zipfile.readEntry();
|
||||||
return;
|
return;
|
||||||
@@ -110,6 +118,15 @@ function extractZipInternal(
|
|||||||
|
|
||||||
const fullPath = path.join(target, safe);
|
const fullPath = path.join(target, safe);
|
||||||
|
|
||||||
|
const resolved = path.resolve(fullPath);
|
||||||
|
const targetResolved = path.resolve(target);
|
||||||
|
|
||||||
|
if (!resolved.startsWith(targetResolved + path.sep)) {
|
||||||
|
console.warn(`Skipping entry (path outside target): ${safe}`);
|
||||||
|
zipfile.readEntry();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Handle directories
|
// Handle directories
|
||||||
if (/\/$/.test(name)) {
|
if (/\/$/.test(name)) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user