Problem/Motivation

Original report by blasthaus to security.drupal.org - security team decided this is not a vulnerability and can be fixed publicly.

This module has a Denial of Service (DOS) vulnerability.

You can see this vulnerability by:

  1. Enabling the module or have the module disabled but not yet uninstalled and have set both
    • "Count content views" and
    • On D7 only, "Use Ajax to increment the counter" module settings.
  2. As someone with no permission, send a post request to the path /modules/statistics/statistics.php with a POST param of nid set to a numeric value out of range i.e. > int(11).

This causes a PDOException and could be used as an attack vector if repeatedly called to try and take down a site.

Furthermore, per the minimal Drupal bootstrap in this file, no error would ever be sent to watchdog.

Proposed resolution

  • do early exit when not integer NID is passed
  • add try/catch to prevent any data send on error

Remaining tasks

Agree that this changes enough and commit

User interface changes

None.

API changes

None.

Data model changes

None.

CommentFileSizeAuthor
#94 2616330-94.patch3.49 KBandypost
#94 interdiff.txt3.02 KBandypost
#90 2616330-90.patch4.41 KB_pratik_
#89 reroll_diff_86-89.txt1.77 KBpooja saraah
#89 2616330-89.patch4.28 KBpooja saraah
#88 2616330-nr-bot.txt144 bytesneeds-review-queue-bot
#86 2616330-86.patch4.28 KBsmustgrave
#86 interdiff-76-86.txt3.97 KBsmustgrave
#76 interdiff-2616330-72-75.txt2.65 KBmohit_aghera
#76 2616330-75.patch3.53 KBmohit_aghera
#72 interdiff-2616330-68-72.txt1.02 KByogeshmpawar
#72 2616330-72.patch1.73 KByogeshmpawar
#69 2616330-69.patch1.8 KBshardulagg
#68 2616330-68.patch1.51 KByogeshmpawar
#64 2616330-63.patch1.85 KBwim leers
#64 interdiff-62-63.txt1.85 KBwim leers
#62 2616330-62.patch2.62 KBwim leers
#50 interdiff-2616330-50.txt533 bytesstefank
#50 2616330-validate-nid-50.patch2.49 KBstefank
#48 interdiff-2616330-48.txt442 bytesstefank
#48 2616330-validate-nid-48.patch2.37 KBstefank
#48 2616330-validate-nid-48.patch2.37 KBstefank
#43 interdiff-2616330-43.txt3.36 KBstefank
#43 2616330-validate-nid-43.patch2.29 KBstefank
#41 interdiff-2616330-41.txt2.97 KBstefank
#41 2616330-validate-nid-41.patch2.72 KBstefank
#37 interdiff.txt491 bytesmallezie
#37 2616330-validate-nid-37.patch2.88 KBmallezie
#36 interdiff-2616330.txt680 bytesmallezie
#36 2616330-validate-nid-36.patch2.9 KBmallezie
#33 interdiff.txt1.19 KBmallezie
#33 2616330-validate-nid-32.patch2.94 KBmallezie
#31 interdiff.txt671 bytesmallezie
#31 2616330-validate-nid-31.patch859 bytesmallezie
#27 interdiff.txt1.68 KBmallezie
#27 2616330-validate-nid-24.patch2.89 KBmallezie
#21 interdiff.txt908 bytesmallezie
#21 2616330-validate-nid-21.patch2.37 KBmallezie
#18 2616330-validate-nid-14.patch2.42 KBmallezie
#14 interdiff.txt555 bytesmallezie
#14 2616330-validate-nid-14.patch2.42 KBmallezie
#10 2616330-test-only.patch1.79 KBmallezie
#10 2616330-validate-nid.patch2.42 KBmallezie

Issue fork statistics-2616330

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

catch created an issue. See original summary.

catch’s picture

I don't agree this is a DOS as such, but I have seen load balancers configured to take web servers out of rotation when they return enough 5** errors, and this would allow you to trigger that condition.

dave reid’s picture

Issue tags: +Security improvements
dawehner’s picture

So I'm wondering whether we should use some form of tokens to validate that the input is valid in any way?

catch’s picture

That'd be tricky since this is used for anonymous users.

