mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-17 08:20:12 +00:00
fix: do not treat a folder or user with a longer name as writable (#12450)
This commit is contained in:
@@ -71,4 +71,11 @@ describe('edit rights', () => {
|
||||
expect(canEditItem('flow', 'f/demo/sum', {}, user({}), builder)).toBe(false)
|
||||
expect(canEditItem('flow', 'u/op/sum', {}, user({}), builder)).toBe(true)
|
||||
})
|
||||
|
||||
it('does not take a folder or user whose name starts the same for the writable one', () => {
|
||||
const writer = user({ folders: ['fin'] })
|
||||
expect(canEditItem('flow', 'f/fin/sum', {}, writer, FULL_CAPABILITIES)).toBe(true)
|
||||
expect(canEditItem('flow', 'f/finance/sum', {}, writer, FULL_CAPABILITIES)).toBe(false)
|
||||
expect(canEditItem('flow', 'u/ops/sum', {}, writer, FULL_CAPABILITIES)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1187,14 +1187,16 @@ export function isObviousOwner(path: string, user?: UserExt): boolean {
|
||||
if (user.is_admin || user.is_super_admin) {
|
||||
return true
|
||||
}
|
||||
let userOwner = `u/${user.username}`
|
||||
// The trailing slash keeps folder `fin` from matching `f/finance/...`, and user
|
||||
// `dev` from matching `u/devops/...`.
|
||||
let userOwner = `u/${user.username}/`
|
||||
if (path.startsWith(userOwner)) {
|
||||
return true
|
||||
}
|
||||
if (user.pgroups.findIndex((x) => path.startsWith(x)) != -1) {
|
||||
if (user.pgroups.findIndex((x) => path.startsWith(x + '/')) != -1) {
|
||||
return true
|
||||
}
|
||||
if (user.folders.findIndex((x) => path.startsWith('f/' + x)) != -1) {
|
||||
if (user.folders.findIndex((x) => path.startsWith('f/' + x + '/')) != -1) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user