← All Posts

How to Run a Self-Hosted Pastebin on Cloudflare Workers

Everyone has hit the problem: you need to share a log file with a teammate, pass a config snippet to a client, or send an error trace to someone on another network. You paste it into Slack, it gets lost. You email it, the attachment gets stripped. You open a Google Doc, and now you're managing access permissions for a throwaway share.

A pastebin solves this. But between Pastebin.com's ads and tracking, PrivateBin's need for a VPS, and GitHub Gist's requirement of a GitHub account, there is no option that is fast, private, and effortless — especially from a remote server with limited internet access.

Enter self-hosted pastebins on Cloudflare Workers.

Why Cloudflare Workers for a Pastebin

Cloudflare Workers run your code at the edge — in data centers close to your users. Combined with D1 (SQLite database) 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.
  • Free tier. 100,000 requests/day, 5GB D1 storage, 10GB R2 storage — all free.
  • Automatic SSL. HTTPS without certificate management.
  • No cold starts. Workers are always warm, so paste creation is instant.

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 of self-hosting is data sovereignty. Your logs, configs, and files stay in your Cloudflare account. No third-party server sees your data. If the pastebin provider disappears, your instance keeps running.

For teams working on sensitive infrastructure — industrial systems, healthcare, financial services — this is not a nice-to-have. It is a requirement.

Cloudflare's free tier is generous, but if you exceed it, you upgrade your own Cloudflare plan. You are not paying a vendor markup on top of infrastructure costs.

Frequently Asked Questions

How much does it cost to run a pastebin on Cloudflare Workers?

Cloudflare's free tier includes 100,000 requests per day, 5 GB of D1 database storage, and 10 GB of R2 object storage — enough for most individual and small-team use. PasteHere itself is a one-time $29 purchase with no subscription. If you exceed the free tier, you upgrade your own Cloudflare plan directly, with no vendor markup.

How long does it take to deploy a self-hosted pastebin on Cloudflare?

Under 5 minutes. You create a D1 database and R2 bucket with two Wrangler CLI commands, run the migration, deploy with bun run deploy, then open the site and follow the setup wizard. The wizard handles database table creation and license activation in a single flow. No Docker, no VPS provisioning, no PHP configuration.

Is a Cloudflare Workers pastebin secure enough for sensitive data?

Yes. PasteHere uses PBKDF2-SHA256 password hashing with 100,000 iterations, HttpOnly session cookies with CSRF token validation, KV-backed rate limiting (5 req/min for login, 20 req/min for creates), and security headers including Content-Security-Policy and Strict-Transport-Security. All data stays in your own Cloudflare account — no third-party server ever sees your pastes or uploaded files.

Can I upload files to a self-hosted pastebin on Cloudflare Workers?

Yes. Files are stored in Cloudflare R2 object storage. You can upload logs, screenshots, PDFs, ZIP archives, and configuration files via the web interface or the REST API using curl. This is useful for sharing multi-megabyte log files from remote servers where email attachments get stripped and Slack has file size limits.

What happens to my pastebin if the PasteHere vendor disappears?

Your deployment keeps running independently. PasteHere deploys to your own Cloudflare account — the code runs on your Workers, data goes to your D1 and R2, and the domain is yours. There is no dependency on the vendor's servers after deployment. This is the core advantage of self-hosting over SaaS pastebins that can shut down without warning.

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