fix: do not treat a folder or user with a longer name as writable (#12450)

This commit is contained in:
Raunak Burrows
2026-11-15 14:17:54 +00:00
committed by GitHub
parent 57268b6616
commit 8c4d83c5e7
2 changed files with 12 additions and 3 deletions
+7
View File
@@ -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)
})
})
+5 -3
View File
@@ -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