@adguard/hostlist-compiler 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/README.md +37 -3
- package/package.json +3 -3
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/schemas/configuration.schema.json +98 -0
- package/src/transformations/ip-normalize.js +182 -0
- package/src/transformations/transform.js +6 -4
- package/src/transformations/validate-allow-ip-and-public-suffix.js +33 -0
- package/src/transformations/validate-allow-ip.js +16 -3
- package/src/transformations/validate.js +118 -53
- package/src/utils.js +137 -0
- package/test/configuration.test.js +6 -0
- package/test/transformations/ip-alignment.test.js +65 -0
- package/test/transformations/ip-normalize.test.js +331 -0
- package/test/transformations/transform.test.js +6 -0
- package/test/transformations/validate-allow-ip-and-public-suffix.test.js +167 -0
- package/test/transformations/validate-allow-ip.test.js +46 -18
- package/test/transformations/validate-allow-public-suffix.test.js +20 -0
- package/test/transformations/validate.test.js +57 -0
|
@@ -46,6 +46,8 @@ describe('Validate', () => {
|
|
|
46
46
|
||example.org^$third-party
|
|
47
47
|
||example.org^$important
|
|
48
48
|
||*.ga^$denyallow=example1.ga|example2.ga
|
|
49
|
+
1.1.1.1$denyallow=001114.cn
|
|
50
|
+
||1.1.1.1^$denyallow=001114.cn
|
|
49
51
|
://ww4.$denyallow=ww4.example.com
|
|
50
52
|
://example.org
|
|
51
53
|
||example.org^|
|
|
@@ -327,4 +329,59 @@ describe('Validate', () => {
|
|
|
327
329
|
'||a.b.c.d^',
|
|
328
330
|
]);
|
|
329
331
|
});
|
|
332
|
+
|
|
333
|
+
it('rejects unsafe IP patterns without ^ (too wide or ambiguous)', () => {
|
|
334
|
+
// These patterns don't have ^ but are still dangerous:
|
|
335
|
+
// - 1-2 octet patterns (too wide)
|
|
336
|
+
// - 3 octet patterns without trailing dot/wildcard (ambiguous)
|
|
337
|
+
const rules = [
|
|
338
|
+
// 1-2 octets — too wide
|
|
339
|
+
'1.2.',
|
|
340
|
+
'1.2.*',
|
|
341
|
+
'||1.2.',
|
|
342
|
+
'||1.2.*',
|
|
343
|
+
'192.168',
|
|
344
|
+
'||192.168',
|
|
345
|
+
// 3 octets without trailing dot/wildcard — ambiguous
|
|
346
|
+
'192.168.1',
|
|
347
|
+
'||192.168.1',
|
|
348
|
+
'10.0.1',
|
|
349
|
+
// 3 octets WITH trailing dot/wildcard, no prefix — unsafe (no || means subnet is unanchored)
|
|
350
|
+
'192.168.1.',
|
|
351
|
+
'192.168.1.*',
|
|
352
|
+
'10.10.34.',
|
|
353
|
+
'10.10.34.*',
|
|
354
|
+
// 3 octets WITH trailing dot/wildcard, with || prefix — rejected in Validate (IP subnet)
|
|
355
|
+
'||192.168.1.',
|
|
356
|
+
'||192.168.1.*',
|
|
357
|
+
// 4 octets WITH trailing dot or wildcard — malformed IP, rejected in all validators
|
|
358
|
+
'1.2.3.4.',
|
|
359
|
+
'1.2.3.4.*',
|
|
360
|
+
'|1.2.3.4.',
|
|
361
|
+
'|1.2.3.4.*',
|
|
362
|
+
'||1.2.3.4.',
|
|
363
|
+
'||1.2.3.4.*',
|
|
364
|
+
// valid domains — kept
|
|
365
|
+
'||example.org^',
|
|
366
|
+
];
|
|
367
|
+
const filtered = validate(rules);
|
|
368
|
+
|
|
369
|
+
expect(filtered).toEqual([
|
|
370
|
+
'||example.org^',
|
|
371
|
+
]);
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it('allows domains with IP-like subdomains', () => {
|
|
375
|
+
// Patterns like ||1.2.3.4.example.com^ are valid domain rules, not IP patterns.
|
|
376
|
+
// parseIpPattern returns null for them (> 4 parts or non-numeric labels),
|
|
377
|
+
// so they pass through all IP checks and are validated as regular domain rules.
|
|
378
|
+
const rules = [
|
|
379
|
+
'||1-2-3-4.example.com^',
|
|
380
|
+
'||111.22.33.44.host.example.com^',
|
|
381
|
+
'||111.22.33.44.ll.host.example.com^',
|
|
382
|
+
];
|
|
383
|
+
const filtered = validate(rules);
|
|
384
|
+
|
|
385
|
+
expect(filtered).toEqual(rules);
|
|
386
|
+
});
|
|
330
387
|
});
|