[Spam protector] too long lines created in .htaccess file
Posted: Mon Apr 22, 2013 9:05 am
The "Spam protector" plugin will write way too long lines into the .htaccess file if it has enough IPs in the database spamblock_htaccess table (within two days' time stamps). Apache will then truncate the line and interpret the remainder of an IP address as an invalid command resulting in "500 Server error" and the site is dead.
[Mon Apr 22 08:33:48 2013] [alert] [client 184.154.15.x] /webpath/.htaccess: Invalid command '6.48.15.137', perhaps misspelled or defined by a module not included in the server configuration, [..]
According to http://httpd.apache.org/docs/current/en ... uring.html the maximum line length in .htaccess files is 8190 chars. The plugin needs to honour that and stay below that upper limit.
Easy would be to add a LIMIT clause to
$q = "SELECT ip FROM {$serendipity['dbPrefix']}spamblock_htaccess WHERE timestamp > " . (time() - 86400*2) . " GROUP BY ip";
(from serendipity_event_spamblock.php)
Paging through (e.g.) 100 entries at a time would allow adding multiple "Deny from" lines.
Better (but slower) would be to check the length of $deny and stop adding older IPs to the end of the string when the length would go beyond 8178 (or 8000 for ease of implementation). Obviously adding multiple "Deny from" lines would be a good idea again.
Probably a valid quick-fix is to limit the entries in the table to the maximum safe amount (~177) and delete all older ones on the insert of a new spam source. (Still only a single line in .htaccess then.)
At this time IPv6 IPs should be taken into account as well, so please don't fall for Max_Length(IP) = 15. That's obsolete these days. Max_Length(IPv6) is 45. Hence 177 entries as a safe maximum for one line in .htaccess.
[Mon Apr 22 08:33:48 2013] [alert] [client 184.154.15.x] /webpath/.htaccess: Invalid command '6.48.15.137', perhaps misspelled or defined by a module not included in the server configuration, [..]
According to http://httpd.apache.org/docs/current/en ... uring.html the maximum line length in .htaccess files is 8190 chars. The plugin needs to honour that and stay below that upper limit.
Easy would be to add a LIMIT clause to
$q = "SELECT ip FROM {$serendipity['dbPrefix']}spamblock_htaccess WHERE timestamp > " . (time() - 86400*2) . " GROUP BY ip";
(from serendipity_event_spamblock.php)
Paging through (e.g.) 100 entries at a time would allow adding multiple "Deny from" lines.
Better (but slower) would be to check the length of $deny and stop adding older IPs to the end of the string when the length would go beyond 8178 (or 8000 for ease of implementation). Obviously adding multiple "Deny from" lines would be a good idea again.
Probably a valid quick-fix is to limit the entries in the table to the maximum safe amount (~177) and delete all older ones on the insert of a new spam source. (Still only a single line in .htaccess then.)
At this time IPv6 IPs should be taken into account as well, so please don't fall for Max_Length(IP) = 15. That's obsolete these days. Max_Length(IPv6) is 45. Hence 177 entries as a safe maximum for one line in .htaccess.