Could possibly hash nid + site key or similar - it won't stop anyone adding fake entries, but it'll mean they were only able to add them if at some point someone visited the node?

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mallezie’s picture

Does anyone has an idea here how to tackle this.
My first thought would be an extra check to determine range of IDs. However this add's an extra query.

catch’s picture

It just needs to check that the integer is small enough to fit in the database column, not that it's within the range of nids on the site.

mallezie’s picture

Status: Active » Needs review
StatusFileSize
new2.42 KB
new1.79 KB

Let's try this. This is probably simplest approach to do, not sure it's the best.
Added two tests to demonstrate the problem.

Status: Needs review » Needs work

The last submitted patch, 10: 2616330-test-only.patch, failed testing.

mallezie’s picture

Status: Needs work » Needs review

Back to needs review.

alexpott’s picture

Status: Needs review » Needs work
+++ b/core/modules/statistics/statistics.php
@@ -22,7 +22,9 @@
+    "options" => array("min_range" => 0, "max_range" => 9999999999),

That's not the maximum size of int(10)... see https://dev.mysql.com/doc/refman/5.5/en/integer-types.html

The largest size is 4294967295.

mallezie’s picture

Status: Needs work » Needs review
StatusFileSize
new2.42 KB
new555 bytes

Thanks!
Adjusted the patch.
I'm just not sure if it wouldn't be better to somehow define the value somewhere as a constant.

Status: Needs review » Needs work

The last submitted patch, 14: 2616330-validate-nid-14.patch, failed testing.

mallezie’s picture

Version: 8.1.x-dev » 8.3.x-dev
Status: Needs work » Needs review

This should probably better start against 8.3.x. Sorry for the noise

Status: Needs review » Needs work

The last submitted patch, 14: 2616330-validate-nid-14.patch, failed testing.

mallezie’s picture

Status: Needs work » Needs review
StatusFileSize
new2.42 KB
dawehner’s picture

+++ b/core/modules/statistics/src/Tests/StatisticsInvalidPostTest.php
@@ -0,0 +1,60 @@
+    $this->client = \Drupal::service('http_client_factory')
+      ->fromOptions(['config/curl' => [CURLOPT_TIMEOUT => 10]]);

Is there a reason we cannot just use the default guzzle client but rather have to setup custom options? I'm curious here.
Note: you can also use ['timeout' => ], guzzle maps that internally.

mallezie’s picture

Status: Needs review » Needs work

Nope no reason, but i'll try to refactor it. (won't be today however)
only reason now is copy paste from StatisticsAdminTest

Note to self, if refactoring this works, file followup for StatisticsAdminTest

mallezie’s picture

Status: Needs work » Needs review
StatusFileSize
new2.37 KB
new908 bytes

Adjusted the client declaration in the new test and created #2785997: Clean up guzzle declaration in core tests to refactor the current tests.

dawehner’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/statistics/src/Tests/StatisticsInvalidPostTest.php
    @@ -0,0 +1,60 @@
    +    $this->client = new Client(['timeout' => 10]);
    

    To be honest I don't get in the first place, why we need a timeout :)

  2. +++ b/core/modules/statistics/src/Tests/StatisticsInvalidPostTest.php
    @@ -0,0 +1,60 @@
    +   */
    +  public function testInvalidPost() {
    +    global $base_url;
    +
    +    // Manually calling statistics.php.
    +    $nid = 'a string instead of an integer';
    +    $post = array('nid' => $nid);
    +    $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php';
    +    $this->client->post($stats_path, array('form_params' => $post));
    +
    +    // An id greater than int(10), the maximum nid database limit.
    +    $nid = 123456789012;
    +    $post = array('nid' => $nid);
    +    $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php';
    +    $this->client->post($stats_path, array('form_params' => $post));
    +  }
    +
    

    IMHO we need some kind of assertions ...

mallezie’s picture

@dawehner thanks!

I thought about the assertions as well. Problem is i have no idea what to assert.
We're testing we're not getting a PDO exception.

i'll update the timeout, it's also in tehe other tests, thats why i added it here.

The last submitted patch, 21: 2616330-validate-nid-21.patch, failed testing.

dawehner’s picture

Well, we could check whether we have the expected node views recorded.

mallezie’s picture

Status: Needs work » Needs review

