Publish: 2022-06-10 | Modify: 2022-06-10
In an earlier article "Backblaze B2, low-cost object storage, supports integration with CloudFlare CDN," a tutorial was introduced on how to integrate Backblaze B2 with CloudFlare CDN. However, there is a flaw where the B2 domain name exposes the bucket
name, allowing anyone to use your CloudFlare accelerated domain name to accelerate Backblaze B2 or directly access the source site for fraudulent activities. This is not only unfriendly but also unsafe.
For example:
https://f002.backblazeb2.com/file/bucket/xxx.txt
https://b2.domain.com/file/bucket/xxx.txt
If I create a bucket named xiaoz
in B2, then I can access your CloudFlare domain name https://b2.domain.com/file/xiaoz/xxx.txt
, thereby consuming your CloudFlare traffic.
Alternatively, I can directly access your source site: https://f002.backblazeb2.com/file/xiaoz/xxx.txt
for traffic hijacking.
The purpose of this article is to remove the extremely unfriendly URL path of B2 and hide the file/bucket/
content.
If your B2 domain name has not yet been integrated with CloudFlare, please refer to this article: https://blog.xiaoz.org/archives/13256 for integration.
CloudFlare Dashboard - Rules - Transformation Rules - Create Transformation Rule - URL Rewriting.
Continue to fill in:
Then select "Rewrite to - Select Dynamic" for the path, and fill in:
concat("/file/bucket", http.request.uri.path)
Change bucket
to your own storage bucket name, and then select "Deploy".
Before optimization, our access path is: https://b2.domain.com/file/bucket/xxx.txt
After optimization, the path becomes: https://b2.domain.com/xxx.txt
As you can see, file/bucket/
has been removed.
Backblaze B2 adds the following header parameters to the response header of the request:
Although they have little impact, just by looking at these parameters, it is known that you are using B2, and these parameter headers are generally not useful. We can also remove them using CloudFlare's rewrite rules.
Still, in the transformation rules section - Create Transformation Rule - Modify Response Headers.
The hostname part is the same as before:
Then select "Remove" for all of them, and finally fill in the aforementioned header parameters.
The transfer traffic between CloudFlare and Backblaze B2 is free. By using CloudFlare transformation rules, the bucket name can be hidden, making the URL more user-friendly and to some extent preventing the risk of Backblaze B2 being hijacked.
Some of the content in this article is referenced from: 【对象存储】搭配CF带宽联盟实现流量免费
I come from China and I am a freelancer. I specialize in Linux operations, PHP, Golang, and front-end development. I have developed open-source projects such as Zdir, ImgURL, CCAA, and OneNav.