Sign inSign up

gas85/ownpastebin

By gas85

โ€ขUpdated 1 day ago

https://github.com/GAS85/ownPastebin/

Image
Developer tools
Web servers
0

6.6K

gas85/ownpastebin repository overview

โ Pastebin

Dev Build Release Build and Push to Dockerhub codecov Release Docker hub Docker Pulls Docker Image Size

Donations: Buy me a coffee PayPal Github Sponsors


A minimal, RAM-friendly paste service with support for raw uploads, TTL, burn-after-read, optional encryption, and pluggable storage backends.


โ Demo

https://sitnikov.eu/pastebin/โ 

โ Donation

Buy me a ๐Ÿบโ 

โ โœจ Features

  • โšก Fast and lightweight

  • ๐Ÿ”Œ Pluggable storage:

    • Valkey / Redis (optional, in-memory)
    • PostgreSQL (optional, persistent)
    • SQLite (default)
  • ๐Ÿ”ฅ Burn-after-read pastes

  • โณ TTL (expiration support)

  • ๐Ÿ” Optional server-side encryption with AES-GCM

  • ๐Ÿ” Optional end-to-end encryption with AES-GCM

  • ๐Ÿ“ฆ Binary-safe uploads/downloads

  • ๐Ÿง  Designed to be memory efficient

  • ๐ŸŒ i18n support - different languages as json files

  • ๐ŸŽจ Theme support - set predefined Theme or use custom CSS to override

  • ๐Ÿช Cookie and Privacy Notice support - set your own links to cookie and privacy policy

  • ๐Ÿ”— Custom links support - set your own personal link with icon to any service

โ โš™๏ธ Configuration

All configuration is done via environment variables.

โ ๐Ÿ—„๏ธ Storage Backends (Priority Order)

The application automatically selects the first available backend, but it is recommended to configure only 1 of them, or use defaults:

  1. Valkeyโ  / Redisโ  - PASTEBIN_REDIS_URL
  2. Postgresโ  - PASTEBIN_POSTGRES_URL
  3. SQLiteโ  default if none above was set - PASTEBIN_SQLITE_PATH
โ Variables
  • PASTEBIN_REDIS_URL - Valkey/Redis connection string. No default - if not set, Valkey/Redis is disabled. Example:

    redis://valkey:6379/0
    
    redis://redis:6379/0
    
  • PASTEBIN_POSTGRES_URL - PostgreSQL connection string. Used if Valkey/Redis is not configured. No default - if not set, PostgreSQL is disabled. Example:

    postgresql://user:pass@postgres:5432/pastebin
    
  • PASTEBIN_SQLITE_PATH - Path to SQLite database file. Default:

    /app/data/pastes.db
    
  • PASTEBIN_SQLITE_PAGE_SIZE - You can set SQLite Page size for a new table. Valid values are power of 2 from 512 to 65536. You can calculate it roughly on following basis:

    • 4096 is default - good for typical text pastes (< 100 KB).
    • 8192 or 16384 - better when pastes are regularly several MB, because each paste fits in fewer pages, reducing I/O and B-tree depth.

โ ๐ŸŒ Application Settings

  • PASTEBIN_BASE_URL- Public base URL of your service. Default:

    http://localhost:8080
    

    Following prefixes are supported:

    • No prefix PASTEBIN_BASE_URL=http://localhost:8080 or PASTEBIN_BASE_URL=https://pastebin.myserver.com
    • Behind nginx at /pastebin - PASTEBIN_BASE_URL=https://myserver.com/pastebin
    • Behind nginx at /tools/paste - PASTEBIN_BASE_URL=https://myserver.com/tools/paste
  • PASTEBIN_HOST - Bind address. Default: 0.0.0.0

  • PASTEBIN_PORT - Port to listen to. Default: 8080

  • PASTEBIN_TLS_KEY - Provide path to TLS Key to enable TLS Support directly on a service.

  • PASTEBIN_TLS_CERT - Provide path to TLS Certificate to enable TLS Support directly on a service.

  • PASTEBIN_TRUSTED_PROXY - Provide IP or CIDR of trusted proxies, so that X-Forwarded-For header will be used.

  • PASTEBIN_LOG_LEVEL - Set log level. Default: Info.

  • PASTEBIN_LOG_FORMAT - Set it to json, to have JSON logs output. Default: text.

  • PASTEBIN_LOG_EXCLUDE - Set it to any regex that you needs to exclude from the logs, e.g. \/health|127.0.0.1 will exclude calls to /health endpoint, and or from IP 127.0.0.1. Default is not set, so that everything shown.

  • PASTEBIN_FILE_LOG - Set log file location to log all App output. Default is not set, it is logged to stdout. If you need log file, simply provide a path writable by user "nobody". Recommended is /app/data/pastebin.log.

