fix: readIgnoreIP regex captures next section header when ignoreip is empty
\s* in the regex matches \n, so when ignoreip = is empty: ^ignoreip\s*=\s*(.+)$ → consumes the newline, captures [badbot] from the next section header as if it were an IP address. Fix: use [ \t]* instead of \s* so the regex never crosses a line boundary. Also tighten the addWhitelist line-finder to use the same pattern. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -48,7 +48,7 @@ function run(cmd) {
|
|||||||
function readIgnoreIP() {
|
function readIgnoreIP() {
|
||||||
try {
|
try {
|
||||||
const content = fs.readFileSync(JAIL_LOCAL, 'utf8');
|
const content = fs.readFileSync(JAIL_LOCAL, 'utf8');
|
||||||
const match = content.match(/^ignoreip\s*=\s*(.+)$/m);
|
const match = content.match(/^ignoreip[ \t]*=[ \t]*(.*)$/m);
|
||||||
if (!match) return [];
|
if (!match) return [];
|
||||||
return match[1].split(/\s+/).filter(s => s && !s.startsWith('#'));
|
return match[1].split(/\s+/).filter(s => s && !s.startsWith('#'));
|
||||||
} catch { return []; }
|
} catch { return []; }
|
||||||
@@ -65,7 +65,7 @@ function getWhitelistNote(ip) {
|
|||||||
async function addWhitelist(ip, note) {
|
async function addWhitelist(ip, note) {
|
||||||
const lines = fs.readFileSync(JAIL_LOCAL, 'utf8').split('\n');
|
const lines = fs.readFileSync(JAIL_LOCAL, 'utf8').split('\n');
|
||||||
for (let i = 0; i < lines.length; i++) {
|
for (let i = 0; i < lines.length; i++) {
|
||||||
if (lines[i].trimStart().startsWith('ignoreip') && !lines[i].includes(ip)) {
|
if (/^ignoreip[ \t]*=/.test(lines[i]) && !lines[i].includes(ip)) {
|
||||||
lines[i] = lines[i].trimEnd() + ` ${ip}${note ? ` # ${note}` : ''}\n`;
|
lines[i] = lines[i].trimEnd() + ` ${ip}${note ? ` # ${note}` : ''}\n`;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user