I'm gonna retest this one, strangely this works locally.

mallezie’s picture

StatusFileSize
new2.89 KB
new1.68 KB

And in the meantime added the remarks from dawehner.

The last submitted patch, 21: 2616330-validate-nid-21.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 27: 2616330-validate-nid-24.patch, failed testing.

mallezie’s picture

Seems the guzzle adjustments still fail here but work locally. The other two fails seems a problem in head.

mallezie’s picture

Status: Needs work » Needs review
StatusFileSize
new859 bytes
new671 bytes

Still no idea why the default guzzle instantiation fails, and the 'drupal' one works on the testbot. Both work locally.
Let's not hold this patch up on that? And fix that in #2785997: Clean up guzzle declaration in core tests ?
Adjusted back to drupal initialization.

Status: Needs review » Needs work

The last submitted patch, 31: 2616330-validate-nid-31.patch, failed testing.

mallezie’s picture

Status: Needs work » Needs review
StatusFileSize
new2.94 KB
new1.19 KB

Ok that was a wrong patch ;-)

dawehner’s picture

Yeah, that's indeed the right solution. You can shortcut that by using \Drupal::httpClient();

mallezie’s picture

So only thing left here, is adjust declaration in test from
$this->client = \Drupal::service('http_client_factory')->fromOptions();

to

$this->client = \Drupal::httpClient();

mallezie’s picture

StatusFileSize
new2.9 KB
new680 bytes

And adjusted this, i think this is ready now.

mallezie’s picture

StatusFileSize
new2.88 KB
new491 bytes

Forgot an unused use statement

dawehner’s picture

+++ b/core/modules/statistics/src/Tests/StatisticsInvalidPostTest.php
@@ -0,0 +1,73 @@
+    global $base_url;
...
+    $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php';
+    $this->client->post($stats_path, array('form_params' => $post));
...
+    $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php';
+    $this->client->post($stats_path, array('form_params' => $post));

Can't we use $this->buildUrl() instead?

timmillwood’s picture

Status: Needs review » Needs work

based on #38

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

stefank’s picture

Status: Needs work » Needs review
StatusFileSize
new2.72 KB
new2.97 KB

Here is a patch against 8.4.x-dev branch with some coding standard changes and changes based on #38.

timmillwood’s picture

Status: Needs review » Needs work

Thanks @stefank, great to see this coming back after 3 months, sorry to have to push it to needs work.

I wonder if we could do this with a kernel test, if not it should be a browser test and not a simpletest based test.

stefank’s picture

StatusFileSize
new2.29 KB
new3.36 KB

Sure, here is a browser test, not sure if its right though.

stefank’s picture

Status: Needs work » Needs review
dawehner’s picture

