Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions Sources/wired3/Controllers/FilesController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,25 @@ public class FilesController {
return
}

let finalPath = resolveAliasesAndSymlinks(in: realPath)

// Prevent privilege escalation: block a non-owner from assigning themselves as owner,
// which would grant new read access to the folder.
// finalPath (alias/symlink-resolved) is used so metadata is read from the canonical location.
if let existingPrivileges = FilePrivilege(path: finalPath) {
if existingPrivileges.owner != user.username,
owner == user.username {
App.serverController.replyError(client: client, error: "wired.error.permission_denied", message: message)
return
}
} else if owner == user.username,
!user.hasPrivilege(name: "wired.account.account.edit_users") {
// No permissions file yet: only admins (edit_users) may claim initial ownership to
// prevent a first-caller-wins escalation on folders never explicitly permissioned.
App.serverController.replyError(client: client, error: "wired.error.permission_denied", message: message)
return
}

var mode: File.FilePermissions = []
if ownerRead { mode.insert(.ownerRead) }
if ownerWrite { mode.insert(.ownerWrite) }
Expand All @@ -636,8 +655,6 @@ public class FilesController {
if everyoneRead { mode.insert(.everyoneRead) }
if everyoneWrite { mode.insert(.everyoneWrite) }

let finalPath = resolveAliasesAndSymlinks(in: realPath)

let wiredMetaPath = finalPath.stringByAppendingPathComponent(path: ".wired")
do {
try FileManager.default.createDirectory(atPath: wiredMetaPath, withIntermediateDirectories: true, attributes: nil)
Expand Down
Loading