Skip to content

Commit

Permalink
Patch path traversal in move-files that can be used by `administrator…
Browse files Browse the repository at this point in the history
…` level attacker only
  • Loading branch information
timothycarambat committed Aug 27, 2024
1 parent f519a4b commit 47a5c71
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const HistoricalMessage = ({
saveChanges={saveEditedMessage}
/>
) : (
<div className={'overflow-x-scroll break-words'}>
<div className={"overflow-x-scroll break-words"}>
<span
className={`flex flex-col gap-y-1`}
dangerouslySetInnerHTML={{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"node": ">=18"
},
"scripts": {
"lint": "cd server && yarn lint && cd ../frontend && yarn lint && cd ../embed && yarn lint && cd ../collector && yarn lint",
"lint": "cd server && yarn lint && cd ../frontend && yarn lint && cd ../collector && yarn lint",
"setup": "cd server && yarn && cd ../collector && yarn && cd ../frontend && yarn && cd .. && yarn setup:envs && yarn prisma:setup && echo \"Please run yarn dev:server, yarn dev:collector, and yarn dev:frontend in separate terminal tabs.\"",
"setup:envs": "cp -n ./frontend/.env.example ./frontend/.env && cp -n ./server/.env.example ./server/.env.development && cp -n ./collector/.env.example ./collector/.env && cp -n ./docker/.env.example ./docker/.env && echo \"All ENV files copied!\n\"",
"dev:server": "cd server && yarn dev",
Expand Down
6 changes: 6 additions & 0 deletions server/endpoints/api/document/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,12 @@ function apiDocumentEndpoints(app) {
const sourcePath = path.join(documentsPath, normalizePath(from));
const destinationPath = path.join(documentsPath, normalizePath(to));
return new Promise((resolve, reject) => {
if (
!isWithin(documentsPath, sourcePath) ||
!isWithin(documentsPath, destinationPath)
)
return reject("Invalid file location");

fs.rename(sourcePath, destinationPath, (err) => {
if (err) {
console.error(`Error moving file ${from} to ${to}:`, err);
Expand Down
6 changes: 6 additions & 0 deletions server/endpoints/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ function documentEndpoints(app) {
const destinationPath = path.join(documentsPath, normalizePath(to));

return new Promise((resolve, reject) => {
if (
!isWithin(documentsPath, sourcePath) ||
!isWithin(documentsPath, destinationPath)
)
return reject("Invalid file location");

fs.rename(sourcePath, destinationPath, (err) => {
if (err) {
console.error(`Error moving file ${from} to ${to}:`, err);
Expand Down
12 changes: 6 additions & 6 deletions server/models/browserExtensionApiKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ const BrowserExtensionApiKey = {

/**
* Gets browser keys by params
* @param {object} clause
* @param {number|null} limit
* @param {object|null} orderBy
* @param {object} clause
* @param {number|null} limit
* @param {object|null} orderBy
* @returns {Promise<import("@prisma/client").browser_extension_api_keys[]>}
*/
where: async function (clause = {}, limit = null, orderBy = null) {
Expand All @@ -111,9 +111,9 @@ const BrowserExtensionApiKey = {
/**
* Get browser API keys for user
* @param {import("@prisma/client").users} user
* @param {object} clause
* @param {number|null} limit
* @param {object|null} orderBy
* @param {object} clause
* @param {number|null} limit
* @param {object|null} orderBy
* @returns {Promise<import("@prisma/client").browser_extension_api_keys[]>}
*/
whereWithUser: async function (
Expand Down

0 comments on commit 47a5c71

Please sign in to comment.