Skip to content

Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.

fix(backend:webdav): ensure lock paths in headers are decoded correctly

johavenceb2f3880327
diff --git a/backend/src/applications/webdav/guards/webdav-protocol.guard.ts b/backend/src/applications/webdav/guards/webdav-protocol.guard.ts
index 9bff9b62..d78cbb19 100644
--- a/backend/src/applications/webdav/guards/webdav-protocol.guard.ts
+++ b/backend/src/applications/webdav/guards/webdav-protocol.guard.ts
@@ -237,7 +237,7 @@ export class WebDAVProtocolGuard implements CanActivate {
if (!req.headers[HEADER.DESTINATION]) {
throw new HttpException(`Missing ${HEADER.DESTINATION} header`, HttpStatus.BAD_REQUEST)
}
- const destination = decodeUrl(urlToPath(req.headers[HEADER.DESTINATION] as string))
+ const destination = urlToPath(req.headers[HEADER.DESTINATION] as string)
if (!REGEX_BASE_PATH.test(destination)) {
this.logger.warn(`The destination does not match the webdav base path : ${destination}`)
throw new HttpException('The destination does not match', HttpStatus.BAD_REQUEST)
diff --git a/backend/src/common/functions.ts b/backend/src/common/functions.ts
index 41f6cc1c..7058aaba 100755
--- a/backend/src/common/functions.ts
+++ b/backend/src/common/functions.ts
@@ -13,6 +13,7 @@ import { ValidatorOptions } from 'class-validator/types/validation/ValidatorOpti
import crypto from 'node:crypto'
import { setTimeout } from 'node:timers/promises'
import { SPACE_PERMS_SEP } from '../applications/spaces/constants/spaces'
+import { decodeUrl } from './shared'
export const regexpEscape = /[.*+?^${}()|[\]\\]/g
export const regexSpecialChars = /[-[\]{}()*+!<=:?./\\^$|#,]/g
@@ -56,13 +57,15 @@ export function formatDateISOString(date: Date): string {
export function urlToPath(url: string): string {
// transform https://sync-in.com/webdav/ to /webdav/
+ let path: string
try {
// transform https://sync-in.com/webdav/ to /webdav/
- return new URL(url).pathname
+ path = new URL(url).pathname
} catch {
// or allows uri like : /webdav/
- return url
+ path = url
}
+ return decodeUrl(path)
}
export async function hashPassword(password: string): Promise<string> {