This commit is contained in:
Chad Curtis committed 2025-09-28 18:31:10 +00:00
1 parent 9507177aaa
commit 2ea05addcc
4 files changed
+67 -61

No files matched your search

+45
View File
@@ -3,6 +3,7 @@ import { ProjectsManager } from './ProjectsManager';
import { JSRuntimeFS } from './JSRuntime';
import { Git } from './git';
import type { NPool } from '@nostrify/nostrify';
import type JSZip from 'jszip';
const createMockNostr = (): NPool => ({
req: vi.fn(),
@@ -438,6 +439,50 @@ describe('ProjectsManager', () => {
vi.restoreAllMocks();
}
});
it('should prevent zip slip attacks during bulk file extraction', async () => {
await projectsManager.init();
// Create a mock ZIP with malicious paths for bulk import
const mockZip = {
files: {
'projects/project1/../../../etc/passwd': {
dir: false,
async: vi.fn().mockResolvedValue(new Uint8Array([1, 2, 3]))
},
'projects/project1/../../outside.txt': {
dir: false,
async: vi.fn().mockResolvedValue(new Uint8Array([4, 5, 6]))
},
'projects/project1/safe-file.txt': {
dir: false,
async: vi.fn().mockResolvedValue(new Uint8Array([7, 8, 9]))
}
}
};
// Spy on console.warn to check for security warnings
const consoleSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
try {
// Extract files from the malicious ZIP for bulk import
const files = await projectsManager.extractFilesFromZip(mockZip as unknown as JSZip, 'projects/project1');
// Should only contain safe files
expect(Object.keys(files)).toEqual(['safe-file.txt']);
expect(files['safe-file.txt']).toEqual(new Uint8Array([7, 8, 9]));
// Should have logged a security warning about skipped files
expect(consoleSpy).toHaveBeenCalledWith(
expect.stringContaining('Skipped 2 files due to resolving to paths outside of project directory:'),
['projects/project1/../../../etc/passwd', 'projects/project1/../../outside.txt']
);
} finally {
// Restore mocks
consoleSpy.mockRestore();
}
});
});
describe('renameProject', () => {
+12
View File
@@ -900,6 +900,7 @@ export class ProjectsManager {
async extractFilesFromZip(zip: JSZip, projectPath: string): Promise<{ [path: string]: Uint8Array }> {
const files: { [path: string]: Uint8Array } = {};
const skippedFiles: string[] = [];
const securitySkippedFiles: string[] = [];
for (const [relativePath, zipEntry] of Object.entries(zip.files)) {
if (zipEntry.dir) continue;
@@ -915,6 +916,13 @@ export class ProjectsManager {
// Skip empty paths (shouldn't happen due to the dir check above, but just in case)
if (!fileRelativePath) continue;
// Validate extraction path is safe (zip slip protection)
// Check for directory traversal attempts in the original path
if (fileRelativePath.includes('../') || fileRelativePath.includes('..\\') || fileRelativePath.startsWith('/') || fileRelativePath.startsWith('\\')) {
securitySkippedFiles.push(relativePath);
continue;
}
try {
const content = await zipEntry.async('uint8array');
files[fileRelativePath] = content;
@@ -924,6 +932,10 @@ export class ProjectsManager {
}
}
if (securitySkippedFiles.length > 0) {
console.warn(`Skipped ${securitySkippedFiles.length} files due to resolving to paths outside of project directory:`, securitySkippedFiles);
}
if (skippedFiles.length > 0) {
console.warn(`Skipped ${skippedFiles.length} files due to extraction errors:`, skippedFiles);
}
-9
View File
@@ -250,8 +250,6 @@ const resources = {
persistentStorageNotSupportedDescription: 'Your browser does not support persistent storage requests.',
failedToRequestPersistentStorage: 'Failed to request persistent storage',
// 404 Page
pageNotFound: 'Oops! Page not found',
returnToHome: 'Return to Home',
@@ -552,8 +550,6 @@ const resources = {
persistentStorageNotSupportedDescription: 'Seu navegador não suporta solicitações de armazenamento persistente.',
failedToRequestPersistentStorage: 'Falha ao solicitar armazenamento persistente',
// About Settings
aboutShakespeare: 'Sobre o Shakespeare',
aboutShakespeareDescription: 'Informações sobre o Shakespeare.',
@@ -863,8 +859,6 @@ const resources = {
persistentStorageNotSupportedDescription: '您的浏览器不支持持久存储请求。',
failedToRequestPersistentStorage: '请求持久存储失败',
// About Settings
aboutShakespeare: '关于Shakespeare',
aboutShakespeareDescription: '关于Shakespeare的信息。',
@@ -1174,7 +1168,6 @@ const resources = {
persistentStorageNotSupportedDescription: 'Burauzar ku ba ta goyan bayan bukatun ajiyar ta dindindin ba.',
failedToRequestPersistentStorage: 'Ya gaza neman ajiyar ta dindindin',
// About Settings
aboutShakespeare: 'Game da Shakespeare',
aboutShakespeareDescription: 'Bayani game da Shakespeare.',
@@ -1484,7 +1477,6 @@ const resources = {
persistentStorageNotSupportedDescription: 'Aṣawakiri rẹ ko ni atilẹyin awọn ibeere ibi ipamọ ti o wa nigbagbogbo.',
failedToRequestPersistentStorage: 'O kuna lati beere ibi ipamọ ti o wa nigbagbogbo',
// About Settings
aboutShakespeare: 'Nipa Shakespeare',
aboutShakespeareDescription: 'Alaye nipa Shakespeare.',
@@ -1789,7 +1781,6 @@ const resources = {
persistentStorageNotSupportedDescription: 'Browser gị akwadoghị arịrịọ nchekwa na-adịgide adịgide.',
failedToRequestPersistentStorage: 'O dara ịrịọ nchekwa na-adịgide adịgide',
// About Settings
aboutShakespeare: 'Gbasara Shakespeare',
aboutShakespeareDescription: 'Ozi gbasara Shakespeare.',