hfs 3.4.0 → 3.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "hfs",
3
- "version": "3.4.0",
3
+ "version": "3.4.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "hfs",
9
- "version": "3.4.0",
9
+ "version": "3.4.1",
10
10
  "license": "GPL-3.0",
11
11
  "dependencies": {
12
12
  "@gregoranders/csv": "^0.0.13",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hfs",
3
- "version": "3.4.0",
3
+ "version": "3.4.1",
4
4
  "description": "HTTP File Server",
5
5
  "keywords": [
6
6
  "file server",
package/src/webdav.js CHANGED
@@ -62,6 +62,10 @@ function webdavStateKey(path) {
62
62
  const key = (0, vfs_1.normalizeFilename)((0, cross_1.safeDecodeURIComponent)(path, ''));
63
63
  return (0, misc_1.hasDirTraversal)(key) ? '' : key;
64
64
  }
65
+ function webdavOverwriteKey(path, ctx, ensureSession = false) {
66
+ const identity = (0, auth_1.getCurrentUsername)(ctx) || ctx.session?.sessionId || ensureSession && (0, uploadOwners_1.getSessionId)(ctx);
67
+ return identity ? webdavStateKey(path) + '|' + identity : undefined;
68
+ }
65
69
  function getWebdavLock(path) {
66
70
  return locks.get(webdavStateKey(path));
67
71
  }
@@ -181,10 +185,10 @@ const webdav = async (ctx, next) => {
181
185
  const resourceKey = resource.key;
182
186
  if (await isLocked(resourceKey, ctx, resource))
183
187
  return;
184
- const overwriteGraceKey = webdavStateKey(resourceKey) + (0, cross_1.prefix)('|', (0, auth_1.getCurrentUsername)(ctx)); // bind temporary overwrite grace to the authenticated user so accounts cannot reuse each other's grace window
188
+ const overwriteGraceKey = webdavOverwriteKey(resourceKey, ctx);
185
189
  // Finder first creates an empty file (a test?) then wants to overwrite it, which requires deletion permission, but the user may not have it, causing a renamed upload. To solve, so we give it special permission for a few seconds.
186
190
  const x = ctx.get('x-expected-entity-length'); // field used by Finder's webdav on actual upload, after
187
- if (isKnownWebdavAgent && canOverwrite.has(overwriteGraceKey)) {
191
+ if (isKnownWebdavAgent && overwriteGraceKey && canOverwrite.has(overwriteGraceKey)) {
188
192
  canOverwrite.delete(overwriteGraceKey);
189
193
  const node = await (0, vfs_1.urlToNode)(resourceKey, ctx);
190
194
  if (node?.source)
@@ -201,8 +205,11 @@ const webdav = async (ctx, next) => {
201
205
  // the upload response URI may differ from the file it actually created when VFS aliases collide
202
206
  if (isKnownWebdavAgent && ctx.body?.uri && ctx.state.uploadDestinationPath) {
203
207
  const node = await (0, uploadOwners_1.getNodeMatchingSource)(ctx.body.uri, ctx, ctx.state.uploadDestinationPath);
204
- if (node)
205
- allowWebdavOverwrite(webdavStateKey(node.vfsPath) + (0, cross_1.prefix)('|', (0, auth_1.getCurrentUsername)(ctx)));
208
+ if (node) {
209
+ const key = webdavOverwriteKey(node.vfsPath, ctx, true);
210
+ if (key)
211
+ allowWebdavOverwrite(key);
212
+ }
206
213
  }
207
214
  }
208
215
  async function handleMkcol() {
@@ -308,7 +315,8 @@ const webdav = async (ctx, next) => {
308
315
  const permissionNode = node || await (0, vfs_1.urlToNode)((0, path_1.dirname)(pathKey), ctx);
309
316
  if (!permissionNode)
310
317
  return ctx.status = cross_1.HTTP_CONFLICT;
311
- const missingWritePerm = node && canOverwrite.has(webdavStateKey(lockKey) + (0, cross_1.prefix)('|', (0, auth_1.getCurrentUsername)(ctx))) ? 0
318
+ const overwriteGraceKey = webdavOverwriteKey(lockKey, ctx);
319
+ const missingWritePerm = node && overwriteGraceKey && canOverwrite.has(overwriteGraceKey) ? 0
312
320
  : (0, vfs_1.statusCodeForMissingPerm)(permissionNode, node ? 'can_delete' : 'can_upload', ctx);
313
321
  if (missingWritePerm) {
314
322
  if (ctx.status === cross_1.HTTP_UNAUTHORIZED)
@@ -521,8 +529,9 @@ async function applyProppatchProp(prop, node, path, ctx) {
521
529
  const { source } = node;
522
530
  if (!source)
523
531
  return cross_1.HTTP_FORBIDDEN;
524
- // WebDAV clients patch metadata right after upload; outside that short same-username grace, metadata writes are file modifications
525
- const missingWritePerm = canOverwrite.has(webdavStateKey(path) + (0, cross_1.prefix)('|', (0, auth_1.getCurrentUsername)(ctx))) ? 0
532
+ // WebDAV clients patch metadata right after upload; outside that short same-uploader grace, metadata writes are file modifications
533
+ const overwriteGraceKey = webdavOverwriteKey(path, ctx);
534
+ const missingWritePerm = overwriteGraceKey && canOverwrite.has(overwriteGraceKey) ? 0
526
535
  : (0, vfs_1.statusCodeForMissingPerm)(node, 'can_delete', ctx, false);
527
536
  if (missingWritePerm)
528
537
  return missingWritePerm;