Cloudflare Attachment bugfix submission
#1
Hello:

I am Waldo Alvarez from TradingFuturo, LLC

I finally after years dealing with the issue found the cause of mybb not working properly with cloudflare. At some point even considered dropping mybb and get another forum software. I could not stop using cloudflare since we have a very high traffic, enough to bring down servers if we stop using it.

Anyways I decided to check mybb sources since I saw a similar problem happening with another php files I wrote.

Thing is cloudflare was caching register page for downloads. And when authenticated users attempted to download attachments, were presented with cached copy of "register to download" page instead of contacting the server and download the attachment.

The solution is very simple, I manually patch mybb with every release that overwrites attachment.php

I think is time to integrate it to main source code of mybb save myself time, fix headaches to many sysadmins around the globe and help with mybb adoption


<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
*
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*
*/

define("IN_MYBB", 1);
define('THIS_SCRIPT', 'attachment.php');

+// prevent CloudFlare caching
+header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
+header("Cache-Control: post-check=0, pre-check=0", false);
+header("Pragma: no-cache");

require_once "./global.php";


if you can please provide credit on next release as that will help me get more known in my sector.

Regards
Reply
#2
It looks like this check is unnecessary - removing it instead may help too: https://github.com/mybb/mybb/blob/mybb_1...al.php#L35
devilshakerz.com/pgp (DF3A 34D9 A627 42E5 BC6A 6750 1F2F B8AA 28FF E1BC) ▪ keybase.io/devilshakerz
Reply
#3
(2022-11-27, 02:29 PM)Devilshakerz Wrote: It looks like this check is unnecessary - removing it instead may help too: https://github.com/mybb/mybb/blob/mybb_1...al.php#L35

Yes very likely it can be perfected around those lines. But you get the idea of the problem. Is like a hack on my side. I am not a mybb developer. I could at some point but currently haven't digged much inside it. Lots of work on my side hehe. Sometimes I mod and hack my installed plugins here and there but that is all about it Wink.

I hope that next mayor version would come with an ORM like eloquent (constructive idea).

Regards
Reply
#4
Wouldn't this affect oppositely when attachments require no authentication ?
Send me a DM or PM if you want to sponsor any update or addition to my plugins.

[Image: signature.png]

Discord omar.gonzalez (Omar G.#6117); Telegram at @omarugc;
Reply
#5
(2022-12-21, 10:41 PM)Omar G. Wrote: Wouldn't this affect oppositely when attachments require no authentication ?

It would reduce caching in that case, buy IMHO Mybb should do something different in such case. Instead of reading the file and send it in a loop should just redirect to the file hosted as static content. But then a lot of logic would have to change for that I guess. Like publishing the file and adding some other way to track the hit count. Considering non-cloudflare hosting.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)