← All Posts

Self-Hosted Pastebin on Cloudflare Workers vs PrivateBin, Gist and Pastebin.com

You need to hand a log file to a teammate, a config snippet to a client, or an error trace to someone on another network. Slack buries it, email strips the attachment, and a Google Doc means managing permissions for a throwaway share. A pastebin fixes that, but the usual options each fail on something: Pastebin.com adds ads and tracking, PrivateBin needs a VPS, and Gist needs a GitHub account.

This post covers running your own pastebin on Cloudflare Workers, D1 and R2, how the common alternatives compare, and how to deploy PasteHere, which is built on that stack.

How It Compares to Pastebin.com, PrivateBin and GitHub Gist

Pastebin.comPrivateBinGitHub GistPasteHere
Where data livesTheir serversYour VPSGitHub's serversYour Cloudflare account
SetupNoneVPS, PHP, web server, upkeepNoneTwo Wrangler commands and a deploy
Needs an account to shareNoNoViewer needs none for a secret gist; author needs GitHubWorkspace password for private pastes
FilesText onlyOptional attachments, off by defaultYes, as gist filesYes, stored in R2
CostFree with ads, paid tiersFree, plus the VPSFree$29 once, plus your Cloudflare usage

Pastebin.com puts ads and tracking next to what you paste and is public by default, so internal error logs and client configs do not belong there. PrivateBin is a good open-source option with client-side encryption and expiry, but it is a server you have to provision, patch and monitor. If you manage dozens of client sites you probably do not want one more VPS. Gist is convenient if everyone is already on GitHub, but your data sits on GitHub's servers, and field technicians or client staff often have no GitHub account. Secret gists are also unlisted, not access-controlled: anyone with the URL can read them.

Why Cloudflare Workers for a Pastebin

Cloudflare Workers run your code at the edge. Combined with D1 (SQLite) and R2 (object storage) you get a full-stack application with:

  • Zero servers. No VPS to provision, no Docker to configure, no OS to update.
  • Global edge. Pastes and files load from the nearest Cloudflare datacenter, which matters when you open the link from a site with a slow uplink.
  • Automatic SSL. HTTPS without certificate management.

What a Basic Self-Hosted Pastebin Should Do

Before we get into the "how," let's define the "what." A useful pastebin should handle:

  • Text pastes. Paste code, logs, configs, or notes. Get a short, shareable URL.
  • File uploads. Share screenshots, PDFs, and archives without attaching them to emails.
  • Custom slugs. Create memorable links like /pastes/debug-auth-timeout instead of random hashes.
  • Access control. At minimum, password protection. You do not want your internal logs indexed by search engines.
  • Zero data leakage. The pastebin operator should never see your data. All storage is in your own account.

Deploying PasteHere on Cloudflare

PasteHere is built on exactly this stack: Astro 6 for server-side rendering, Cloudflare Workers for hosting, D1 for metadata and sessions, and R2 for file storage. Here is the full deployment flow:

1. Create Cloudflare Resources

bunx wrangler d1 create pastehere-db
bunx wrangler r2 bucket create pastehere-bucket

These commands create a D1 database for storing pastes, users, and sessions, and an R2 bucket for uploaded files. Copy the database ID into wrangler.toml.

2. Run Migrations

bunx wrangler d1 migrations apply pastehere-db --remote

PasteHere ships with SQL migration files. This command applies them to your D1 database, creating all required tables.

3. Deploy

bun run deploy

This builds and deploys the Astro application to Cloudflare Workers. The entire deployment takes under two minutes.

4. Open the Setup Wizard

On first visit, PasteHere runs a setup wizard that checks your Cloudflare resources, prompts for a license key, and lets you set your workspace password. After that, you are live.

Key differentiator: PasteHere's setup wizard creates database tables automatically, so you do not need to run SQL migrations manually. After the deploy, just open the site and follow the wizard.

Security Considerations

A public-facing pastebin needs more than a database. PasteHere includes defense in depth:

  • Password hashing. PBKDF2-SHA256 with 100,000 iterations.
  • Session management. HttpOnly cookies, 7-day expiry, CSRF token validation on all mutations.
  • Rate limiting. KV-backed at 5 req/min for login, 20 req/min for creates.
  • Security headers. Content-Security-Policy, X-Frame-Options: DENY, Strict-Transport-Security.
  • Filename sanitization. Path traversal and header injection prevention on file uploads.
  • Safe error messages. Generic client responses with detailed logging server-side only.

Why Self-Hosted Over SaaS

The main advantage is data sovereignty. Your logs, configs, and files stay in your Cloudflare account, and no third-party server sees them. The code runs on your Workers and the data sits in your D1 and R2, so if the PasteHere vendor disappears your instance keeps running. A hosted pastebin that shuts down takes your links with it.

For teams working on sensitive infrastructure (industrial systems, healthcare, financial services) client contracts often forbid pasting logs into third-party services, so this is a requirement and not a preference.

Cost is your own Cloudflare bill. The free tier (100,000 requests per day, 5 GB of D1, 10 GB of R2) covers an individual or small team. If you outgrow it you upgrade your own Cloudflare plan with no vendor markup. PasteHere itself is a one-time $29 purchase with no subscription. Files go to R2, so you can upload multi-megabyte logs, screenshots, PDFs and ZIPs from the web UI or with curl, which is what you need from a remote server where email strips attachments and chat tools cap file size.

Deploy Your Own Pastebin

PasteHere is a one-click-deploy pastebin for Cloudflare Workers. Text pastes, file uploads, password protection, and full security hardening. $29 one-time.

Get PasteHere ($29)