@samitouri / QOSami-HFS / commits / cdd7670a

fix: network ranges were working only if CIDR syntax was used

Massimo Melina committed Mar 20, 2025 at 15:09 UTC cdd7670a313b7d0f065155fdd99c2791e02c83ff
1 file changed +4 -8
src/misc.ts
+4 -8
@@ -12,13 +12,9 @@ export * from './debounceAsync'
12 import { Readable, Transform } from 'stream'
13 import { SocketAddress, BlockList } from 'node:net'
14 import { ApiError } from './apiMiddleware'
15 -import { HTTP_BAD_REQUEST, HTTP_METHOD_NOT_ALLOWED } from './const'
15 +import { HTTP_BAD_REQUEST } from './const'
16 import { isIpLocalHost, makeMatcher, try_ } from './cross'
17 import { isIPv6 } from 'net'
18 -import { statusCodeForMissingPerm, VfsNode } from './vfs'
19 -import events from './events'
20 -import { rm } from 'fs/promises'
21 -import { setCommentFor } from './comments'
18 import _ from 'lodash'
19
20 export function pattern2filter(pattern: string){
@@ -43,7 +39,7 @@ export function makeNetMatcher(mask: string, emptyMaskReturns=false) {
39 return () => emptyMaskReturns
40 mask = mask.replaceAll(' ','')
41 mask = mask.replace('localhost', '::1|127.0.0.1')
46 - if (!mask.includes('/')) // for CIDR we use BlockList
42 + if (!/\/|-(?![^\[]*\])/.test(mask)) // when no CIDR and no ranges are used, then we use standard matcher, otherwise BlockList. For "-" we must skip those inside []
43 return makeMatcher(mask)
44 const all = mask.split('|')
45 const neg = all[0]?.[0] === '!'
@@ -51,8 +47,8 @@ export function makeNetMatcher(mask: string, emptyMaskReturns=false) {
47 all[0] = all[0]!.slice(1)
48 const bl = new BlockList()
49 for (const x of all) {
54 - const m = /^([.:\da-f]+)(?:\/(\d+)|-(.+)|)$/i.exec(x)
55 - if (!m) {
50 + const m = /^([.:\da-f]+)(?:\/(\d+)|-(.+)|)$/i.exec(x) // parse cidr or range
51 + if (!m) { // we don't support wildcards in this case
52 console.warn("error in network mask", x)
53 continue
54 }