-
Notifications
You must be signed in to change notification settings - Fork 4
Project/Version rename, multi-game support, depenency rework & other changes #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Dependency rework
(cherry picked from commit 62253e6)
…y? localized entirely within your kitchen? (begin validation against swagger file)
Rename Mod/ModVersion to Project/Version
…ame, disable beatmods importer, update api responses to not send generic messages
This reverts commit 6c8be9c.
…tAPIPublicResponse` instead.
| }).then(async (project) => { | ||
| DatabaseHelper.refreshCache(`projects`); | ||
| if (iconIsValid) { | ||
| (icon as UploadedFile).mv(filePath); |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression High
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 6 months ago
To fix the issue, we need to ensure that the constructed filePath is both normalized and validated to prevent directory traversal or other attacks. This can be achieved by:
- Using
path.resolveto normalize the path and remove any..segments. - Using
fs.realpathSyncto resolve symbolic links and ensure the path points to a real location. - Validating that the resolved path starts with the expected root directory (
Config.storage.iconsDir).
Additionally, we should sanitize the icon.name using a library like sanitize-filename to remove any special characters that could be used maliciously.
Changes required:
- Add the
sanitize-filenamepackage to sanitizeicon.name. - Update the construction and validation of
filePathto include normalization, symbolic link resolution, and sanitization.
-
Copy modified lines R3-R4 -
Copy modified lines R91-R94
| @@ -2,2 +2,4 @@ | ||
| import path from 'node:path'; | ||
| import fs from 'node:fs'; | ||
| import sanitize from 'sanitize-filename'; | ||
| import { DatabaseHelper, ContentHash, Status, UserRoles } from '../../../shared/Database.ts'; | ||
| @@ -88,4 +90,6 @@ | ||
| // move the icon to the correct location | ||
| filePath = `${path.resolve(Config.storage.iconsDir)}/${icon.md5}${path.extname(icon.name)}`; | ||
| if (filePath.startsWith(`${path.resolve(Config.storage.iconsDir)}`) == false) { | ||
| const sanitizedFileName = sanitize(icon.name); | ||
| filePath = path.resolve(Config.storage.iconsDir, `${icon.md5}${path.extname(sanitizedFileName)}`); | ||
| const resolvedFilePath = fs.realpathSync(filePath); | ||
| if (!resolvedFilePath.startsWith(fs.realpathSync(Config.storage.iconsDir))) { | ||
| iconIsValid = false; |
-
Copy modified lines R40-R41
| @@ -39,3 +39,4 @@ | ||
| "zod": "^3.24.1", | ||
| "zod-validation-error": "^3.4.1" | ||
| "zod-validation-error": "^3.4.1", | ||
| "sanitize-filename": "^1.6.3" | ||
| }, |
| Package | Version | Security advisories |
| sanitize-filename (npm) | 1.6.3 | None |
| if (filePath.startsWith(`${path.resolve(Config.storage.modsDir)}`) == false) { | ||
| return res.status(400).send({ message: `Invalid zip file.` }); | ||
| } else { | ||
| file.mv(filePath); |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression High
user-provided value
| let oldFileName = project.iconFileName; | ||
| project.iconFileName = `${icon.md5}${path.extname(icon.name)}`; | ||
| project.save().then((project) => { | ||
| icon.mv(filePath, (error) => { |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression High
closes #88
closes #4
closes #83
closes #23