Attached patch is a port that went into 4.7. We can polish / modify a bit more though.

Patch introduces tokens for form requested by authenticated users. During validation, the token field is checked to make sure this user requested the form previously during his/her session. This defends against cross site request forgeries where a users visits an external form that posts to Drupal.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Heine’s picture

Status: Active » Needs review

Note: I'd rather keep the rewriting of node revisions / menu disable to use $_POST and the rewriting of some old style (4.6) forms to other issues.

Heine’s picture

Category: task » bug
FileSize
6.99 KB

Modified to prevent XHTML validation errors (as in http://drupal.org/node/90635)

eaton’s picture

Status: Needs review » Reviewed & tested by the community

Just ran this through its paces on a fresh install. Some forms, like poll.module's voting, aren't fully FAPI-ified and thus are unaffected by this security check. Others, like commenting and node creation, properly throw a validation error when submitting a form with a tainted or missing token.

drumm’s picture

This is a big patch, any other reviews? Anything different from the 4.7 version?

Jo Wouters’s picture

I'm not sure if this is a security issue, but it is relatively easy to get to know the 'drupal_private_key':

The token (which is publicly shown in every form) is calculated with this function:

function drupal_get_token($value = '') {
  $private_key = drupal_get_private_key();
  return md5(session_id() . $value . $private_key);

The session_id is know to the user, $value is the forum_id.
$private_key is the only unknown part.
And since $private_key = mt_rand() (a number between 0 and 2147483647 on my machine) it is relatively easy to get to know the drupal_private_key.

(it costed me less then 40 minutes to find 2 different drupal_private_keys)

Apart from that, this patch seems to be working on head.

Jo Wouters’s picture

note: that should be "$value is the form_id" of course.

We should put the issue about the 'drupal_private_key' in a seperate issue. I'll open one, and attach a patch.

Heine’s picture

FileSize
7.04 KB

Changed into a 256 bits key.

Heine’s picture

Status: Reviewed & tested by the community » Needs review
Kjartan’s picture

Been using this patch on my site for a few days now and haven't had any troubles yet.

drumm’s picture

Status: Needs review » Fixed

Committed to HEAD>

Anonymous’s picture

Status: Fixed » Closed (fixed)