Subject: | significant bug in Net::Akismet |
Date: | Wed, 22 Aug 2007 07:04:54 -0400 |
To: | bug-Net-Akismet [...] rt.cpan.org |
From: | John Belmonte <john [...] neggie.net> |
It seems that Net::Akismet is confusing the user agent making the
request to Akismet with the user agent making the comment to the blog.
These are two very different things, and both are required by Akismet.
The user agent given to LWP::UserAgent->agent should be that of
Net::Akismet-- that part is correct.
The user agent given in the Akismet request (e.g., along side referrer)
must be that which came from the comment posting. Akismet requires this
to do its analysis. Unfortunately Net::Akismet is using its own user
agent here, which could seriously skew the effects of the check/ham/spam
requests.
A patched to fix this problem is attached. It also addresses a smaller
issue: Akismet's own user agent string should not have a
space in it (i.e. "Akismet Perl")-- the HTTP spec says "<word>
[/<version>]". LWP::UserAgent->agent has it's own agent and knows to
prepend when your string ends with a space. I propose that the final
user agent HTTP field look something like this e.g.:
SomeBlogEngine/1.2 NetAkismet/0.02 libwww-perl/5.50
I think Akismet's suggestion of "|" as delimiter is incorrect.
Proposed Net::Akismet patch:
* check/ham/spam functions take USER_AGENT field. This must be the
User-Agent string from the comment HTTP request, and is required by
Akismet. (See <http://akismet.com/development/api/>.)
* improve Net::Akismet's own user agent string for standard conformance
and to include libwww-perl component.
--- Akismet.pm.orig 2007-08-18 15:20:56.000000000 -0400
+++ Akismet.pm 2007-08-18 15:21:03.000000000 -0400
@@ -14,9 +14,9 @@
use LWP::UserAgent;
use HTTP::Request::Common;
-our $VERSION = '0.02';
+our $VERSION = '0.03';
-my $UA_SUFFIX = "Akismet Perl/$VERSION";
+my $UA_SUFFIX = "Net-Akismet/$VERSION";
=head1 SYNOPSIS
@@ -27,6 +27,7 @@
my $verdict = $akismet->check(
USER_IP => '10.10.10.11',
+ USER_AGENT => 'Mozilla/5.0',
COMMENT_CONTENT => 'Run, Lola, Run, the spam will catch you!',
COMMENT_AUTHOR => 'dosser',
COMENT_AUTHOR_EMAIL => 'dosser@subway.de',
@@ -62,7 +63,7 @@
If supplied the value is prepended to this module's identification string to become something like:
- yourkillerapp/0.042 | Akismet Perl/0.01
+ your-killer-app/0.042 Net-Akismet/0.01 libwww-perl/5.8
Otherwise just Akismet Perl's user agent string will be sent.
@@ -85,9 +86,10 @@
my $key = $self->{KEY} or return undef;
my $url = $self->{URL} or return undef;
- my $agent = $params{USER_AGENT}? "$params{USER_AGENT} | " : '';
-
- $self->{ua}->agent($agent.$UA_SUFFIX);
+ # NOTE: trailing space leaves LWP::UserAgent agent string in place
+ my $agent = "$UA_SUFFIX ";
+ $agent = "$params{USER_AGENT} $agent" if $params{USER_AGENT};
+ $self->{ua}->agent($agent);
bless $self, $class;
@@ -124,7 +126,11 @@
=item USER_IP
-The B<only required> item. Represents the IP address of the comment submitter.
+B<Required.> Represents the IP address of the comment submitter.
+
+=item USER_AGENT
+
+B<Required.> User agent string from the comment submitter's request.
=item COMMENT_CONTENT
@@ -208,14 +214,14 @@
my $comment = shift;
- $comment->{USER_IP} || return undef;
+ $comment->{USER_IP} && $comment->{USER_AGENT} || return undef;
my $response = $self->{ua}->request(
POST "http://$self->{KEY}.rest.akismet.com/1.1/$action",
[
blog => $self->{URL},
user_ip => $comment->{USER_IP},
- user_agent => $self->{ua}->agent(),
+ user_agent => $comment->{USER_AGENT},
referrer => $comment->{REFERRER},
permalink => $comment->{PERMALINK},
comment_type => $comment->{COMMENT_TYPE},