fix: mask "**/*.ext" was limited to depth 1
Massimo Melina committed
Apr 10, 2023 at 11:30 UTC
f385d680ef1b33ac781c35c1146b4daaabd6bdcf
3 files changed
+14
-5
src/vfs.ts
+10
-4
@@ -54,8 +54,11 @@ export const defaultPerms: VfsPerm = {
54
export const MIME_AUTO = 'auto'
55
56
function inheritFromParent(parent: VfsNode, child: VfsNode) {
57
- for (const k of typedKeys(defaultPerms))
58
- child[k] ??= parent[k]
57
+ for (const k of typedKeys(defaultPerms)) {
58
+ const v = parent[k]
59
+ if (v !== undefined) // small optimization: don't expand the object
60
+ child[k] ??= v
61
+ }
62
if (typeof parent.mime === 'object' && typeof child.mime === 'object')
63
_.defaults(child.mime, parent.mime)
64
else
@@ -249,8 +252,11 @@ function inheritMasks(item: VfsNode, parent: VfsNode, virtualBasename:string) {
252
if (!masks) return
253
const o: Masks = {}
254
for (const [k,v] of Object.entries(masks))
252
- if (k.startsWith('**/'))
253
- o[k.slice(3)] = v
255
+ if (k.startsWith('**')) {
256
+ o[k] = v
257
+ if (k[3] === '/' )
258
+ o[k.slice(3)] = v
259
+ }
260
else if (k.startsWith(virtualBasename+'/'))
261
o[k.slice(virtualBasename.length+1)] = v
262
if (Object.keys(o).length)
tests/config.yaml
+3
@@ -78,6 +78,9 @@ vfs:
78
can_see: false
79
"**/*":
80
can_list: false
81
+ "**.png":
82
+ can_read:
83
+ - rejetto
84
- name: cantReadPage
85
source: tests
86
masks:
tests/test.ts
+1
-1
@@ -48,7 +48,7 @@ describe('basics', () => {
48
it('forbidden list.cant see', reqList('/cantListPage/', { outList:['page/'] }))
49
it('forbidden list.but readable file', req('/cantListPage/page/gpl.png', 200))
50
it('forbidden list.alternative method', reqList('/cantListPageAlt/page/', 403))
51
- it('forbidden list.alternative method readable file', req('/cantListPageAlt/page/gpl.png', 200))
51
+ it('forbidden list.match **', req('/cantListPageAlt/page/gpl.png', 401))
52
53
it('cantListBut', reqList('/cantListBut/', 403))
54
it('cantListBut.parent', reqList('/', { permInList: { 'cantListBut/': 'l' } }))