To reproduce:
- Take a page which is denied to anonymous users by node_privacy_byrole
- Go to it as an anonymous user
- Receive 404 error

Note: this bug did not exist in 4.5.x

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

willmoy’s picture

Title: user.module incorrectly assumes 404 when access denied » node.module incorrectly assumes 404 when access denied
Component: user.module » node.module
FileSize
686 bytes

Tested patch against 4.6.2 branch attached.

willmoy’s picture

Title: node.module incorrectly assumes 404 when access denied » 4.6.2 node.module incorrectly assumes 404 when access denied
Status: Active » Needs review
FileSize
682 bytes

New patch. Correctly handles both 403s and 404s. Adds an extra query to verify which is happening.

Dries’s picture

Status: Needs review » Needs work

That code is insecure and may lead to SQL injection attacks.

willmoy’s picture

Status: Needs work » Needs review

The patch doesn't include enough context to show that the query is subject to a check of is_numeric(arg(1)). I don't think this is vulnerable to SQL injection, but I'd be grateful if someone else would check and I apologise if I'm missing something.

The patched code in context:

case 'view':
      if (is_numeric(arg(1))) {
        $node = node_load(array('nid' => arg(1)), $_GET['revision']);
        if ($node->nid) {
          drupal_set_title(check_plain($node->title));
          print theme('page', node_show($node, arg(2)));
        }
        else if (db_fetch_object(db_query('SELECT nid FROM {node} WHERE nid=%s', arg(1)))) {
          drupal_access_denied();
        }
        else {
          drupal_not_found();
        }
      }
      break;

The cvs version of this patch http://drupal.org/node/27873 has the same context.

killes@www.drop.org’s picture

I think the problem is this:
WHERE nid=%s', arg(1)

It should be

WHERE nid = '%s'", arg(1)

if arg(1) were indeed a string, but since it isn't it should be

WHERE nid = %d', arg(1)

willmoy’s picture

Thanks very much killes, that was dumb of me.

New patch attached.

Steven’s picture

Status: Needs review » Fixed

Committed.

Anonymous’s picture

Anonymous’s picture

Anonymous’s picture

Anonymous’s picture

Status: Fixed » Closed (fixed)