[mv3] Better validate hostnames in "Filtering mode details" editor

Related issue:
https://github.com/uBlockOrigin/uBOL-home/issues/564
This commit is contained in:
Raymond Hill 2025-12-12 09:48:40 -05:00
parent cdfa514c2a
commit 621ad89c64
No known key found for this signature in database
GPG key ID: F5630CAE62A14316
3 changed files with 16 additions and 4 deletions

View file

@ -60,7 +60,7 @@ section[data-pane="develop"] > div > * {
:root.dark #cm-container .cm-editor .cm-line .ubol-literal {
color: #1dae74;
}
#cm-container .cm-editor .cm-line.badline:not(.cm-activeLine) {
#cm-container .cm-editor .cm-line.badline {
background-color: color-mix(in srgb, var(--info3-ink) 15%, transparent 85%);
}

View file

@ -515,7 +515,7 @@ export function rulesFromText(text) {
if ( indices.length === 0 ) { continue; }
const result = ruleFromLines(lines, indices);
if ( result.bad ) {
bad.push(...result.bad.slice(4));
bad.push(...result.bad.slice(0, 4));
} else if ( result.rule ) {
rules.push(result.rule);
}

View file

@ -89,8 +89,20 @@ const perScopeParsers = {
};
const addHostnameToMode = (modes, mode, node) => {
if ( node.list !== true ) { return false; }
modes[mode].push(punycode.toASCII(node.val));
if ( node.list !== true ) { return node.val === '-'; }
if ( node.key !== undefined ) { return false; }
if ( node.val === undefined ) { return false; }
const hn = punycode.toASCII(node.val.toLowerCase());
if ( hn.length > 253 ) { return false; }
if ( hn.split('.').some(isInvalidLabel) ) { return false; }
modes[mode].push(hn);
};
const isInvalidLabel = label => {
if ( label.length === 0 ) { return true; }
if ( label.length > 63 ) { return true; }
if ( /^[^\da-z]|[^\da-z]$|[^\da-z-]/.test(label) ) { return true; }
return false;
};
/******************************************************************************/