โ โณ TTL Settings

  • PASTEBIN_DEFAULT_BURN - If enabled all pastes without burn=false will be saved to be viewed only once. You can still set burn=false via UI or CLI. Default: false.
  • PASTEBIN_DEFAULT_TTL - Default expiration if none provided. Default: 0 (no expiration)
  • PASTEBIN_MAX_TTL - Maximum allowed TTL. It is recommended to set this value for internet accessible sites. It is recommended to set this value if protected pastes are enabled. If set:
    • caps user-provided TTL
    • used when no TTL is provided

Supported Formats:

FormatExample
Seconds3600
Hours1h
Days1d
Months (30d)1mo

โ ๐Ÿ“ Limits

  • PASTEBIN_MAX_PARALLEL_UPLOADS - Max amount of parallel POST requests. Default 20. Be aware that each requests needs memory. E.g. if PASTEBIN_MAX_PASTE_SIZE=5MB and PASTEBIN_MAX_PARALLEL_UPLOADS=20, that needs around 5*20*2,3 (roughly amount of modifications) = 230 Mb of RAM and with PASTEBIN_MAX_PASTE_SIZE=30MB around 1,5 GB of RAM.
  • PASTEBIN_MAX_PASTE_SIZE - Max upload size. Default: 5MB

Supported Formats:

FormatExample
bytes3600
Kilobytes1kb
Megabytes1mb
Gigabytes1gb

โ ๐Ÿ” Security

  • PASTEBIN_SERVER_SIDE_ENCRYPTION_ENABLED- Enable server side encryption before to store the paste. Recommended on shared environments. Default false - disabled.
  • PASTEBIN_SERVER_SIDE_ENCRYPTION_KEY- 32-byte base64 key (required if encryption enabled). You can generate Key with openssl, or directly with this container.
openssl rand -base64 32

Or:

docker run -e GENERATE_KEY=true gas85/ownpastebin:latest

โš ๏ธ If you ever rotate the key or loose it, old pastes become permanently unreadable. There is no restore for it. โš ๏ธ

โ ๐Ÿ•’ Misc

  • PASTEBIN_SLUG_LEN - Uniq URL Length. Default to 20. It is not recommended to go below this value to avoid possible collision (handled by storage) and Link guessing attack.
  • PASTEBIN_PROTECTED_PASTE_ENABLED - enable support for protected pastes. They can be created with a flag protected=true and can be only removed by expiration time or burn option. It is recommended to set PASTEBIN_MAX_TTL this feature is enabled, otherwise it could result in pastes that live indefinitely. They can only be removed via direct database access. Default to false.
  • PASTEBIN_EXPIRY_TIMES - You can set your own expiration timers list as <Name>:<Value in seconds>,. Where <Name> could be Never for never expired pastes, or X <label>, where X expiration time shown in UI and <label> could be one of Min/Hour/Day/Week/Month/Year. E.g. "Never:0,5 Min:300,1 Hour:3600,1 Day:86400,1 Week:604800" will produce following dropdown:
    • Never
    • 5 Min
    • 1 Hour
    • 1 Day
    • 1 Week
  • PASTEBIN_DATE_FORMAT - Text logs timestamp format. Disabled when logs format is set to json. Default: %Y-%m-%d %H:%M:%S
  • TZ - Timezone. Default Europe/Zurich
  • PASTEBIN_THEME - Set custom theme as per W3.CSS Color Themesโ , add e.g. blue, teal, green, etc. Default theme used when not set.
  • PASTEBIN_THEME_CUSTOM_CSS - Overrides Theme with your own CSS. Please use format as in a W3.CSS Color Themesโ . This will overrule PASTEBIN_THEME, you should't use both. Default theme used when non of them set. You can set it to e.g. w3-theme-l5 {color:#000 !important; background-color:#fff !important}.w3-theme-l3 {color:#000 !important; background-color:#f8f9fa !important}....
  • PASTEBIN_COOKIE_URL - Set custom Cookie URL. This Application itself will not set any cookies, but if you are using this application as sub path to your domain or behind e.g. OAUTH2 Proxyโ  they could set cookies and you will need to reference your cookie policy here. Default is not set.
  • PASTEBIN_PRIVACY_URL - Set custom Privacy Policy URL if you need. Default is not set.
  • PASTEBIN_CUSTOM_ICON - Set custom icon to your PASTEBIN_CUSTOM_URL if needed. You can set something from Font Awesomeโ  free collection, e.g. fa-solid fa-question to set a โ”. Default: fa-solid fa-question if PASTEBIN_CUSTOM_URL was set.
  • PASTEBIN_CUSTOM_URL - Set custom URL if needed, works together with PASTEBIN_CUSTOM_ICON. Default is not set.

โ ๐Ÿง  Storage Behavior

ConfigBackend Used
PASTEBIN_REDIS_URLValkey/Redis
PASTEBIN_POSTGRES_URLPostgreSQL
None setSQLite

You can still set custom SQLite DB location via PASTEBIN_SQLITE_PATH.

โ Notes
  • Valkey, or Redis = fastest, but memory-based storage. Fits good for Local network usage.
  • PostgreSQL = persistent, scalable. Fits good for Local network and Internet usage, distributed, high performance.
  • SQLite = zero-config, minimal RAM usage. Default, simple fast storage fits to all.

