📜 ⬆️ ⬇️

How to wind 40k views on Habrahabr. Bug or feature?



Good day to all, the screenshot above was made just before the publication of the article, about him today and will be discussed.
In the process of creating and publishing articles on Habré, I noticed one very interesting feature of the view counter. It consisted in the fact that each time with any editing of an article that has not yet been published and saved as a draft, the counter is increased by +1 each time.

It turned out that for example at the time of publication, the article could already have from 1 to N views. I decided to test my hunch, and created a test article, which I saved as a draft:
')


We make a few changes, each time saving the article to make sure that the view counter really increases:



Well, what if you create a script that will do the same, but without user intervention? The easiest option here would be to use JavaScript and run the execution directly in the browser. After downloading the Tampermonkey plugin, I sketched a small script in it:

// ==UserScript== // @name New Userscript // @namespace http://tampermonkey.net/ // @version 0.1 // @description try to take over the world! // @author You // @match https://habrahabr.ru/* // @grant none // ==/UserScript== var postID = 322272; (function() { 'use strict'; // Your code here... setInterval(fakeEdit, 1000); })(); function fakeEdit() { if (location.href.indexOf('post/' + postID.toString()) > 0) location.href = 'https://habrahabr.ru/topic/edit/' + postID.toString() + '/'; else { text = document.getElementById('text_textarea'); text.value = Math.random().toString(36).substring(2) +'\n'+ Math.random().toString(36).substring(2); to_draft = document.getElementsByName('draft')[0]; to_draft.click(); } } 

What's going on here:

  1. We run an infinite loop with an iteration interval of 1 second, the loop in turn performs the function fakeEdit
  2. The fakeEdit function checks the current page address:
    2.1. if at the moment it is an editing page, then we change the contents of the text_textarea field, in which the text of the article is located, then simulates saving by clicking on the “In Drafts” button;
    2.2. if the address of the current page contains a post , then proceed to editing the article.

Timeout is needed here, so that after the page loads, all the elements have time to load. Run and leave it for a few days. As a result, after a short period of time, we get about the following result:



I do not consider the above described by me - a vulnerability, but still before the publication of this article, I notified the Habr administration about such non-standard behavior of the counter, and here is their answer:
Hello!
Sorry for the late reply. The view counter really counts not only unique views (actually, like similar counters on most resources on the Internet). Before your appeal, it never occurred to us to consider it as a vulnerability, because it is rather difficult to abuse it in our community: if bad material falls into the “most readable”, it will attract the attention of a large number of users who, in turn, “merge” the material rating and the author's karma, so that he will punish himself, and if he gets a good one, then it’s not a pity.

Of course, everyone decides for himself whether to use the knowledge gained or not, but the main thing to remember is that everything has consequences. I decided to stop the script at 40,000 views, but the question of whether there is a limit still remains, as well as what happens when this redistribution is exceeded?

Source: https://habr.com/ru/post/322272/


All Articles