Skip to content

A local-first personal finance app

:cloud: Fix server sync file download when server-files are in .config (#6010)

Michael Clark37481535e7fb
diff --git a/packages/desktop-client/.gitignore b/packages/desktop-client/.gitignore
index eb9b164f0d..caa3f96e73 100644
--- a/packages/desktop-client/.gitignore
+++ b/packages/desktop-client/.gitignore
@@ -31,3 +31,6 @@ public/*.wasm
# translations
locale/
+
+# service worker build output
+dev-dist
diff --git a/packages/sync-server/src/app-sync.ts b/packages/sync-server/src/app-sync.ts
index e40923cb74..b9ea23ac99 100644
--- a/packages/sync-server/src/app-sync.ts
+++ b/packages/sync-server/src/app-sync.ts
@@ -1,6 +1,7 @@
// @ts-strict-ignore
import { Buffer } from 'node:buffer';
import fs from 'node:fs/promises';
+import { resolve } from 'node:path';
import { SyncProtoBuf } from '@actual-app/crdt';
import express from 'express';
@@ -306,8 +307,16 @@ app.get('/download-user-file', async (req, res) => {
return;
}
+ const path = getPathForUserFile(fileId);
+
+ if (!path.startsWith(resolve(config.get('userFiles')))) {
+ //Ensure the user doesn't try to access files outside of the user files directory
+ res.status(403).send('Access denied');
+ return;
+ }
+
res.setHeader('Content-Disposition', `attachment;filename=${fileId}`);
- res.sendFile(getPathForUserFile(fileId));
+ res.sendFile(path, { dotfiles: 'allow' });
});
app.post('/update-user-filename', (req, res) => {
diff --git a/upcoming-release-notes/6010.md b/upcoming-release-notes/6010.md
new file mode 100644
index 0000000000..80ef5d7f80
--- /dev/null
+++ b/upcoming-release-notes/6010.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [MikesGlitch]
+---
+
+Fix sync server file download when files are in .config directory on linux