BlueGit

timfa filemanager

Merge feature/root-list-chmod-on-access

timfa Tim Falken · pushed by timfa

Authored 2026-05-25 · 5 months ago

Hash
a61c3c57b6c5c31022d1b35add533be3c450b398
5 files changed +170 −4
.github/technical-reference.md +8 −0
@@ -1,5 +1,9 @@
1 1 # Technical Reference
2 2
3 ## installsystemdservice.sh
4 - bool_is_true(value) - Parses common truthy string values used for installer feature flags.
5 - FILEMANAGER_SERVICE_RUN_AS_ROOT - Optional installer env flag; when true, writes a root-running systemd unit (omits User=) and enables FILEMANAGER_LIST_ACCESS_CHMOD in the unit environment.
6
3 7 ## server/index.js
4 8 - start() - Initialises DB/keys, starts HTTP/HTTPS servers, and starts the background thumbnail cache loop.
5 9 - shutdown(opts, ...servers) - Graceful teardown: stops thumbnail loop, closes DB/servers, exits with configurable code after drain/timeout.
@@ -80,6 +84,9 @@
80 84 - GET /api/files/roots - Returns readable roots with display label (alias when configured), originalName, and path.
81 85 - GET /api/files/roots - Adds a synthetic 'My folder' root for the authenticated user when userPath is configured.
82 86 - loadConfigAndRoots() - Loads config and effective roots together so route access checks stay consistent.
87 - parseOctalMode(rawValue, fallback) - Parses optional octal chmod mode overrides from environment variables and falls back to secure defaults when invalid.
88 - envFlagEnabled(name) - Boolean environment flag parser for file-route runtime feature toggles.
89 - applyRecursiveAccessChmod(startDir) - Best-effort recursive chmod pass used for Samba-style compatibility on folder-access requests; skips symlinks and continues past individual errors.
83 90 - resolveRootForUser(absPath, roots, user, config) - Resolves access for configured roots plus user-owned personal folder.
84 91 - resolveRootForUser(absPath, roots, user, config) - Allows admins to access orphaned user folders (deleted-account folders) under userPath.
85 92 - resolveRootForUser(absPath, roots, user, config) - Treats the local subtitle debug log directory as an admin-only read-only browse root for the debug menu.
@@ -96,6 +103,7 @@
96 103 - POST /api/files/folder-icon - Sets or clears a folder's explicit icon assignment; imagePath must have a cached thumbnail; write access required.
97 104 - GET /api/files/search - Fuzzy-searches all readable roots (and personal folder when configured) for files, returning ranked matches with path metadata.
98 105 - GET /api/files/list - Returns directory items including name/path/isDir plus size, mtime, and uploadedAt; uploadedAt comes from persisted `file_meta.uploaded_at` when present, otherwise it is backfilled from filesystem creation/change metadata and saved.
106 - GET /api/files/list - When FILEMANAGER_LIST_ACCESS_CHMOD=1, runs a best-effort recursive chmod on the opened folder before listing (defaults: dirs 0777, files 0666; overrides via FILEMANAGER_LIST_ACCESS_CHMOD_DIR_MODE and FILEMANAGER_LIST_ACCESS_CHMOD_FILE_MODE).
99 107 - GET /api/files/search-images - Fuzzy-searches readable roots for image files with ready thumbnails, returning capped results plus scan-truncation metadata for scalable global favicon selection.
100 108 - GET /api/files/global-favicon-image - Publicly serves the configured global favicon thumbnail file so browsers can load `<link rel="icon">` without auth headers.
101 109 - GET /api/files/global-favicon - Returns the configured global favicon source file path ({favicon:{filePath}} or {favicon:null}).
@@ -1,5 +1,9 @@
1# Technical Reference
1# Technical Reference
2
2
3## installsystemdservice.sh
4- bool_is_true(value) - Parses common truthy string values used for installer feature flags.
5- FILEMANAGER_SERVICE_RUN_AS_ROOT - Optional installer env flag; when true, writes a root-running systemd unit (omits User=) and enables FILEMANAGER_LIST_ACCESS_CHMOD in the unit environment.
6
3## server/index.js
7## server/index.js
4- start() - Initialises DB/keys, starts HTTP/HTTPS servers, and starts the background thumbnail cache loop.
8- start() - Initialises DB/keys, starts HTTP/HTTPS servers, and starts the background thumbnail cache loop.
5- shutdown(opts, ...servers) - Graceful teardown: stops thumbnail loop, closes DB/servers, exits with configurable code after drain/timeout.
9- shutdown(opts, ...servers) - Graceful teardown: stops thumbnail loop, closes DB/servers, exits with configurable code after drain/timeout.
@@ -80,6 +84,9 @@
80- GET /api/files/roots - Returns readable roots with display label (alias when configured), originalName, and path.
84- GET /api/files/roots - Returns readable roots with display label (alias when configured), originalName, and path.
81- GET /api/files/roots - Adds a synthetic 'My folder' root for the authenticated user when userPath is configured.
85- GET /api/files/roots - Adds a synthetic 'My folder' root for the authenticated user when userPath is configured.
82- loadConfigAndRoots() - Loads config and effective roots together so route access checks stay consistent.
86- loadConfigAndRoots() - Loads config and effective roots together so route access checks stay consistent.
87- parseOctalMode(rawValue, fallback) - Parses optional octal chmod mode overrides from environment variables and falls back to secure defaults when invalid.
88- envFlagEnabled(name) - Boolean environment flag parser for file-route runtime feature toggles.
89- applyRecursiveAccessChmod(startDir) - Best-effort recursive chmod pass used for Samba-style compatibility on folder-access requests; skips symlinks and continues past individual errors.
83- resolveRootForUser(absPath, roots, user, config) - Resolves access for configured roots plus user-owned personal folder.
90- resolveRootForUser(absPath, roots, user, config) - Resolves access for configured roots plus user-owned personal folder.
84- resolveRootForUser(absPath, roots, user, config) - Allows admins to access orphaned user folders (deleted-account folders) under userPath.
91- resolveRootForUser(absPath, roots, user, config) - Allows admins to access orphaned user folders (deleted-account folders) under userPath.
85- resolveRootForUser(absPath, roots, user, config) - Treats the local subtitle debug log directory as an admin-only read-only browse root for the debug menu.
92- resolveRootForUser(absPath, roots, user, config) - Treats the local subtitle debug log directory as an admin-only read-only browse root for the debug menu.
@@ -96,6 +103,7 @@
96- POST /api/files/folder-icon - Sets or clears a folder's explicit icon assignment; imagePath must have a cached thumbnail; write access required.
103- POST /api/files/folder-icon - Sets or clears a folder's explicit icon assignment; imagePath must have a cached thumbnail; write access required.
97- GET /api/files/search - Fuzzy-searches all readable roots (and personal folder when configured) for files, returning ranked matches with path metadata.
104- GET /api/files/search - Fuzzy-searches all readable roots (and personal folder when configured) for files, returning ranked matches with path metadata.
98- GET /api/files/list - Returns directory items including name/path/isDir plus size, mtime, and uploadedAt; uploadedAt comes from persisted `file_meta.uploaded_at` when present, otherwise it is backfilled from filesystem creation/change metadata and saved.
105- GET /api/files/list - Returns directory items including name/path/isDir plus size, mtime, and uploadedAt; uploadedAt comes from persisted `file_meta.uploaded_at` when present, otherwise it is backfilled from filesystem creation/change metadata and saved.
106- GET /api/files/list - When FILEMANAGER_LIST_ACCESS_CHMOD=1, runs a best-effort recursive chmod on the opened folder before listing (defaults: dirs 0777, files 0666; overrides via FILEMANAGER_LIST_ACCESS_CHMOD_DIR_MODE and FILEMANAGER_LIST_ACCESS_CHMOD_FILE_MODE).
99- GET /api/files/search-images - Fuzzy-searches readable roots for image files with ready thumbnails, returning capped results plus scan-truncation metadata for scalable global favicon selection.
107- GET /api/files/search-images - Fuzzy-searches readable roots for image files with ready thumbnails, returning capped results plus scan-truncation metadata for scalable global favicon selection.
100- GET /api/files/global-favicon-image - Publicly serves the configured global favicon thumbnail file so browsers can load `<link rel="icon">` without auth headers.
108- GET /api/files/global-favicon-image - Publicly serves the configured global favicon thumbnail file so browsers can load `<link rel="icon">` without auth headers.
101- GET /api/files/global-favicon - Returns the configured global favicon source file path ({favicon:{filePath}} or {favicon:null}).
109- GET /api/files/global-favicon - Returns the configured global favicon source file path ({favicon:{filePath}} or {favicon:null}).
.github/tests.md +1 −0
@@ -47,6 +47,7 @@
47 47 - `GET /api/files/thumbnail`
48 48 - `GET /api/files/root-access`
49 49 - `orphaned user folder access`
50 - `list access recursive chmod`
50 51 - `subtitle debug cache access`
51 52 - `folder icon endpoints`
52 53 - `file search endpoint`
@@ -47,6 +47,7 @@
47- `GET /api/files/thumbnail`
47- `GET /api/files/thumbnail`
48- `GET /api/files/root-access`
48- `GET /api/files/root-access`
49- `orphaned user folder access`
49- `orphaned user folder access`
50- `list access recursive chmod`
50- `subtitle debug cache access`
51- `subtitle debug cache access`
51- `folder icon endpoints`
52- `folder icon endpoints`
52- `file search endpoint`
53- `file search endpoint`
installsystemdservice.sh +31 −4
@@ -19,9 +19,36 @@ KNOWN_PACKAGE_MANAGERS=(apt-get apt dnf yum pacman zypper apk)
19 19 # Resolve the user who owns the project directory (i.e. the user who cloned it,
20 20 # not root). Falls back to the SUDO_USER env var, then 'pi'.
21 21 RUN_AS="${SUDO_USER:-pi}"
22 SERVICE_RUN_AS_ROOT="${FILEMANAGER_SERVICE_RUN_AS_ROOT:-0}"
23
24 bool_is_true() {
25 case "${1,,}" in
26 1|true|yes|on)
27 return 0
28 ;;
29 *)
30 return 1
31 ;;
32 esac
33 }
34
35 SERVICE_USER_LINE="User=${RUN_AS}"
36 SERVICE_CAPABILITY_LINES=$'AmbientCapabilities=CAP_NET_BIND_SERVICE\nCapabilityBoundingSet=CAP_NET_BIND_SERVICE'
37 SERVICE_ENV_LINE=""
38
39 if bool_is_true "$SERVICE_RUN_AS_ROOT"; then
40 SERVICE_USER_LINE="# Running as root (User= omitted intentionally)"
41 SERVICE_CAPABILITY_LINES="# Root mode selected: privileged-port capability lines not required"
42 SERVICE_ENV_LINE="Environment=FILEMANAGER_LIST_ACCESS_CHMOD=1"
43 fi
22 44
23 45 echo "[install] Project directory : $SCRIPT_DIR"
24 echo "[install] Service will run as user: $RUN_AS"
46 if bool_is_true "$SERVICE_RUN_AS_ROOT"; then
47 echo "[install] Service will run as root (FILEMANAGER_SERVICE_RUN_AS_ROOT=1)."
48 echo "[install] Enabling recursive chmod-on-folder-list via FILEMANAGER_LIST_ACCESS_CHMOD=1"
49 else
50 echo "[install] Service will run as user: $RUN_AS"
51 fi
25 52
26 53 log_warn() {
27 54 echo "[install][warn] $*" >&2
@@ -141,14 +168,14 @@ After=network.target
141 168
142 169 [Service]
143 170 Type=simple
144 User=${RUN_AS}
171 ${SERVICE_USER_LINE}
145 172 WorkingDirectory=${SCRIPT_DIR}
146 173 ExecStart=/bin/sh ${SCRIPT_DIR}/start.sh
147 174 Restart=always
148 175 RestartSec=5
149 176 # Allow binding to privileged ports (< 1024) without running as root.
150 AmbientCapabilities=CAP_NET_BIND_SERVICE
151 CapabilityBoundingSet=CAP_NET_BIND_SERVICE
177 ${SERVICE_CAPABILITY_LINES}
178 ${SERVICE_ENV_LINE}
152 179
153 180 [Install]
154 181 WantedBy=multi-user.target
@@ -19,9 +19,36 @@ KNOWN_PACKAGE_MANAGERS=(apt-get apt dnf yum pacman zypper apk)
19# Resolve the user who owns the project directory (i.e. the user who cloned it,
19# Resolve the user who owns the project directory (i.e. the user who cloned it,
20# not root). Falls back to the SUDO_USER env var, then 'pi'.
20# not root). Falls back to the SUDO_USER env var, then 'pi'.
21RUN_AS="${SUDO_USER:-pi}"
21RUN_AS="${SUDO_USER:-pi}"
22SERVICE_RUN_AS_ROOT="${FILEMANAGER_SERVICE_RUN_AS_ROOT:-0}"
23
24bool_is_true() {
25 case "${1,,}" in
26 1|true|yes|on)
27 return 0
28 ;;
29 *)
30 return 1
31 ;;
32 esac
33}
34
35SERVICE_USER_LINE="User=${RUN_AS}"
36SERVICE_CAPABILITY_LINES=$'AmbientCapabilities=CAP_NET_BIND_SERVICE\nCapabilityBoundingSet=CAP_NET_BIND_SERVICE'
37SERVICE_ENV_LINE=""
38
39if bool_is_true "$SERVICE_RUN_AS_ROOT"; then
40 SERVICE_USER_LINE="# Running as root (User= omitted intentionally)"
41 SERVICE_CAPABILITY_LINES="# Root mode selected: privileged-port capability lines not required"
42 SERVICE_ENV_LINE="Environment=FILEMANAGER_LIST_ACCESS_CHMOD=1"
43fi
22
44
23echo "[install] Project directory : $SCRIPT_DIR"
45echo "[install] Project directory : $SCRIPT_DIR"
24echo "[install] Service will run as user: $RUN_AS"
46if bool_is_true "$SERVICE_RUN_AS_ROOT"; then
47 echo "[install] Service will run as root (FILEMANAGER_SERVICE_RUN_AS_ROOT=1)."
48 echo "[install] Enabling recursive chmod-on-folder-list via FILEMANAGER_LIST_ACCESS_CHMOD=1"
49else
50 echo "[install] Service will run as user: $RUN_AS"
51fi
25
52
26log_warn() {
53log_warn() {
27 echo "[install][warn] $*" >&2
54 echo "[install][warn] $*" >&2
@@ -141,14 +168,14 @@ After=network.target
141
168
142[Service]
169[Service]
143Type=simple
170Type=simple
144User=${RUN_AS}
171${SERVICE_USER_LINE}
145WorkingDirectory=${SCRIPT_DIR}
172WorkingDirectory=${SCRIPT_DIR}
146ExecStart=/bin/sh ${SCRIPT_DIR}/start.sh
173ExecStart=/bin/sh ${SCRIPT_DIR}/start.sh
147Restart=always
174Restart=always
148RestartSec=5
175RestartSec=5
149# Allow binding to privileged ports (< 1024) without running as root.
176# Allow binding to privileged ports (< 1024) without running as root.
150AmbientCapabilities=CAP_NET_BIND_SERVICE
177${SERVICE_CAPABILITY_LINES}
151CapabilityBoundingSet=CAP_NET_BIND_SERVICE
178${SERVICE_ENV_LINE}
152
179
153[Install]
180[Install]
154WantedBy=multi-user.target
181WantedBy=multi-user.target
server/routes/files.js +75 −0
@@ -184,6 +184,70 @@ const upload = multer({
184 184 limits: { fileSize: 10 * 1024 * 1024 * 1024 }, // 10 GB
185 185 });
186 186
187 function parseOctalMode (rawValue, fallback)
188 {
189 const trimmed = String(rawValue || '').trim();
190 if (!trimmed) return fallback;
191 if (!/^[0-7]{3,4}$/.test(trimmed)) return fallback;
192 const parsed = Number.parseInt(trimmed, 8);
193 if (!Number.isInteger(parsed) || parsed < 0 || parsed > 0o7777) return fallback;
194 return parsed;
195 }
196
197 function envFlagEnabled (name)
198 {
199 const value = String(process.env[name] || '').trim().toLowerCase();
200 return value === '1' || value === 'true' || value === 'yes' || value === 'on';
201 }
202
203 function applyRecursiveAccessChmod (startDir)
204 {
205 const dirMode = parseOctalMode(process.env.FILEMANAGER_LIST_ACCESS_CHMOD_DIR_MODE, 0o777);
206 const fileMode = parseOctalMode(process.env.FILEMANAGER_LIST_ACCESS_CHMOD_FILE_MODE, 0o666);
207 const queue = [path.resolve(startDir)];
208
209 while (queue.length)
210 {
211 const current = queue.pop();
212 if (!current) continue;
213
214 let stat;
215 try
216 {
217 stat = fs.lstatSync(current);
218 } catch
219 {
220 continue;
221 }
222
223 if (stat.isSymbolicLink()) continue;
224
225 try
226 {
227 fs.chmodSync(current, stat.isDirectory() ? dirMode : fileMode);
228 } catch
229 {
230 // Continue best-effort; listing should still work when possible.
231 }
232
233 if (!stat.isDirectory()) continue;
234
235 let entries = [];
236 try
237 {
238 entries = fs.readdirSync(current, { withFileTypes: true });
239 } catch
240 {
241 continue;
242 }
243
244 for (const entry of entries)
245 {
246 queue.push(path.join(current, entry.name));
247 }
248 }
249 }
250
187 251 // ---------------------------------------------------------------------------
188 252 // Helpers
189 253 // ---------------------------------------------------------------------------
@@ -1045,6 +1109,17 @@ router.get('/list', requireAuth, (req, res) =>
1045 1109 const info = resolveRootForUser(dir, roots, req.user, config);
1046 1110 if (!info || !canReadInfo(req.user, info)) return res.status(403).json({ error: 'Access denied.' });
1047 1111
1112 if (envFlagEnabled('FILEMANAGER_LIST_ACCESS_CHMOD'))
1113 {
1114 try
1115 {
1116 applyRecursiveAccessChmod(dir);
1117 } catch (err)
1118 {
1119 logError('Best-effort chmod pass failed before directory listing.', err, { dir: String(dir || '') });
1120 }
1121 }
1122
1048 1123 let entries;
1049 1124 try
1050 1125 {
@@ -184,6 +184,70 @@ const upload = multer({
184 limits: { fileSize: 10 * 1024 * 1024 * 1024 }, // 10 GB
184 limits: { fileSize: 10 * 1024 * 1024 * 1024 }, // 10 GB
185});
185});
186
186
187function parseOctalMode (rawValue, fallback)
188{
189 const trimmed = String(rawValue || '').trim();
190 if (!trimmed) return fallback;
191 if (!/^[0-7]{3,4}$/.test(trimmed)) return fallback;
192 const parsed = Number.parseInt(trimmed, 8);
193 if (!Number.isInteger(parsed) || parsed < 0 || parsed > 0o7777) return fallback;
194 return parsed;
195}
196
197function envFlagEnabled (name)
198{
199 const value = String(process.env[name] || '').trim().toLowerCase();
200 return value === '1' || value === 'true' || value === 'yes' || value === 'on';
201}
202
203function applyRecursiveAccessChmod (startDir)
204{
205 const dirMode = parseOctalMode(process.env.FILEMANAGER_LIST_ACCESS_CHMOD_DIR_MODE, 0o777);
206 const fileMode = parseOctalMode(process.env.FILEMANAGER_LIST_ACCESS_CHMOD_FILE_MODE, 0o666);
207 const queue = [path.resolve(startDir)];
208
209 while (queue.length)
210 {
211 const current = queue.pop();
212 if (!current) continue;
213
214 let stat;
215 try
216 {
217 stat = fs.lstatSync(current);
218 } catch
219 {
220 continue;
221 }
222
223 if (stat.isSymbolicLink()) continue;
224
225 try
226 {
227 fs.chmodSync(current, stat.isDirectory() ? dirMode : fileMode);
228 } catch
229 {
230 // Continue best-effort; listing should still work when possible.
231 }
232
233 if (!stat.isDirectory()) continue;
234
235 let entries = [];
236 try
237 {
238 entries = fs.readdirSync(current, { withFileTypes: true });
239 } catch
240 {
241 continue;
242 }
243
244 for (const entry of entries)
245 {
246 queue.push(path.join(current, entry.name));
247 }
248 }
249}
250
187// ---------------------------------------------------------------------------
251// ---------------------------------------------------------------------------
188// Helpers
252// Helpers
189// ---------------------------------------------------------------------------
253// ---------------------------------------------------------------------------
@@ -1045,6 +1109,17 @@ router.get('/list', requireAuth, (req, res) =>
1045 const info = resolveRootForUser(dir, roots, req.user, config);
1109 const info = resolveRootForUser(dir, roots, req.user, config);
1046 if (!info || !canReadInfo(req.user, info)) return res.status(403).json({ error: 'Access denied.' });
1110 if (!info || !canReadInfo(req.user, info)) return res.status(403).json({ error: 'Access denied.' });
1047
1111
1112 if (envFlagEnabled('FILEMANAGER_LIST_ACCESS_CHMOD'))
1113 {
1114 try
1115 {
1116 applyRecursiveAccessChmod(dir);
1117 } catch (err)
1118 {
1119 logError('Best-effort chmod pass failed before directory listing.', err, { dir: String(dir || '') });
1120 }
1121 }
1122
1048 let entries;
1123 let entries;
1049 try
1124 try
1050 {
1125 {
tests/files.routes.test.js +55 −0
@@ -170,6 +170,10 @@ afterAll(() =>
170 170
171 171 beforeEach(() =>
172 172 {
173 delete process.env.FILEMANAGER_LIST_ACCESS_CHMOD;
174 delete process.env.FILEMANAGER_LIST_ACCESS_CHMOD_DIR_MODE;
175 delete process.env.FILEMANAGER_LIST_ACCESS_CHMOD_FILE_MODE;
176
173 177 fs.rmSync(rootDir, { recursive: true, force: true });
174 178 fs.mkdirSync(rootDir, { recursive: true });
175 179 if (mockUserPath)
@@ -685,6 +689,57 @@ describe('orphaned user folder access', () =>
685 689 });
686 690 });
687 691
692 describe('list access recursive chmod', () =>
693 {
694 test('GET /api/files/list applies recursive chmod when enabled', async () =>
695 {
696 const nestedDir = path.join(rootDir, 'locked');
697 const nestedFile = path.join(nestedDir, 'data.txt');
698 fs.mkdirSync(nestedDir, { recursive: true });
699 fs.writeFileSync(nestedFile, 'hello');
700
701 fs.chmodSync(rootDir, 0o700);
702 fs.chmodSync(nestedDir, 0o700);
703 fs.chmodSync(nestedFile, 0o600);
704
705 process.env.FILEMANAGER_LIST_ACCESS_CHMOD = '1';
706
707 const listRes = await req('GET', `/api/files/list?dir=${encodeURIComponent(rootDir)}`);
708 expect(listRes.status).toBe(200);
709
710 const rootMode = fs.statSync(rootDir).mode & 0o777;
711 const dirMode = fs.statSync(nestedDir).mode & 0o777;
712 const fileMode = fs.statSync(nestedFile).mode & 0o777;
713
714 expect(rootMode).toBe(0o777);
715 expect(dirMode).toBe(0o777);
716 expect(fileMode).toBe(0o666);
717 });
718
719 test('GET /api/files/list leaves permissions unchanged when disabled', async () =>
720 {
721 const nestedDir = path.join(rootDir, 'locked');
722 const nestedFile = path.join(nestedDir, 'data.txt');
723 fs.mkdirSync(nestedDir, { recursive: true });
724 fs.writeFileSync(nestedFile, 'hello');
725
726 fs.chmodSync(rootDir, 0o700);
727 fs.chmodSync(nestedDir, 0o700);
728 fs.chmodSync(nestedFile, 0o600);
729
730 const listRes = await req('GET', `/api/files/list?dir=${encodeURIComponent(rootDir)}`);
731 expect(listRes.status).toBe(200);
732
733 const rootMode = fs.statSync(rootDir).mode & 0o777;
734 const dirMode = fs.statSync(nestedDir).mode & 0o777;
735 const fileMode = fs.statSync(nestedFile).mode & 0o777;
736
737 expect(rootMode).toBe(0o700);
738 expect(dirMode).toBe(0o700);
739 expect(fileMode).toBe(0o600);
740 });
741 });
742
688 743 describe('subtitle debug cache access', () =>
689 744 {
690 745 test('admins can browse the subtitle debug cache folder', async () =>
@@ -170,6 +170,10 @@ afterAll(() =>
170
170
171beforeEach(() =>
171beforeEach(() =>
172{
172{
173 delete process.env.FILEMANAGER_LIST_ACCESS_CHMOD;
174 delete process.env.FILEMANAGER_LIST_ACCESS_CHMOD_DIR_MODE;
175 delete process.env.FILEMANAGER_LIST_ACCESS_CHMOD_FILE_MODE;
176
173 fs.rmSync(rootDir, { recursive: true, force: true });
177 fs.rmSync(rootDir, { recursive: true, force: true });
174 fs.mkdirSync(rootDir, { recursive: true });
178 fs.mkdirSync(rootDir, { recursive: true });
175 if (mockUserPath)
179 if (mockUserPath)
@@ -685,6 +689,57 @@ describe('orphaned user folder access', () =>
685 });
689 });
686});
690});
687
691
692describe('list access recursive chmod', () =>
693{
694 test('GET /api/files/list applies recursive chmod when enabled', async () =>
695 {
696 const nestedDir = path.join(rootDir, 'locked');
697 const nestedFile = path.join(nestedDir, 'data.txt');
698 fs.mkdirSync(nestedDir, { recursive: true });
699 fs.writeFileSync(nestedFile, 'hello');
700
701 fs.chmodSync(rootDir, 0o700);
702 fs.chmodSync(nestedDir, 0o700);
703 fs.chmodSync(nestedFile, 0o600);
704
705 process.env.FILEMANAGER_LIST_ACCESS_CHMOD = '1';
706
707 const listRes = await req('GET', `/api/files/list?dir=${encodeURIComponent(rootDir)}`);
708 expect(listRes.status).toBe(200);
709
710 const rootMode = fs.statSync(rootDir).mode & 0o777;
711 const dirMode = fs.statSync(nestedDir).mode & 0o777;
712 const fileMode = fs.statSync(nestedFile).mode & 0o777;
713
714 expect(rootMode).toBe(0o777);
715 expect(dirMode).toBe(0o777);
716 expect(fileMode).toBe(0o666);
717 });
718
719 test('GET /api/files/list leaves permissions unchanged when disabled', async () =>
720 {
721 const nestedDir = path.join(rootDir, 'locked');
722 const nestedFile = path.join(nestedDir, 'data.txt');
723 fs.mkdirSync(nestedDir, { recursive: true });
724 fs.writeFileSync(nestedFile, 'hello');
725
726 fs.chmodSync(rootDir, 0o700);
727 fs.chmodSync(nestedDir, 0o700);
728 fs.chmodSync(nestedFile, 0o600);
729
730 const listRes = await req('GET', `/api/files/list?dir=${encodeURIComponent(rootDir)}`);
731 expect(listRes.status).toBe(200);
732
733 const rootMode = fs.statSync(rootDir).mode & 0o777;
734 const dirMode = fs.statSync(nestedDir).mode & 0o777;
735 const fileMode = fs.statSync(nestedFile).mode & 0o777;
736
737 expect(rootMode).toBe(0o700);
738 expect(dirMode).toBe(0o700);
739 expect(fileMode).toBe(0o600);
740 });
741});
742
688describe('subtitle debug cache access', () =>
743describe('subtitle debug cache access', () =>
689{
744{
690 test('admins can browse the subtitle debug cache folder', async () =>
745 test('admins can browse the subtitle debug cache folder', async () =>