You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jspwiki.apache.org by Andrew Jaquith <an...@gmail.com> on 2009/03/04 06:46:12 UTC
Edit-related hash fields?
Janne,
Could you give me a little background on how the SpamFilter hash
fields work in 2.8? I've been able to replicate most of the behavior
of the plain editor as ActionBean event handlers & Stripe-ified JSPs,
but I haven't done so with the spam-filtering/hash fields just yet.
My primary reason for asking (other than trying to understand how it
works): I'm wondering if there's something we might be able to do here
that is related to CSRF prevention.
Andrew
Re: Edit-related hash fields?
Posted by Andrew Jaquith <an...@gmail.com>.
Hmmmmmmm...
Couple of observations:
- I understand your point about needing *two* random field names
(shorthand: one filled, one not). Easily done, if we do a custom tag.
- My suggestion on wiki:spamProtect was meant to indicate the goal of
the tag, not necessarily the class that relies on the outputit creates
(SpamFilter). We could certainly call it wiki:SpamFilterFields, but
that seems a little clinical. Not passionate about this; just thought
it might be better to express the intent of the tag, not the machinery
behind it.
- Randomizing "all" field names kills Stripes parameter binding dead.
So that is not a good idea.
- My suggestion of checking for the @TicketRequired annotation before
doing the SpamFilter checks was mostly about re-using an annotation to
keep things simple, but we need not do that. I should have probably
explained the "buried premise" behind that. The premise is that what
we do for spam detection should probably work on more than just the
Edit & Comment JSPs. There's other places we need to do it, like user
registration, group creation, etc. So my comments were oriented
towards strategies for making spam protection generally reusable
wherever we needed it. That might not have been clear, but it's what I
meant.
The strategy I'd used with the anti-CSRF feature for Stripes was to
have the thing that creates the ticket parameter (during the GET)
collaborate with an annotation signifies something important to the
controller (during the POST). That is, the tag tells us to generate
the special fields, and the annotation tells somebody (later) that we
need to look for them. The "somebody" is an Interceptor, which means
we can re-use that function across the entire webapp. That's the kind
of strategy that could work for SpamFilter, too. The bottom line is
that it's damned simple: add an annotation to the method you want to
protect, then add a matching tag to the JSP that creates the form.
Everything else is hidden away. For the annotation, we can use our
own, like @SpamProtect.... or @SpamFilter :)
Of course, all of the foregoing is *before* we get to actual content
analysis, which is now, and will continue to be, done in the
SpamFilter.
On Tue, Mar 10, 2009 at 6:18 AM, Janne Jalkanen <ja...@iki.fi> wrote:
>> The SpamFilter does not stash anything in the Session (because spambots
>> sometimes do not send cookies).
>
> D'oh, shouldn't have written this before breakfast. Of course we write
> the hashfield name in the Session.
>
> But my comment still stands not wanting to do this in a
> Stripes-dependent manner. I especially don't want us rejecting edits
> in multiple places.
>
> Besides, I want to enhance SpamFilter to go into a direction of
> SpamAssassin, that is, allow different weights for different tests.
> This means that SpamFilter must get all the relevant data and be able
> to reject/approve things without the framework getting in the way.
>
> /Janne
>
Re: Edit-related hash fields?
Posted by Janne Jalkanen <ja...@iki.fi>.
> The SpamFilter does not stash anything in the Session (because spambots
> sometimes do not send cookies).
D'oh, shouldn't have written this before breakfast. Of course we write
the hashfield name in the Session.
But my comment still stands not wanting to do this in a
Stripes-dependent manner. I especially don't want us rejecting edits
in multiple places.
Besides, I want to enhance SpamFilter to go into a direction of
SpamAssassin, that is, allow different weights for different tests.
This means that SpamFilter must get all the relevant data and be able
to reject/approve things without the framework getting in the way.
/Janne
Re: Edit-related hash fields?
Posted by Janne Jalkanen <ja...@ecyrd.com>.
> optional "timeout" parameter). FYI the ticket parameter name is not
> actually randomized; it's overkill because the value isn't
> predictable. The patch is here:
It's not overkill. Trust me. You will want to have two parameters
with random names that need to be treated differently at the server
end (one is full and one is empty).
This is to curb those bots which understand the post schema used - you
want to write it in such a way that any "post this field to that" -
schema does not work.
I've been thinking about randomizing all input field names just to
make things more complicated.
> As for the other items (#1 and #3), these are things I'd like to
> reimplement, but in a slightly different way. I agree that a tag would
> be good, although I prefer "wiki:spamProtect." Similar to how we do it
I would prefer to attach it to the SpamFilter name
(wiki:SpamFilterTags) because then it's obvious who uses them.
> Where I think we could do things a little differently is how we manage
> stuff that gets stashed in the session.
The SpamFilter does not stash anything in the Session (because
spambots sometimes do not send cookies).
> We could re-use the Ticket
> scheme I developed for Stripes, or do something like what Stripes
> does, which is to write out an encrypted parameter with the name of
> the spam-trap param as the payload. The latter is probably the better
> approach. Verification would be via an Interceptor, and we could
> simply state that if the target ActionBean event handler method had a
> @TicketRequired annotation, we should *always* do the spam-check
> thing.
No, we should leave this configurable to the enduser via our filtering
mechanism (which works regardless of whether Stripes are used or not,
e.g. for embedders). I see no reason to involve Stripes here.
People who are embedding JSPWiki as a part of their own webapp will
probably also need a spam filter.
/Janne
Re: Edit-related hash fields?
Posted by Andrew Jaquith <an...@gmail.com>.
So, a quick update on this. The anti-CSRF feature (#2) seemed
important enough that it warranted me writing a patch for Stripes.
That's what I've done, and I'm awaiting to hear from the Stripes team
to see if it warrants inclusion in the main branch.
Basically, what the feature does is require users to access the
"display JSP" before submitting the POST. It does this by causing the
stripes:form tag to generate a unique "ticket" param that is later
required to access an event handler method. Methods can be marked as
protected simply by annotating them with @TicketRequired (with an
optional "timeout" parameter). FYI the ticket parameter name is not
actually randomized; it's overkill because the value isn't
predictable. The patch is here:
http://stripesframework.org/jira/browse/STS-363
So, if it's accepted to the trunk we will get this feature "for free."
If not, I'll pull it back into JSPWiki.
As for the other items (#1 and #3), these are things I'd like to
reimplement, but in a slightly different way. I agree that a tag would
be good, although I prefer "wiki:spamProtect." Similar to how we do it
now, the tag would generate the UTF-8 "canary" field (mangled return
value means UTF-8 not supported), plus the honeypot spam trap field.
The canary param can be a fixed field name; the spam-trap param still
be random.
Where I think we could do things a little differently is how we manage
stuff that gets stashed in the session. We could re-use the Ticket
scheme I developed for Stripes, or do something like what Stripes
does, which is to write out an encrypted parameter with the name of
the spam-trap param as the payload. The latter is probably the better
approach. Verification would be via an Interceptor, and we could
simply state that if the target ActionBean event handler method had a
@TicketRequired annotation, we should *always* do the spam-check
thing.
Andrew
On Wed, Mar 4, 2009 at 5:33 PM, Janne Jalkanen <Ja...@ecyrd.com> wrote:
>> How big of an issue is this any more? Does this change if we require
>> accept-charset="UTF-8" on all our forms? Just wondering if we need to
>> carry this into 3.0.
>
> The problem is that badly behaving clients will behave badly regardless of
> what accept-charset says. So I'd rather keep it. There are still plenty of
> broken clients out there.
>
>>> 2) An input field with a random name. This means that a bot will need to
>>> actually GET the form first and parse it out before it can send
>>> syntactically correct POSTs. This is a LOT more effort than just simply
>>> looking at the fields once and crafting your auto-poster to conform.
>>
>> This feels like a fairly standard anti-CSRF approach, although you
>> didn't call it that per se.
>
> No, 'cos I thought about it before I heard about CSRF ;-)
>
>>> That is an interesting approach! It's a "honey pot" field,
>>
>> essentially. That's a little less amenable to a framework-level fix,
>> unless we patch the Stripes FormTag class. If not, a simple custom Tag
>> class would probably be better than the inline scriptlet stuff we are
>> doing now.
>
> Well, we could have a simple <wiki:SpamFilterFields /> in there somewhere
> which could insert all of these.
>
> /Janne
>
Re: Edit-related hash fields?
Posted by Janne Jalkanen <Ja...@ecyrd.com>.
> How big of an issue is this any more? Does this change if we require
> accept-charset="UTF-8" on all our forms? Just wondering if we need to
> carry this into 3.0.
The problem is that badly behaving clients will behave badly
regardless of what accept-charset says. So I'd rather keep it. There
are still plenty of broken clients out there.
>> 2) An input field with a random name. This means that a bot will
>> need to
>> actually GET the form first and parse it out before it can send
>> syntactically correct POSTs. This is a LOT more effort than just
>> simply
>> looking at the fields once and crafting your auto-poster to conform.
>
> This feels like a fairly standard anti-CSRF approach, although you
> didn't call it that per se.
No, 'cos I thought about it before I heard about CSRF ;-)
>> That is an interesting approach! It's a "honey pot" field,
> essentially. That's a little less amenable to a framework-level fix,
> unless we patch the Stripes FormTag class. If not, a simple custom Tag
> class would probably be better than the inline scriptlet stuff we are
> doing now.
Well, we could have a simple <wiki:SpamFilterFields /> in there
somewhere which could insert all of these.
/Janne
Re: Edit-related hash fields?
Posted by Andrew Jaquith <an...@gmail.com>.
Ok -- that is pretty close to what I'd been able to reverse-engineer. :)
A few questions & observations:
> 1) An UTF-8 detector. We put a single non-Latin1 character in the form to
> make sure the input is not mangled by some badly behaving robots or user
> clients. This used to be a major problem a few years back, and this solved
> all of those "hey, my edit destroyed all UTF-8 characters" -problems. It
> also turns out many of the older bots just assume a form is Latin1.
How big of an issue is this any more? Does this change if we require
accept-charset="UTF-8" on all our forms? Just wondering if we need to
carry this into 3.0.
> 2) An input field with a random name. This means that a bot will need to
> actually GET the form first and parse it out before it can send
> syntactically correct POSTs. This is a LOT more effort than just simply
> looking at the fields once and crafting your auto-poster to conform.
This feels like a fairly standard anti-CSRF approach, although you
didn't call it that per se. I do think that this is something we
should have on *all* our forms, not just editing. I've pinged the
Stripes folks and think that we could probably solve the problem
there. See my comments here:
http://stripesframework.org/jira/browse/STS-363
I'd like to get your comments on the approach (within the Stripes JIRA
system, of course).
> 3) A hidden input field which is meant to catch those bots which do a GET
> and then randomly fill all fields with garbage. This field MUST be empty
> when SpamFilter examines the contents of the POST. Since it's hidden with
> the use of CSS, the bot would need to understand CSS to bypass this one
> (and, the fieldname is also randomized in order to prevent someone from
> hardcoding the fact that it needs to be empty).
That is an interesting approach! It's a "honey pot" field,
essentially. That's a little less amenable to a framework-level fix,
unless we patch the Stripes FormTag class. If not, a simple custom Tag
class would probably be better than the inline scriptlet stuff we are
doing now.
Will muse on this a bit more...
Re: Edit-related hash fields?
Posted by Janne Jalkanen <Ja...@ecyrd.com>.
There are a few fields that SpamFilter uses.
First, those inserted by SpamFilter.insertInputFields():
1) An UTF-8 detector. We put a single non-Latin1 character in the
form to make sure the input is not mangled by some badly behaving
robots or user clients. This used to be a major problem a few years
back, and this solved all of those "hey, my edit destroyed all UTF-8
characters" -problems. It also turns out many of the older bots just
assume a form is Latin1.
What is currently in plain.jsp (and should actually be moved to
insertInputFields()):
2) An input field with a random name. This means that a bot will need
to actually GET the form first and parse it out before it can send
syntactically correct POSTs. This is a LOT more effort than just
simply looking at the fields once and crafting your auto-poster to
conform.
3) A hidden input field which is meant to catch those bots which do a
GET and then randomly fill all fields with garbage. This field MUST
be empty when SpamFilter examines the contents of the POST. Since it's
hidden with the use of CSS, the bot would need to understand CSS to
bypass this one (and, the fieldname is also randomized in order to
prevent someone from hardcoding the fact that it needs to be empty).
The idea between 2 & 3 is that we've got two fields with random names,
one of which needs to be empty and one of which needs to be filled
with pre-determined data. This is quite hard for most bots to catch,
unless they are specifically crafted for JSPWiki and contain some
amount of logic to figure this one out. In the future we could also
do full input field name randomization and even random reordering of
the input fields to make it even more difficult.
(Once they've passed these simple tests, then the content-based
analysis starts. But these are sufficient to catch ~95% of all spam.)
/Janne
On Mar 4, 2009, at 07:46 , Andrew Jaquith wrote:
> Janne,
>
> Could you give me a little background on how the SpamFilter hash
> fields work in 2.8? I've been able to replicate most of the behavior
> of the plain editor as ActionBean event handlers & Stripe-ified JSPs,
> but I haven't done so with the spam-filtering/hash fields just yet.
>
> My primary reason for asking (other than trying to understand how it
> works): I'm wondering if there's something we might be able to do here
> that is related to CSRF prevention.
>
> Andrew