โ ๐Ÿš€ Run

โ Docker
docker run -d \
  --name pastebin \
  -p 8080:8080 \
  -v ./data:/app/data \
  -e PASTEBIN_MAX_TTL=360d \
  -e PASTEBIN_BASE_URL=http://localhost:8080 \
  --restart always \
  gas85/ownpastebin:latest
โ Docker Compose

Please refer to docker-compose.ymlโ  as example.

docker compose up -d
โ Kubernetes / Openshift

Please refer to k8s.ymlโ  as example.

kubectl apply -f k8s.yml

โ Build

You can build it from sources with following commands:

go mod download
CGO_ENABLED=1 GOOS=linux go build -ldflags="-s -w" -o pastebin .

Or use docker

docker build -t ownpastebin:latest .

You can perform local test automation with following command:

CGO_ENABLED=1 go test ./... -v

โ ๐Ÿ“ฆ Pastebin API

You can find API documentation under /swagger-ui e.g. https://sitnikov.eu/pastebin/swagger-uiโ 

โ ๐Ÿš€ Create Paste - POST /

Create a new paste.

โ Supported Content Types
  • application/json
  • application/x-www-form-urlencoded
  • multipart/form-data
  • raw body (--data-binary)
โ Query Parameters
NameTypeDescription
ttlintTime to live (seconds)
protectedboolProtected paste, will not be deleted upon request, only expiration time and / or burn can remove such kind of pastes
burnboolDelete after first read
encryptedboolMarks paste as client-side encrypted. It is only being used to give UI a trigger to offer Decryption directly in Browser. Otherwise encrypted data will be shown.
โ Examples
โ Raw upload
curl "http://localhost:8080" --data-binary "@file.txt"

E.g. you can push all docker logs to the pastebin:

# As per https://wiki.sitnikov.eu/doku.php?id=howto:docker#push_all_docker_logs_to_the_pastebin
docker ps --format '{{.Names}}' | xargs -I {} sh -c 'docker logs --timestamps -tail 500 {} 2>&1 | sed "s/^/[{}] /"' | curl http://localhost:8080 --data-binary @-
โ Burn after read + TTL
curl "http://localhost:8080?burn=true&ttl=60" --data-binary "@file.txt"
โ Burn after read + TTL + protect paste from deletion
curl "http://localhost:8080?burn=true&ttl=60&protected=true" --data-binary "@file.txt"
โ Response

As Response you will get JSON with URL to the webUI for this paste and paste ID that you can use e.g. to call /raw or /download endpoint.

{
  "url": "http://localhost:8080/abc123",
  "id": "abc123",
  "lang": "text"
}
โ ๐Ÿ“– View Paste - GET /{paste_id}

Returns HTML view.

curl http://localhost:8080/abc123
โ ๐Ÿ“„ View Raw Paste - GET /raw/{paste_id}

Returns plain text or binary-safe response.

curl http://localhost:8080/raw/abc123
โ โฌ‡๏ธ Download Paste - GET /download/{paste_id}

Forces file download.

curl http://localhost:8080/download/abc123
โ โŒ Delete Paste - DELETE /{paste_id}
curl -X DELETE http://localhost:8080/abc123
โ ๐Ÿ”ฅ Burn After Read

If burn=true:

  • First request โ†’ returns content
  • Second request โ†’ 404 Not Found
โ Protected paste

if protected=true:

  • DELETE Method is disabled for this paste and will return 403 Forbidden with paste is protected message
  • Burn and expiration time works as before and will remove protected pastes too
โ โš ๏ธ Limits & Errors
โ Paste too large
413 Paste too large
403 Paste is protected

โ ๐Ÿงพ Logging

Example:

2026-03-25 09:55:57 - INFO - pastebin - access method=GET path=/ status=200 duration=1.077ms bytes=15044 ip=192.168.65.1:57801
{"level":"INFO","msg":{"bytes":14562,"duration":"710ยตs","ip":"192.168.65.1:59435","message":"access","method":"GET","path":"/","status":200},"time":"2026-04-27T20:13:34.986291506+02:00"}

โ Translate

  1. Copy static/en.json to any new language file you need.
  2. Translate it.
  3. In static/custom.js update const flags with new language.
  4. In templates/index.html and templates/index_full.html add new language in i18n-dropdown div.

โ ๐Ÿ› ๏ธ Notes

  • Works with curl, browsers, API clients
  • Binary-safe storage
  • No in-memory caching โ†’ RAM efficient
  • SQLite uses WAL mode for better concurrency
  • Expired pastes are cleaned on access (lazy cleanup) and periodically during the day

โ ๐Ÿ“Œ Summary

This pastebin is designed to be:

  • โšก Fast
  • ๐Ÿง  Memory-efficient
  • ๐Ÿ”Œ Flexible (multi-backend)
  • ๐Ÿ” Secure (optional encryption)

Inspired by Pastebinโ .

Tag summary

Content type

Image

Digest

sha256:783105668โ€ฆ

Size

14 MB

Last updated

1 day ago

docker pull gas85/ownpastebin