kern/filepizza
حول
:pizza: نقل الملفات من نظير إلى نظير في متصفحك
تطوير الويب والتطبيقاتالنمو المقاس للنجوم
- خلال 24 ساعة
- +٢
- خلال 7 أيام
- +٧
- خلال 15 يومًا
- +١٣
- خلال شهر
- +٣٨
تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.
README.md
الأصلPeer-to-peer file transfers in your browser
Cooked up by Alex Kern & Neeraj Baid while eating Sliver @ UC Berkeley.
Using WebRTC, FilePizza eliminates the initial upload step required by other web-based file sharing services. Because data is never stored in an intermediary server, the transfer is fast, private, and secure.
A hosted instance of FilePizza is available at file.pizza.
What's new with FilePizza v2
- A new UI with dark mode support, now built on modern browser technologies.
- Works on most mobile browsers, including Mobile Safari.
- Transfers are now directly from the uploader to the downloader's browser (WebRTC without WebTorrent) with faster handshakes.
- Uploaders can monitor the progress of the transfer and stop it if they want.
- Better security and safety measures with password protection and reporting.
- Support for uploading multiple files at once, which downloaders receive as a zip file.
- Streaming downloads with a Service Worker.
- Out-of-process storage of server state using Redis.
- A command line client for sending and receiving from a terminal.
Development
Requires Node.js 24 or newer (CI and the Docker image use 26) and pnpm.
$ git clone https://github.com/kern/filepizza.git
$ pnpm install
$ pnpm dev # development server on http://localhost:3000
$ pnpm build # production build into .output/
$ pnpm start # run the production build
Run pnpm lint:check, pnpm format:check, pnpm type:check, pnpm test:coverage and pnpm test:e2e (after pnpm build) before opening a pull request, or pnpm ci to run everything. See AGENTS.md for more on the project layout.
Running with Docker
$ pnpm docker:build
$ pnpm docker:up
$ pnpm docker:down
Command line client
filepizza sends and receives files from a terminal, and works with the website: a link from filepizza send opens in any browser, and filepizza receive takes a link made on the website. It is written in TypeScript and compiled with Bun into one executable.
$ pnpm install
$ pnpm build:cli # needs Bun; writes dist/filepizza
$ ./dist/filepizza send photo.jpg notes/
Share link: https://file.pizza/download/abcd1234
$ ./dist/filepizza receive https://file.pizza/download/abcd1234
send <file or folder>...shares files, and folders with everything in them, until you press Ctrl-C.--onceexits after one download has finished, which suits scripts.receive <link>saves the files into the current folder, or the one given with--output. It also takes just the code from the end of a link, with--servernaming the site. It will not overwrite existing files unless you pass--force.--server <url>picks the FilePizza server (defaulthttps://file.pizza, or$FILEPIZZA_SERVER), so it works with a self-hosted one.--password <text>protects a share, or answers its prompt. Set$FILEPIZZA_PASSWORDinstead where you can: command line arguments are visible to other users of the machine.
The Docker image includes it as well, at /usr/local/bin/filepizza: docker exec <container> filepizza send --server http://localhost:3000 file (inside the container, the server is on port 3000).
Like the website, it needs the sender to stay online while the transfer runs, and the files go directly between the two machines. Executables for Linux (x64, arm64), macOS (Apple silicon and Intel) and Windows (x64) are attached to each GitHub release with a SHA256SUMS file; unpack one and run it (they aren't code signed, so macOS may ask you to allow a download from a browser: xattr -d com.apple.quarantine filepizza). Building it yourself produces an executable for the machine that builds it, because its WebRTC library ships a native addon for each platform. Releases are made by pushing a tag that matches the version in package.json (git tag v2.1.0 && git push origin v2.1.0). During development, pnpm cli send ... runs it without compiling.
Security notes
- A share link is the only secret: anyone who has it can download, unless a password is set. The short code is 8 characters of
a-z0-9(about 2.8 trillion possibilities) and the long link five words from a list of 98 (about 9 billion). Guessing is what the rate limiter is for: turn it on for a public instance, or limit the same paths at your reverse proxy. - Passwords are checked by the uploader and are not rate limited per downloader. Use a long one if the link may be seen by others.
- The client treats what the sender says as untrusted: it saves files only inside the download folder (not through links that lead out of it, and never overwriting without
--force), refuses names with control characters, and shows nothing from the sender unescaped in your terminal. It does trust the sender for how much data arrives, as a browser download does; it refuses an offer larger than the free disk space. sendshares exactly the files and folders you name (links inside a folder are skipped). Anyone with the link gets them until you stop it.
Securing TURN
/api/ice hands out TURN credentials to anyone who asks, so a TURN server (coturn) that uses them is a relay for whoever visits. Three things keep that in check:
- Limit the credentials.
RATE_LIMIT_ICE(default 20 a minute per client, see Rate limiting) bounds how many one client can get. In the default setup each credential is also a key stored in Redis forTURN_CREDENTIAL_TTL(24 hours); withTURN_SECRETset, credentials are derived from the shared secret instead and nothing is stored, so prefer that for a public instance: setTURN_SECRETin.envand run coturn with--use-auth-secret --static-auth-secret=<the same secret>instead of--redis-userdb. - Limit what coturn will relay.
docker-compose.production.ymlruns coturn with--denied-peer-ipfor private, loopback and link-local ranges,--no-multicast-peersand--no-tcp-relay, plus caps on allocations and bandwidth:TURN_USER_QUOTA(12 concurrent allocations per credential),TURN_TOTAL_QUOTA(1000 in all),TURN_MAX_BPS(12,500,000 bytes a second, about 100 Mbit/s, per session) andTURN_BPS_CAPACITY(0, no total cap: set it to your uplink if you want one). Change them in.env. - Keep credentials short-lived. Lower
TURN_CREDENTIAL_TTLif your transfers are short; the trade-off is that a relayed transfer is cut off when its credential expires.
I checked the compose settings against the real coturn image: with stock coturn, which is what runs without them, a credential holder could ask it to relay to private addresses such as 10.x, 172.16-31.x and 192.168.x, and with them every private range is refused while public peers still work, and a credential can only hold the number of allocations the quota allows. Peers that can reach each other on a LAN normally connect directly and don't use the relay, but if you run FilePizza and its peers all inside one private network and rely on TURN between them, remove the private ranges from the denied-peer-ip list.
Rate limiting
A share link is the only thing that protects a share, so anything that lets a client try many links, or make many channels or TURN credentials, is worth limiting. It is off unless asked for, so that development and a FilePizza behind a proxy that isn't set up for it are not surprised, and docker-compose.production.yml turns it on (set RATE_LIMIT_ENABLED=false in .env to turn it off there). With RATE_LIMIT_ENABLED=true FilePizza counts, per client address and window, requests to:
| Setting | Counts | Default |
|---|---|---|
RATE_LIMIT_LOOKUPS |
the download page, GET /api/channel/*, POST /api/destroy |
60 |
RATE_LIMIT_CREATES |
POST /api/create |
30 |
RATE_LIMIT_ICE |
POST /api/ice |
60 |
A client over its limit gets 429 Too Many Requests with a Retry-After header, the download page says to wait, and the command line client says so too. Each limit has its own count, and the window starts with a client's first request.
- Storage. With
REDIS_URLset the counts live in Redis (keysratelimit:<kind>:<client>, each with an expiry), so several instances share them; the counting runs as one script inside Redis. Without it they are kept in memory, which suits a single instance. If Redis fails, requests are let through instead of refused. - Who a client is. By default the address that connected. Behind a reverse proxy that is the proxy, so every visitor would share one count: set
RATE_LIMIT_PROXY_HOPSto the number of proxies that append toX-Forwarded-For(1 for nginx or a single load balancer, 2 for a CDN plus a load balancer). The client is then taken that many entries from the right, so what a client puts further left in the header is ignored. Only set it if the proxies do append; with it set and no header the connecting address is used. IPv6 addresses are counted by their /64, since one person can have a whole /64. - Choosing limits. People on one network, such as an office, share an address, so keep the defaults generous: they allow about one lookup a second, which makes guessing links hopeless while an ordinary visit makes one or two requests. Tighten them if you see abuse.
Stack
- TanStack Start (TanStack Router, Vite and Nitro)
- React 19 and Tailwind CSS v4
- TypeScript
- PeerJS for WebRTC
- View Transitions
- Oxlint and Oxfmt for linting and formatting
- Vitest and Playwright for tests
- Redis (optional)
Configuration
The server can be customized with the following environment variables:
PORT– Port the production server listens on. Defaults to3000.REDIS_URL– Connection string for a Redis instance used to store channel metadata. If not set, FilePizza falls back to in-memory storage.COTURN_ENABLED– When set totrue, enables TURN support for connecting peers behind NAT.TURN_HOST– Hostname or IP address of the TURN server, as visitors' browsers reach it. Defaults to the host the visitor used to reach FilePizza (honouringX-Forwarded-Host), which is right when coturn runs on the same machine, and falls back to127.0.0.1if that can't be determined.TURN_PORT– Port of the TURN server. Defaults to3478.TURNS_PORT– Port of the TURN-over-TLS server. Defaults to5349.TURN_TRANSPORT– Set toudportcpto restrict the TURN URLs to that transport. By default no transport is requested.TURN_SECRET– Shared secret for coturn'suse-auth-secretmode (static-auth-secret). When set, FilePizza hands out time-limited credentials derived from it and doesn't write them to Redis. When unset, credentials are stored in Redis for coturn'sredis-userdb.TURN_CREDENTIAL_TTL– How long, in seconds, the TURN credentials from/api/icestay valid. Defaults to86400(24 hours); values under 60 are ignored. A relayed transfer still running when they expire is cut off, so don't set it below the longest transfer you want to allow. See Securing TURN.TURN_REALM– Realm used when generating TURN credentials. Defaults tofile.pizza.STUN_SERVER– STUN server URL to use whenCOTURN_ENABLEDis disabled. Defaults tostun:stun.l.google.com:19302.RATE_LIMIT_ENABLED– Set totrueto limit, per client address, how often links can be looked up and made (see Rate limiting). Off by default, and on indocker-compose.production.yml.RATE_LIMIT_WINDOW– Length of the counting window in seconds. Defaults to60.RATE_LIMIT_LOOKUPS– Looking up a link (the download page,/api/channel/*,/api/destroy) per client and window. Defaults to60.RATE_LIMIT_CREATES– Making a channel (/api/create) per client and window. Defaults to30.RATE_LIMIT_ICE– Asking for ICE and TURN settings (/api/ice) per client and window. Defaults to20.RATE_LIMIT_PROXY_HOPS– How many reverse proxies in front of FilePizza append toX-Forwarded-For. Defaults to0: no header is trusted and the client is whoever connected.PEERJS_HOST– Hostname or IP address to the self-hosted PeerJS server. Defaults to0.peerjs.com.PEERJS_PORT– Port of the self-hosted PeerJS server. Defaults to PeerJS's own default (443).PEERJS_PATH– Path to self-hosted PeerJS server. Defaults to/.
Self-hosting
docker-compose.production.yml runs FilePizza with Redis and a coturn TURN server. Out of the box it works when visitors reach FilePizza at the same address as coturn. The server hands the ICE and signalling settings to each visitor's browser, so anything that points at "localhost" would point at the visitor's own computer.
Open the TURN ports on your firewall:
3478(TCP and UDP),5349(TCP and UDP) and the relay range60000-60128(UDP).Serve it over HTTPS so downloads can stream to disk. See the FAQ below.
Optional settings go in a
.envfile next to the compose file (it's read if present):# Only if coturn is reachable at a different address than FilePizza itself. TURN_HOST=turn.example.com # Realm shared by FilePizza and coturn. Defaults to file.pizza. TURN_REALM=turn.example.comTURN_HOSTdefaults to the address the visitor used to reach the site, so a single-machine setup needs nothing. If you put coturn on another host, set it. If peers show as connected but nothing transfers when either side is behind a NAT, checkTURN_HOSTfirst.Signalling server: by default the browsers use the public PeerJS cloud (
0.peerjs.com) to find each other. To run your own, startpnpm start:peerjs(bin/peerjs.js) and setPEERJS_HOST,PEERJS_PORTandPEERJS_PATHto its address.
If you don't need TURN, leave COTURN_ENABLED unset: FilePizza then uses only the STUN server (STUN_SERVER), which works for peers that can reach each other directly, for example on the same network.
FAQ
How are my files sent? Your files are sent directly from your browser to the downloader's browser. They never pass through our servers. FilePizza uses WebRTC to send files. This requires that the uploader leave their browser window open until the transfer is complete.
Can multiple people download my file at once? Yes! Just send them your short or long URL.
How big can my files be? As big as your browser can handle.
Why is my download held in memory when I self-host? Streaming downloads (writing straight to disk, so very large files work) rely on a service worker, which browsers only allow on secure origins: https:// or http://localhost. When FilePizza is served from a plain-HTTP address such as a private IP (http://192.168.x.x), or from Safari, the downloader's browser buffers the whole file in memory and saves it at the end, so big files can fail. Serve your instance over HTTPS (for example behind a reverse proxy with a certificate) to get streaming downloads.
What happens when I close my browser? Keep your browser page open until every recipient finishes downloading. After you close it, the share link stops working. Recipients can still use any files they downloaded in full.
Why doesn't it work with iCloud Private Relay or a VPN? WebRTC needs a direct (UDP) path between the two browsers, or a relay it can reach. Private Relay and many VPNs route Safari's traffic through their own proxies, which can stop that path from forming, so peers never connect. If a transfer stalls on "connecting", turn Private Relay or the VPN off for the page (on iOS: Settings → your name → iCloud → Private Relay) and try again. If you self-host, running coturn with TURN over TCP (TURN_TRANSPORT=tcp) may give these networks a relay they can use.
Why does my download fail with a download manager, or show a 404? FilePizza streams the file from the other browser straight into your download, through a link that only exists inside your browser. A download manager or accelerator that takes over the download and fetches that link itself can't get the file, and shows "404 Not Found". Turn the download manager off for this site and try again. Some browsers, for example when set to ask where to save each file, request the link a second time; for downloads up to 128 MB FilePizza keeps what it has sent so the second request still works, but a larger download can only be requested once.
Are my files encrypted? Yes, all WebRTC communications are automatically encrypted using public-key cryptography because of DTLS. You can add an optional password to your upload for an extra layer of security.
License & Acknowledgements
FilePizza is released under the BSD 3-Clause license. A huge thanks to iblowyourdesign for the pizza illustration.
استكشف مشاريع مشابهة ومرتبطة
جارٍ التحميل…
