Ciekawy przypadek ubitego WordPress’a

blog.tomaszdunia.pl 1 dzień temu

Go to English version of this post

Opublikowałem dzisiaj wpis Darmowa chmura ~200GB na Twoje pliki, który stał się dość popularny. Udostępniłem go w kilku miejscach, a jednym z nich był portal Hacker News, gdzie wpis wybił się na chwilę na stronę główną. Licznik odwiedzin wystrzelił co z początku mocno mnie ucieszyło. Jednakże po paru minutach zacząłem dostawać wiadomości, iż blog działa, ale sam wpis się nie ładuje. Sprawdziłem i faktycznie tak było. Żadna z podstron bloga nie wczytywała się prawidłowo, a zamiast niej pojawiała się domyślna strona hostingu. Myślę sobie – pięknie, to tyle ze spokojnej niedzieli…

Był to już nie pierwszy raz kiedy blog mi eksplodował na skutek dużej liczby wyświetleń, która uderzała gwałtownie. Przeważnie były to problemy z bazą danych MySQL, która osiągała limit zapytań. Uznałem, iż tym razem to pewnie to samo. To co jednak zwróciło moją uwagę to fakt, iż strona główna działała prawidłowo, tak samo jak panel administracyjny. Na tej podstawie doszedłem do wniosku, iż to musi być coś innego. Ale co?

Jak nie wiem co zrobić to przeważnie uderzam w klawisze i publikuję toota z prośbą o pomoc na Mastodonie. Tak też zrobiłem i tym razem. Na szczęście na pomoc przyszedł mi @m0bi, który skierował mnie we adekwatnym kierunku. To już nie pierwszy raz kiedy m0bi ratuje mi skórę za co z tego miejsca dziękuję! Jego podpowiedź brzmiała “sprawdź rewrite’y i ogólnie .htaccess“. Bingo! Gdy zajrzałem do zawartości pliku .htaccess mojego bloga okazało się, iż wygląda tak:

<Files "wp-login.php"> AuthType Basic AuthName "User: [...] Password: [...]" AuthUserFile /etc/apache2/AUTH/[...] Require valid-user </Files> # BEGIN WordPress # The directives (lines) between "BEGIN WordPress" and "END WordPress" are # dynamically generated, and should only be modified via WordPress filters. # Any changes to the directives between these markers will be overwritten. # END WordPress

Jak widać wszystkie reguły z sekcji WordPress’a zostały wyczyszczone. Zatem rozwiązanie było bardzo proste i ograniczało się do dopisania:

<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>

To oczywiście rozwiązało problem i strona wróciła do swojej pełnej sprawności. Uf… Kryzys zażegnany, więc przyszła pora zastanowić się co spowodowało wyczyszczenie pliku .htaccess z reguł rewrite. W przypadku WordPress’a winę za katastrofę przeważnie ponosi nieprawidłowo działająca lub wręcz złośliwa wtyczka (plugin). Nie mam stuprocentowej pewności, bo nie udało mi się odtworzyć tej sytuacji, ale mam bardzo poważne podejrzenia, iż mogła to być konkretnie wtyczka Enable Mastodon Apps. Jak na złość zainstalowałem ją dzisiaj, bo trochę grzebałem w ustawieniach wtyczki ActivityPub oraz Friends i natrafiłem na nią jako rozszerzenie działania tej drugiej. Co interesujące po jej instalacji nie miałem czasu się dalej bawić, więc choćby jej nie włączyłem i odroczyłem kucowanie na kiedy indziej. Czy to możliwe, iż jedynie zainstalowana, ale nie włączona wtyczka mogła tak nabruździć? To pytanie pozostawiam na razie bez odpowiedzi, ale na pewno będę jeszcze drążył ten temat.

An interesting case of WordPress being killed

I published a post today titled ~200GB Free Cloud for Your files, which became quite popular. I shared it in several places, one of them being Hacker News, where it briefly made it to the homepage. The visitor counter skyrocketed, which at first made me very happy. However, after a few minutes, I started receiving messages saying that the blog was working, but the post itself wasn’t loading. I checked, and indeed that was the case. None of the blog’s subpages were loading correctly, and instead, the default hosting page appeared. I thought to myself – great, so much for a peaceful Sunday…

This wasn’t the first time the blog crashed due to a large number of views that hit suddenly. Usually, it was MySQL database issues, reaching the query limit. I figured it was probably the same this time. However, what caught my attention was the fact that the homepage was working fine, as well as the admin panel. Based on this, I concluded that it must be something else. But what?

When I don’t know what to do, I usually hit the keys and publish a toot asking for help on Mastodon. That’s what I did this time as well. Fortunately, @m0bi came to help, pointing me in the right direction. It’s not the first time m0bi has saved my day, so I would like to thank him once again from here! His advice was “check the rewrites and the .htaccess file“. Bingo! When I looked into the contents of my blog’s .htaccess file, it turned out to look like this:

<Files "wp-login.php"> AuthType Basic AuthName "User: [...] Password: [...]" AuthUserFile /etc/apache2/AUTH/[...] Require valid-user </Files> # BEGIN WordPress # The directives (lines) between "BEGIN WordPress" and "END WordPress" are # dynamically generated, and should only be modified via WordPress filters. # Any changes to the directives between these markers will be overwritten. # END WordPress

As you can see, all the rules from the WordPress section were cleared out. So, the solution was very simple, and it was just a matter of adding the following:

<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>

This, of course, solved the problem, and the site returned to full functionality. Phew… Crisis averted. Now, it was time to figure out what caused the .htaccess file to lose its rewrite rules. In the case of WordPress, the culprit is usually a malfunctioning or even malicious plugin. I’m not 100% sure, as I wasn’t able to reproduce the issue, but I have a strong suspicion that it could have been the Enable Mastodon Apps plugin. As luck would have it, I installed it today because I was tinkering with the settings of the ActivityPub and Friends plugins and came across it as an extension for the latter. Interestingly, after installing it, I didn’t have time to play with it further, so I didn’t even activate it and postponed having fun for another time. Is it possible that just an installed, but not activated plugin could cause such trouble? I’ll leave this question unanswered for now, but I will definitely investigate further.

Jeżeli podobał Ci się ten wpis to możesz mnie wesprzeć!

Idź do oryginalnego materiału