Paste a secret, get a link, send it. The first person to open it and press
Reveal sees the secret; the link dies at that moment. The recipient needs a
browser and nothing else — no account, no client, no installed tooling.
The server cannot read what it stores. AES-256-GCM happens in the browser and
the key lives in the URL fragment, which browsers never transmit, so hushd
holds ciphertext and no key material. That is a property of where the key sits
rather than a promise about our conduct, which is why there is deliberately no
endpoint accepting a plaintext secret and no server-side-encryption fallback:
two guarantees behind one URL would be worse than one honest guarantee.
Three decisions carry the design:
* GET /s/{id} touches NO storage, not even to check existence. Slack, Teams,
WhatsApp, iMessage and Outlook Safe Links all fetch a URL before a human
sees it, so destroying on GET would destroy most secrets in transit and the
recipient's "already used" would be indistinguishable from interception.
Only POST /reveal consumes. Bot user-agent detection is an arms race;
removing the side effect from GET is not. Pinned by
TestGettingTheRevealPageNeverConsumesTheSecret.
* Destruction is one Redis GETDEL, which is atomic. GET-then-DEL has a window
where two simultaneous readers both win, and for a one-time secret that
window is the product. The store contract demands atomicity and the same
concurrency test runs against both implementations.
* Missing, already-revealed, expired and evicted are ONE indistinguishable
410. Separating them would confirm to a prober that a given link was real.
The secret id IS the capability, so secret.ID is a struct whose every
accidental path — %v, %s, String(), slog, json.Marshal — emits a redacted
handle or refuses, and the raw value needs an explicit Value(). The first
version tried to prevent leaks by implementing no String() at all; its own test
caught that Go's fmt prints unexported fields anyway, so forbidding the method
had removed the control rather than the leak.
Operationally: structured JSON on stdout in the fleet's wire format, which
Vector already collects with no annotation; six hush_* metrics on the chassis
registry with no id, IP or path in any label; five alert rules wired into
vmalert. The public Ingress enumerates /, /s/ and /api/ so /metrics, /healthz
and /readyz share the port but are unreachable from the internet — no
basic-auth middleware to maintain and get wrong.
Dependencies are vendored because go-chassis is private: the Woodpecker test
step and the in-cluster Kaniko build both run -mod=vendor with GOPROXY=off and
hold no git credential.
cmd/hush-mcp is a stdio MCP server doing the same client-side crypto locally,
so using hush from an agent preserves the same guarantee as using it from a
browser.
74 lines
2.6 KiB
Go
74 lines
2.6 KiB
Go
// Package web serves hush's two pages. Both are static: they read no storage,
|
|
// so a link previewer fetching either one cannot destroy a secret.
|
|
package web
|
|
|
|
import (
|
|
"embed"
|
|
"fmt"
|
|
"html/template"
|
|
"net/http"
|
|
)
|
|
|
|
//go:embed templates/*.html
|
|
var files embed.FS
|
|
|
|
// Pages renders the create and reveal pages. Templates are embedded, so the
|
|
// container carries no template directory to go missing at runtime.
|
|
type Pages struct {
|
|
create *template.Template
|
|
reveal *template.Template
|
|
}
|
|
|
|
// Data is everything a page needs. The limits are passed through so the browser
|
|
// enforces the same caps the server does and a user learns their secret is too
|
|
// large before uploading it, not after.
|
|
type Data struct {
|
|
MaxCiphertextBytes int
|
|
DefaultTTLSeconds int
|
|
MinTTLSeconds int
|
|
MaxTTLSeconds int
|
|
}
|
|
|
|
// New parses the embedded templates. It fails at boot rather than on first
|
|
// request: a template error is a build defect and should not wait for traffic
|
|
// to surface.
|
|
func New() (*Pages, error) {
|
|
create, err := template.ParseFS(files, "templates/base.html", "templates/create.html")
|
|
if err != nil {
|
|
return nil, fmt.Errorf("parse create template: %w", err)
|
|
}
|
|
reveal, err := template.ParseFS(files, "templates/base.html", "templates/reveal.html")
|
|
if err != nil {
|
|
return nil, fmt.Errorf("parse reveal template: %w", err)
|
|
}
|
|
return &Pages{create: create, reveal: reveal}, nil
|
|
}
|
|
|
|
// Create writes the create page.
|
|
func (p *Pages) Create(w http.ResponseWriter, d Data) error {
|
|
return render(w, p.create, d)
|
|
}
|
|
|
|
// Reveal writes the reveal page.
|
|
//
|
|
// The secret id is NOT passed in and is NOT interpolated into the HTML. The
|
|
// page reads it from location.pathname in the browser, alongside the key it
|
|
// reads from location.hash. That keeps the template free of any value that
|
|
// could be reflected, and means this handler needs no escaping decisions about
|
|
// a capability.
|
|
func (p *Pages) Reveal(w http.ResponseWriter, d Data) error {
|
|
return render(w, p.reveal, d)
|
|
}
|
|
|
|
func render(w http.ResponseWriter, t *template.Template, d Data) error {
|
|
// no-store on both pages: a cached create page is harmless, but a cached
|
|
// reveal page in a shared proxy would be a copy of a one-time URL.
|
|
w.Header().Set("Cache-Control", "no-store, max-age=0")
|
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
|
// Referrer-Policy is load-bearing here, not boilerplate: without it a click
|
|
// on any link from the reveal page could send the full URL — including the
|
|
// fragment-adjacent path — to a third party.
|
|
w.Header().Set("Referrer-Policy", "no-referrer")
|
|
return t.ExecuteTemplate(w, "base.html", d)
|
|
}
|