+++ b/core/modules/statistics/statistics.php
@@ -22,7 +22,12 @@
+  $nid = filter_input(INPUT_POST, 'nid', FILTER_VALIDATE_INT, [
+    'options' => [
+      'min_range' => 0,
+      'max_range' => 4294967295,
+    ],
+  ]);
   if ($nid) {

It would be nice to document why this validation is applied here. (Otherwise we get a DB exception)

stefank’s picture

Would something like that be sufficient?

 + // Checks if Posted nid is in range of valid integers and prevent PDOException.
  $nid = filter_input(INPUT_POST, 'nid', FILTER_VALIDATE_INT, [
    'options' => [
      'min_range' => 0,
      'max_range' => 4294967295,
    ],
  ]);
mallezie’s picture

Nit: Checks if posted nid is in range of valid integers and prevent a PDOException.

Lowercase P, and an 'a' before PDOException. But look corrects according to me.

stefank’s picture

Cool, @mallezie thanks for that.

Sorry, somehow managed to upload the patch twice.

timmillwood’s picture

Status: Needs review » Needs work
+++ b/core/modules/statistics/statistics.php
@@ -22,7 +22,13 @@
+  //Checks if posted nid is in range of valid integers and prevent a PDOException.

Need a space after //, and no more than 80 characters per line. So just drop PDOException. down to the next line.

stefank’s picture

Status: Needs work » Needs review
StatusFileSize
new2.49 KB
new533 bytes

Thanks @timmillwood. That is updated.

timmillwood’s picture

Status: Needs review » Reviewed & tested by the community

Looks good

dawehner’s picture

Nice!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
mysql> create table test (nid int(10) unsigned NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Query OK, 0 rows affected (0.03 sec)

mysql> insert into test values (4294967296);
ERROR 1264 (22003): Out of range value for column 'nid' at row 1
mysql> insert into test values (4294967295);
Query OK, 1 row affected (0.00 sec)

mysql>

So the number chosen looks great...

But I have a couple of concerns. One this value is different on postgres :( Here's a similar test on a postrges db.

drupal8alt=> \d+ node
nid	integer	not null default nextval('node_nid_seq'::regclass)	plain
vid	bigint		plain
type	character varying(32)	not null	extended		The ID of the target entity.
uuid	character varying(128)	not null	extended
langcode	character varying(12)	not null	extended
drupal8alt=> CREATE TABLE test (nid integer NOT NULL);
drupal8alt=> insert into test values (4294967296);
ERROR:  integer out of range
drupal8alt=> insert into test values (4294967295);
ERROR:  integer out of range

And the other concern is that the test added should be fail if we update the node table to hold larger integers so we know we need to update statistics.php if we do that.

alexpott’s picture

So thinking about this some more

This causes a PDOException and could be used as an attack vector if repeatedly called to try and take down a site.

How can this take down a site? I've looked at the original issue on security.drupal.org and there is no supporting evidence of this. Yes a user can generate an error by manipulating a URL - is that a problem? If it is then perhaps we need to catch exceptions here. However, I've confirmed that if you've got error logging set to not display error messages all you see a 500 with a message...:

The website encountered an unexpected error. Please try again later.
<br />

I'm not sure that we even need to fix this.

dawehner’s picture

There is this usual argument that once you have a 500 your reverse proxy believes your site is down. I'm not sure at the moment whether this is per path or just for the entire domain. On the other hand this would probably just make the statistics to no longer appear.

In general I believe a 500 would cause less resources than a database insert.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

wim leers’s picture

There is this usual argument that once you have a 500 your reverse proxy believes your site is down.

If this were the case then a single 500 response on d.o would bring all of d.o down. I'm 99.9999% certain that the reverse proxy will not conclude that the entire site is down. (If it happens for GET requests on the frontpage, that's a different story.) I'm 80% certain that most reverse proxies only consider a site to be down when their requests to origin time out.

In general I believe a 500 would cause less resources than a database insert.

True. That would make this a scalability rather than a security improvement issue.

OTOH, what do we really gain from letting the DB to attempt this query? The whole point of this controller is to receive requests from anonymous users to track page views. It's totally possible to DDoS Drupal by sending millions of requests to this. Similarly, you can bypass Drupal's page cache by providing a random URL query string. These are not things Drupal can protect against, that's up to the layer above it.

So, I agree with @alexpott:

I'm not sure that we even need to fix this.

wim leers’s picture

Assigned: Unassigned » catch

Oh, looks like @catch has a different experience — quoting him from #2:

I don't agree this is a DOS as such, but I have seen load balancers configured to take web servers out of rotation when they return enough 5** errors, and this would allow you to trigger that condition.

Let's get his thoughts on this, also because he created this issue.

dawehner’s picture

If this were the case then a single 500 response on d.o would bring all of d.o down. I'm 99.9999% certain that the reverse proxy will not conclude that the entire site is down. (If it happens for GET requests on the frontpage, that's a different story.) I'm 80% certain that most reverse proxies only consider a site to be down when their requests to origin time out.

It is not an issue when you customize your settings. A better alternative for the uptime of your site is a dedicated script. Individual 500s then don't kill your site.

alexpott’s picture

If we want to stop this page throwing 500s that might be reasonable. Whilst I'm not sure that the site being taken down is a good argument I think saying that a script like this should not present an error ever might be. Therefore catching exceptions is what we should do rather than trying to filter because we can't get that right for the different databases we support.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new2.62 KB

#61 sounds great!

First, rebasing.

Status: Needs review » Needs work

The last submitted patch, 62: 2616330-62.patch, failed testing. View results

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new1.85 KB
new1.85 KB

This implements #61.

Status: Needs review » Needs work

The last submitted patch, 64: 2616330-63.patch, failed testing. View results

dawehner’s picture

Do you mind adding back in the test?

Anonymous’s picture

Sorry for the stupid question, but why does the internal script collect statistics on external queries at all?

It would be better to do this on sever side just before sending the render page:

  1. Do not check the validity nid (int range, existence node, user permissions to view, ...)
  2. No extra costs for sending and processing Ajax requests.
  3. No extra settings for statistics.php (like .htaccess rule).
  4. No dependence on js support by device. I know a wide range of people who surf the Internet with js disabled (for the sake of saving device charging and security).
  5. The best guarantee that the page was actually viewed (after all it was necessary to fully render it to increase the statistic counter).
yogeshmpawar’s picture

Status: Needs work » Needs review
StatusFileSize
new1.51 KB

Rerolled the patch against 8.6.x branch because its failed to apply.

shardulagg’s picture

Assigned: catch » shardulagg
StatusFileSize
new1.8 KB

Only local images are allowed.

added comments with changes

timmillwood’s picture

Assigned: shardulagg » Unassigned

@vaplas Re: #67 - This used to be a server side request back in early releases of Drupal 7 and before, but it meant you couldn't use it with reverse proxy caching like Varnish, because only the first view after a cache clear would get counted. The AJAX request was put in to bypass the caching and count all views.

timmillwood’s picture

Status: Needs review » Needs work

Re #68 @Yogesh Pawar

+++ b/core/modules/statistics/statistics.php
@@ -8,23 +8,28 @@
+  // Never pres

Incomplete comment

Re #69 @shardulagg

+++ b/core/modules/statistics/statistics.php
@@ -8,23 +8,36 @@
+try { // added try/catch block to handle PDOException ¶
...
+    ¶
+	  $nid = filter_input(INPUT_POST, 'nid', FILTER_VALIDATE_INT, [
+    	// range set so that value of nid does not goes out of bound and PDOException is not triggered
+		'options' => [
+						'min_range' => 0,
+      					'max_range' => 4294967295,
+    				 ],
+  	]);  ¶
+	  ¶
...
+  // do nothing ¶

Lots of odd white space added.
Missing capital letters and full stops / periods.
Comments longer than 80 characters.

yogeshmpawar’s picture

Status: Needs work » Needs review
StatusFileSize
new1.73 KB
new1.02 KB

Updated patch & interdiff as per comment #71

timmillwood’s picture

Status: Needs review » Needs work

As suggested in #66, can we have the test back?

  1. +++ b/core/modules/statistics/statistics.php
    @@ -8,23 +8,31 @@
    +  // Added try/catch block to handle PDOException.
    

    I think we can remove this comment.

  2. +++ b/core/modules/statistics/statistics.php
    @@ -8,23 +8,31 @@
    +    $nid = filter_input(INPUT_POST, 'nid', FILTER_VALIDATE_INT, ['options' => ['min_range' => 0, 'max_range' => 4294967295]]);
    

    The options array looks like it can be removed?

Anonymous’s picture

@timmillwood, thank you very much for your help in this matter. Clever mechanism hiding here. I knew it!) Perhaps it is worth discussing this change, but this is certainly beyond the scope of this issue.


Additional interdiff file for the main patch withgit diff -w will make review the patch more readable (now shifting all lines creates unnecessary noise).

Also, the decision taken does not coincide with the IS / title of issue. Because we don't validate nid, but just catch exceptions. Or not?

andypost’s picture

This is bug and why test is lost? #66 said it as well

+++ b/core/modules/statistics/tests/src/Functional/StaitsticsInvalidPostTest.php
@@ -0,0 +1,40 @@
+class StatisticsInvalidPostTest extends StatisticsTestBase {

this one from #62

  1. +++ b/core/modules/statistics/statistics.php
    @@ -8,23 +8,31 @@
    +    $nid = filter_input(INPUT_POST, 'nid', FILTER_VALIDATE_INT, ['options' => ['min_range' => 0, 'max_range' => 4294967295]]);
    

    better to expand options array to next lines

  2. +++ b/core/modules/statistics/statistics.php
    @@ -8,23 +8,31 @@
    +  // Do nothing.
    

    better to tell why... do nothing

mohit_aghera’s picture

Status: Needs work » Needs review
StatusFileSize
new3.53 KB
new2.65 KB

Adding removed test cases again. see #66
Fixed issues mentioned by @andypost
Need some more help in refining catch block description further.

Status: Needs review » Needs work

The last submitted patch, 76: 2616330-75.patch, failed testing. View results

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs work » Needs review
StatusFileSize
new3.97 KB
new4.28 KB

Starting at #76 not sure why the test was added to the file module? The namespace even says statistics so I went ahead and moved that.

Updated phpcs errors and deprecated calls.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new144 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

pooja saraah’s picture

StatusFileSize
new4.28 KB
new1.77 KB

Fixed failed commands on #86
Attached patch against Drupal 10.1.x

_pratik_’s picture

StatusFileSize
new4.41 KB
_pratik_’s picture

Status: Needs work » Needs review
alexpott’s picture

+++ b/core/modules/statistics/statistics.php
@@ -8,23 +8,38 @@
+    // Range set so that value of nid does not goes out of bound
+    // and PDOException is not triggered.
+    $nid = filter_input(INPUT_POST, 'nid', FILTER_VALIDATE_INT, [
+      'options' => [
+        'min_range' => 0,
+        'max_range' => 4294967295,
+      ],
+    ]);

In #61 we agreed to not validate the range. It's not possible to set a value for all DB types supported by core. The correct patch to be re-rolling is #68 - unfortunately #69 added this back in without explanation and after it was decided that filtering by number is incorrect.

smustgrave’s picture

Status: Needs review » Needs work
andypost’s picture

Title: statistics.php should validate nid is within range » statistics.php can exit early and prevent output errors
Status: Needs work » Needs review
StatusFileSize
new3.02 KB
new3.49 KB

Address #92 by removing extra range filtering which is database dependent and will need real controller to check further access (currently it using config setting) and re-titled

Interdiff vs #89 - we should not add theme to base test as child ones must care

andypost’s picture

Hope this kind of optimization fits

+++ b/core/modules/statistics/statistics.php
@@ -8,23 +8,34 @@
+  $request = Request::createFromGlobals();
+  $kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod');
...
-    $container->get('request_stack')->push(Request::createFromGlobals());
...
+    $container->get('request_stack')->push($request);

I see no reason to have 2 requests because of bug #2613044: Requests are pushed onto the request stack twice, popped once

smustgrave’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs issue summary update

Feel bad I was part of that carrying the bad approach forward.

Can we update the issue summary for the proposed solution and remaining tasks?

andypost’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update

Updated to the last patch and #61

smustgrave’s picture

Thanks for the quick turnaround.

So reading the proposed solution compared to the patch I see it now.

Ran the test locally just to make sure it failed but it passes without the fix. So think they need to be tweaked.

quietone’s picture

Status: Needs work » Postponed

Statistics is approved for removal. See #3266457: [Policy] Deprecate Statistics module in D10 and move to contrib in D11

This is now Postponed. The status is set according to two policies. The Remove a core extension and move it to a contributed project and the Extensions approved for removal policies.

It will be moved to a contributed Statistics project once the project is created and the Drupal 11 branch is open.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Project: Drupal core » Statistics
Version: 11.x-dev » 1.0.0-beta1
Component: statistics.module » Code
Status: Postponed » Needs work
fgm’s picture

Issue summary: View changes

Reworded IS to account for changes since D8.

fgm’s picture

Status: Needs work » Needs review

Pinging @catch since you were the original issue poster. @mallezie @stefank since you did the most patches before the split.

fgm’s picture

Daniel's suggestion in #5 is relevant in the "transitions tracking" part of the plan #3436823: Plan for Statistics 1.x.

fgm’s picture

Regarding the nid validation : the maximum check was removed for DB independence, but can we agree we should really keep the min_range => 1 check ? I do not think there is any case in which a nid can be zero or negative, is there ?

Although it will not be inserted because the column is marked UNSIGNED, applying the check in the filter will save a roundtrip to the DB in that case.

  • fgm committed 8cc5bbd9 on 1.x
    git commit -m 'Issue #2616330 by mallezie, fgm, stefank, Wim Leers,...
fgm’s picture

Status: Needs review » Fixed

Merged 9 years later. Thanks everyone.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.