-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔒 Limited permissions for uploaded files to 0644 (#21841)
Fixes https://linear.app/ghost/issue/ENG-1010/uploaded-file-permission-security-improvement - This commit ensures all files uploaded to Ghost via importer are set with 0644 permissions to improve security. - Uploaded files previously retained their original permissions, which could leave them executable. - This commit prevents files from being inadvertently executable.
- Loading branch information
Showing
3 changed files
with
29 additions
and
0 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
25 changes: 25 additions & 0 deletions
25
ghost/core/test/unit/server/data/importer/import-manager.test.js
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,25 @@ | ||
const should = require('should'); | ||
const fs = require('fs-extra'); | ||
const path = require('path'); | ||
const glob = require('glob'); | ||
const importManager = require('../../../../../core/server/data/importer/import-manager'); | ||
|
||
describe('Import Manager', function () { | ||
describe('extractZip', function () { | ||
it('extracts zip file and sets correct file permissions', async function () { | ||
const zipPath = path.join(__dirname, '/test.zip'); | ||
const extractedPath = await importManager.extractZip(zipPath); | ||
try { | ||
const files = glob.sync('**/*', {cwd: extractedPath, nodir: true}); | ||
files.forEach((file) => { | ||
const filePath = path.join(extractedPath, file); | ||
const stats = fs.statSync(filePath); | ||
const fileMode = stats.mode & 0o777; | ||
should.equal(fileMode, 0o644, `File ${file} should have 0644 permissions`); | ||
}); | ||
} finally { | ||
await fs.remove(extractedPath); | ||
} | ||
}); | ||
}); | ||
}); |
Binary file not shown.