Skip to content

Commit 621ad89

Browse files
committed
[mv3] Better validate hostnames in "Filtering mode details" editor
Related issue: uBlockOrigin/uBOL-home#564
1 parent cdfa514 commit 621ad89

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

platform/mv3/extension/css/develop.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ section[data-pane="develop"] > div > * {
6060
:root.dark #cm-container .cm-editor .cm-line .ubol-literal {
6161
color: #1dae74;
6262
}
63-
#cm-container .cm-editor .cm-line.badline:not(.cm-activeLine) {
63+
#cm-container .cm-editor .cm-line.badline {
6464
background-color: color-mix(in srgb, var(--info3-ink) 15%, transparent 85%);
6565
}
6666

platform/mv3/extension/js/dnr-parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ export function rulesFromText(text) {
515515
if ( indices.length === 0 ) { continue; }
516516
const result = ruleFromLines(lines, indices);
517517
if ( result.bad ) {
518-
bad.push(...result.bad.slice(4));
518+
bad.push(...result.bad.slice(0, 4));
519519
} else if ( result.rule ) {
520520
rules.push(result.rule);
521521
}

platform/mv3/extension/js/mode-parser.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,20 @@ const perScopeParsers = {
8989
};
9090

9191
const addHostnameToMode = (modes, mode, node) => {
92-
if ( node.list !== true ) { return false; }
93-
modes[mode].push(punycode.toASCII(node.val));
92+
if ( node.list !== true ) { return node.val === '-'; }
93+
if ( node.key !== undefined ) { return false; }
94+
if ( node.val === undefined ) { return false; }
95+
const hn = punycode.toASCII(node.val.toLowerCase());
96+
if ( hn.length > 253 ) { return false; }
97+
if ( hn.split('.').some(isInvalidLabel) ) { return false; }
98+
modes[mode].push(hn);
99+
};
100+
101+
const isInvalidLabel = label => {
102+
if ( label.length === 0 ) { return true; }
103+
if ( label.length > 63 ) { return true; }
104+
if ( /^[^\da-z]|[^\da-z]$|[^\da-z-]/.test(label) ) { return true; }
105+
return false;
94106
};
95107

96108
/******************************************************************************/

0 commit comments

Comments
 (0)