secret_paste 0.0.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,178 @@
1
+ """The pages around a self-hosted, zero-knowledge secret paste (PrivateBin), from one source.
2
+
3
+ A site that runs PrivateBin for its people needs two things that PrivateBin does not ship:
4
+ an explainer (how the key stays in the link's ``#fragment``, what the server can and cannot
5
+ see, an honest threat model, a live in-page demo) and a way to reach it from the paste
6
+ page itself. This package holds both as templates, so a fix to either lands once and
7
+ every site that renders them gets it.
8
+
9
+ >>> site = Site(operator="Ada", site="example.org",
10
+ ... paste_url="https://secrets.apps.example.org/",
11
+ ... explainer_url="https://apps.example.org/secrets/")
12
+ >>> html = render_explainer(site)
13
+ >>> 'href="https://secrets.apps.example.org/"' in html and '{{' not in html
14
+ True
15
+ >>> 'href="https://apps.example.org/secrets/"' in render_privatebin_template(site)
16
+ True
17
+
18
+ From the shell (``python -m secret_paste`` or ``secret-paste``), with a TOML file holding
19
+ the same fields::
20
+
21
+ secret-paste explainer site.toml -o frontend/index.html
22
+ secret-paste privatebin-template site.toml -o server/secretpaste.php
23
+ secret-paste explainer site.toml -o frontend/index.html --check # exit 1 if stale
24
+ """
25
+
26
+ from __future__ import annotations
27
+
28
+ import html
29
+ import json
30
+ import re
31
+ from collections.abc import Mapping
32
+ from dataclasses import dataclass, fields
33
+ from importlib.resources import files
34
+ from typing import Literal
35
+ from urllib.parse import urlsplit
36
+
37
+ __all__ = [
38
+ "RENDERERS",
39
+ "Site",
40
+ "render_explainer",
41
+ "render_privatebin_template",
42
+ ]
43
+
44
+ _PLACEHOLDER = re.compile(r"\{\{(\w+)\}\}")
45
+ # A URL we write into HTML attributes and a PHP single-quoted string: https, a host,
46
+ # an optional plain path. Nothing that needs escaping in either place.
47
+ _SAFE_URL = re.compile(
48
+ r"https://[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)+"
49
+ r"(?::[0-9]{1,5})?(/[A-Za-z0-9._~/-]*)?"
50
+ )
51
+
52
+
53
+ @dataclass(frozen=True)
54
+ class Site:
55
+ """What differs between two sites that run the same secret paste.
56
+
57
+ ``paste_url`` is where PrivateBin answers (ideally its own host, so its page shares
58
+ no origin with anything else); ``explainer_url`` is where the explainer is served.
59
+ ``voice`` is ``"I"`` for a site run by one person, ``"we"`` for a team.
60
+ """
61
+
62
+ operator: str
63
+ site: str
64
+ paste_url: str
65
+ explainer_url: str
66
+ voice: Literal["I", "we"] = "I"
67
+ signin_phrase: str = "a sign-in"
68
+ brand: str = ""
69
+ og_image: str = ""
70
+
71
+ def __post_init__(self):
72
+ for name in ("paste_url", "explainer_url") + (
73
+ ("og_image",) if self.og_image else ()
74
+ ):
75
+ value = getattr(self, name)
76
+ if not _SAFE_URL.fullmatch(value):
77
+ raise ValueError(f"{name} must be a plain https URL, got {value!r}")
78
+ if not self.paste_url.endswith("/"):
79
+ raise ValueError(f"paste_url must end with '/', got {self.paste_url!r}")
80
+ if self.voice not in ("I", "we"):
81
+ raise ValueError(f"voice must be 'I' or 'we', got {self.voice!r}")
82
+
83
+ @classmethod
84
+ def from_mapping(cls, data: Mapping) -> Site:
85
+ """A ``Site`` from a mapping (a parsed TOML file), refusing unknown keys."""
86
+ known = {f.name for f in fields(cls)}
87
+ if unknown := set(data) - known:
88
+ raise ValueError(
89
+ f"unknown site keys {sorted(unknown)}; known: {sorted(known)}"
90
+ )
91
+ return cls(**data)
92
+
93
+
94
+ def _template(name: str) -> str:
95
+ return files(__package__).joinpath("data", name).read_text(encoding="utf-8")
96
+
97
+
98
+ def _fill(template: str, values: Mapping[str, str]) -> str:
99
+ """Replace every ``{{name}}``; a placeholder without a value, or a value without a
100
+ placeholder, is an error (a template and its renderer that drifted apart)."""
101
+ used = set(_PLACEHOLDER.findall(template))
102
+ if missing := used - set(values):
103
+ raise KeyError(f"template placeholders without a value: {sorted(missing)}")
104
+ if extra := set(values) - used:
105
+ raise KeyError(f"values without a placeholder in the template: {sorted(extra)}")
106
+ return _PLACEHOLDER.sub(lambda m: values[m.group(1)], template)
107
+
108
+
109
+ def _explainer_values(site: Site) -> dict[str, str]:
110
+ e = html.escape
111
+ parts = urlsplit(site.paste_url)
112
+ host = parts.hostname or ""
113
+ path = parts.path or "/"
114
+ own_host = path == "/"
115
+ kicker = " · ".join(
116
+ p
117
+ for p in (
118
+ site.brand,
119
+ "Secret paste",
120
+ host + ("" if own_host else path.rstrip("/")),
121
+ )
122
+ if p
123
+ )
124
+ # Say "its own address" only when it is one: a paste under a path shares its origin.
125
+ address_clause = (
126
+ f"on its own address ({e(host)}, so it shares no origin with the other tools on {e(site.site)}), "
127
+ if own_host
128
+ else ""
129
+ )
130
+ if site.og_image:
131
+ social = (
132
+ f'<meta property="og:image" content="{e(site.og_image)}">\n'
133
+ '<meta property="og:image:width" content="1200">\n'
134
+ '<meta property="og:image:height" content="630">\n'
135
+ '<meta name="twitter:card" content="summary_large_image">'
136
+ )
137
+ else:
138
+ social = '<meta name="twitter:card" content="summary">'
139
+ solo = site.voice == "I"
140
+ return {
141
+ "social_card_html": social,
142
+ "kicker": e(kicker),
143
+ "paste_url": e(site.paste_url),
144
+ # A JS string literal inside an inline <script>: json, and no "</" can close it.
145
+ "paste_url_js": json.dumps(site.paste_url).replace("</", "<\\/"),
146
+ "paste_path": e(path),
147
+ "address_clause": address_clause,
148
+ "paste_host": e(host),
149
+ "operator_title": "Me, the operator, being curious"
150
+ if solo
151
+ else "Us, the operators, being curious",
152
+ "operator_can_see": (
153
+ "I can see that a paste exists and how big it is. I can't read it."
154
+ if solo
155
+ else "We can see that a paste exists and how big it is. We can't read it."
156
+ ),
157
+ "we_looked": "I looked" if solo else "We looked",
158
+ "signin_phrase": e(site.signin_phrase),
159
+ "operator": e(site.operator),
160
+ "site": e(site.site),
161
+ }
162
+
163
+
164
+ def render_explainer(site: Site) -> str:
165
+ """The explainer page: one self-contained HTML file, no external loads."""
166
+ return _fill(_template("explainer.html"), _explainer_values(site))
167
+
168
+
169
+ def render_privatebin_template(site: Site) -> str:
170
+ """A PrivateBin template: upstream's bootstrap5 page plus a "How this works" link
171
+ near the top, pointing at ``site.explainer_url``."""
172
+ return _fill(_template("secretpaste.php"), {"explainer_url": site.explainer_url})
173
+
174
+
175
+ RENDERERS = {
176
+ "explainer": render_explainer,
177
+ "privatebin-template": render_privatebin_template,
178
+ }
@@ -0,0 +1,43 @@
1
+ """Command line: render one of secret_paste's files from a site's TOML file.
2
+
3
+ ``secret-paste {explainer,privatebin-template} SITE.toml -o OUT [--check]``. With
4
+ ``--check`` nothing is written; the exit status is 1 when OUT differs from a fresh render,
5
+ so a platform's test can catch a committed copy that fell behind the template.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import argparse
11
+ import sys
12
+ import tomllib
13
+ from pathlib import Path
14
+
15
+ from secret_paste import RENDERERS, Site
16
+
17
+
18
+ def main(argv: list[str] | None = None) -> int:
19
+ parser = argparse.ArgumentParser(prog="secret-paste", description=__doc__)
20
+ parser.add_argument("what", choices=sorted(RENDERERS))
21
+ parser.add_argument("site", type=Path, help="TOML file with the site's fields")
22
+ parser.add_argument("-o", "--out", type=Path, required=True)
23
+ parser.add_argument("--check", action="store_true", help="compare, do not write")
24
+ args = parser.parse_args(argv)
25
+
26
+ site = Site.from_mapping(tomllib.loads(args.site.read_text(encoding="utf-8")))
27
+ text = RENDERERS[args.what](site)
28
+ if args.check:
29
+ current = args.out.read_text(encoding="utf-8") if args.out.exists() else None
30
+ if current != text:
31
+ print(
32
+ f"{args.out} is stale: re-render with `secret-paste {args.what} {args.site} -o {args.out}`",
33
+ file=sys.stderr,
34
+ )
35
+ return 1
36
+ return 0
37
+ args.out.parent.mkdir(parents=True, exist_ok=True)
38
+ args.out.write_text(text, encoding="utf-8")
39
+ return 0
40
+
41
+
42
+ if __name__ == "__main__":
43
+ sys.exit(main())
@@ -0,0 +1,454 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Share a secret — how it works</title>
7
+ <meta name="description" content="A secret paste where the server stores only ciphertext and the key lives in the link's #fragment. How it works, a live demo, and what it cannot protect.">
8
+ <meta name="theme-color" content="#0f766e">
9
+ <meta property="og:type" content="website">
10
+ <meta property="og:title" content="Share a secret — how it works">
11
+ <meta property="og:description" content="The server holds a locked box. The key never reaches it. A visual explanation, a live demo, and an honest threat model.">
12
+ {{social_card_html}}
13
+ <style>
14
+ :root {
15
+ --bg: #f6f8f7; --surface: #ffffff; --ink: #14201e; --muted: #50625f; --line: #d5dfdc;
16
+ --teal: #0f766e; --teal-soft: #d9f0ec; --amber: #b45309; --amber-soft: #fdf0d2; --gold: #f2b01e;
17
+ --red: #b42318; --red-soft: #fde8e6; --green: #17713b; --green-soft: #def5e6;
18
+ --slate: #475569; --slate-soft: #e6eaee; --code: #0b1f1c; --code-ink: #cfeee8;
19
+ --radius: 14px; --btn-ink: #ffffff;
20
+ }
21
+ @media (prefers-color-scheme: dark) {
22
+ :root:not([data-theme="light"]) {
23
+ --bg: #0c1413; --surface: #121c1b; --ink: #e6f0ee; --muted: #9db3af; --line: #26403c;
24
+ --teal: #3dc2b3; --teal-soft: #12302c; --amber: #f5b25a; --amber-soft: #33270f; --gold: #f2b01e;
25
+ --red: #ff8a7e; --red-soft: #3a1714; --green: #6fd694; --green-soft: #12301f;
26
+ --slate: #a9b8c8; --slate-soft: #1b2733; --code: #070d0c; --code-ink: #bfe9e1; --btn-ink: #04201c;
27
+ }
28
+ }
29
+ :root[data-theme="dark"] {
30
+ --bg: #0c1413; --surface: #121c1b; --ink: #e6f0ee; --muted: #9db3af; --line: #26403c;
31
+ --teal: #3dc2b3; --teal-soft: #12302c; --amber: #f5b25a; --amber-soft: #33270f; --gold: #f2b01e;
32
+ --red: #ff8a7e; --red-soft: #3a1714; --green: #6fd694; --green-soft: #12301f;
33
+ --slate: #a9b8c8; --slate-soft: #1b2733; --code: #070d0c; --code-ink: #bfe9e1; --btn-ink: #04201c;
34
+ }
35
+ * { box-sizing: border-box; }
36
+ [hidden] { display: none !important; }
37
+ html { scroll-behavior: smooth; }
38
+ body {
39
+ margin: 0; background: var(--bg); color: var(--ink);
40
+ font: 17px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
41
+ -webkit-text-size-adjust: 100%;
42
+ }
43
+ main { max-width: 860px; margin: 0 auto; padding: 0 16px 64px; }
44
+ a { color: var(--teal); text-underline-offset: 3px; }
45
+ h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
46
+ h2 { font-size: 1.55rem; margin-top: 0; }
47
+ h3 { font-size: 1.1rem; }
48
+ p { margin: 0 0 1em; }
49
+ code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
50
+ section { margin-top: 56px; }
51
+ .kicker { text-transform: uppercase; letter-spacing: .09em; font-size: .78rem; font-weight: 700; color: var(--teal); margin-bottom: 6px; }
52
+ .lede { color: var(--muted); font-size: 1.08rem; max-width: 62ch; }
53
+ .btn {
54
+ display: inline-flex; align-items: center; justify-content: center; gap: 8px;
55
+ min-height: 48px; padding: 0 22px; border-radius: 999px; border: 1px solid var(--teal);
56
+ background: var(--teal); color: var(--btn-ink); font: inherit; font-weight: 650; text-decoration: none; cursor: pointer;
57
+ }
58
+ .btn.ghost { background: transparent; color: var(--teal); }
59
+ .btn.small { min-height: 44px; padding: 0 16px; }
60
+ .btn:focus-visible, button:focus-visible, a:focus-visible, textarea:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
61
+ .card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
62
+
63
+ /* hero */
64
+ .hero { padding: 44px 0 8px; }
65
+ .hero h1 { font-size: clamp(2rem, 6.2vw, 3.1rem); letter-spacing: -.02em; }
66
+ .hero h1 em { font-style: normal; color: var(--teal); }
67
+ .cta { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 22px; }
68
+ .premise {
69
+ margin-top: 26px; background: var(--amber-soft); border: 1px solid color-mix(in srgb, var(--amber) 35%, transparent);
70
+ border-radius: var(--radius); padding: 14px 18px; font-size: .98rem;
71
+ }
72
+ .premise strong { color: var(--amber); }
73
+
74
+ /* diagram */
75
+ .stage { padding: 12px; }
76
+ .stage svg { display: block; width: 100%; height: auto; max-width: 640px; margin: 0 auto; }
77
+ .stage .item { transition: transform .9s cubic-bezier(.6,.05,.25,1), opacity .5s ease; }
78
+ @media (prefers-reduced-motion: reduce) { .stage .item { transition: none; } }
79
+ .band-sender, .band-recip { fill: var(--teal-soft); stroke: var(--teal); }
80
+ .band-server { fill: var(--slate-soft); stroke: var(--slate); }
81
+ .band-label { font: 700 15px system-ui, sans-serif; letter-spacing: .06em; fill: var(--muted); }
82
+ .svg-ink { fill: var(--ink); } .svg-muted { fill: var(--muted); }
83
+ .lane { stroke: var(--amber); stroke-width: 3; stroke-dasharray: 3 9; stroke-linecap: round; fill: none; }
84
+ .lane-label { font: 600 15px system-ui, sans-serif; fill: var(--amber); }
85
+ .srv-say { font: 600 17px system-ui, sans-serif; fill: var(--ink); }
86
+ .controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; margin: 10px 0 4px; }
87
+ .dots { display: flex; gap: 2px; }
88
+ .dot { width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: none; cursor: pointer; padding: 0; }
89
+ .dot i { width: 14px; height: 14px; border-radius: 50%; background: var(--line); display: block; transition: background .2s, transform .2s; }
90
+ .dot[aria-current="step"] i { background: var(--teal); transform: scale(1.35); }
91
+ .caption { min-height: 6.4em; text-align: center; max-width: 54ch; margin: 6px auto 0; }
92
+ .caption b { display: block; font-size: 1.15rem; margin-bottom: 2px; }
93
+
94
+ /* demo */
95
+ textarea {
96
+ width: 100%; min-height: 84px; resize: vertical; padding: 12px 14px; font: inherit; font-size: 16px;
97
+ background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 10px;
98
+ }
99
+ .row { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }
100
+ .out { display: grid; gap: 14px; margin-top: 8px; }
101
+ .tag { font-size: .74rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; margin-bottom: 4px; }
102
+ .tag.server { color: var(--slate); } .tag.link { color: var(--amber); } .tag.result { color: var(--teal); }
103
+ pre.blob {
104
+ margin: 0; padding: 12px 14px; background: var(--code); color: var(--code-ink); border-radius: 10px;
105
+ overflow-wrap: anywhere; white-space: pre-wrap; word-break: break-all; font-size: .85rem; line-height: 1.5;
106
+ }
107
+ pre.blob .k { color: #f2b01e; } pre.blob .id { color: #8fd3ff; } pre.blob .dim { color: #7c9a95; }
108
+ .verdict { padding: 12px 14px; border-radius: 10px; font-weight: 600; }
109
+ .verdict.ok { background: var(--green-soft); color: var(--green); }
110
+ .verdict.bad { background: var(--red-soft); color: var(--red); }
111
+ .fine { color: var(--muted); font-size: .9rem; }
112
+
113
+ /* url anatomy */
114
+ .url { font-size: clamp(.82rem, 3.2vw, 1.15rem); word-break: break-all; line-height: 1.9; padding: 18px; background: var(--code); color: #cfeee8; border-radius: var(--radius); }
115
+ .url .a { color: #9fb6b1; } .url .i { color: #8fd3ff; border-bottom: 2px solid #8fd3ff; }
116
+ .url .h { color: #f2b01e; } .url .kk { color: #f2b01e; background: rgba(242,176,30,.14); border-bottom: 2px solid #f2b01e; padding: 0 2px; }
117
+ .legend { display: grid; gap: 10px; margin-top: 14px; }
118
+ .legend div { display: grid; grid-template-columns: 14px 1fr; gap: 10px; align-items: start; }
119
+ .legend i { width: 14px; height: 14px; border-radius: 4px; margin-top: 6px; }
120
+
121
+ /* sees vs holds */
122
+ .three { display: grid; gap: 14px; }
123
+ @media (min-width: 720px) { .three { grid-template-columns: repeat(3, 1fr); } }
124
+ .three .card h3 { display: flex; gap: 8px; align-items: center; }
125
+ .three ul { margin: 0; padding-left: 1.1em; } .three li { margin-bottom: .35em; }
126
+ .three .server { border-top: 5px solid var(--slate); } .three .link { border-top: 5px solid var(--amber); } .three .both { border-top: 5px solid var(--teal); }
127
+
128
+ /* threat model */
129
+ .threats { display: grid; gap: 12px; }
130
+ .threat { display: grid; grid-template-columns: 44px 1fr; gap: 12px; padding: 16px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); }
131
+ .threat .ic { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-weight: 800; font-size: 1.2rem; }
132
+ .threat.ok .ic { background: var(--green-soft); color: var(--green); }
133
+ .threat.part .ic { background: var(--amber-soft); color: var(--amber); }
134
+ .threat.no .ic { background: var(--red-soft); color: var(--red); }
135
+ .threat h3 { margin: 0 0 2px; font-size: 1.02rem; } .threat p { margin: 0; color: var(--muted); font-size: .96rem; }
136
+ .threat .verdict-tag { font-size: .72rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; margin-bottom: 2px; }
137
+ .threat.ok .verdict-tag { color: var(--green); } .threat.part .verdict-tag { color: var(--amber); } .threat.no .verdict-tag { color: var(--red); }
138
+ .limits { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
139
+ .limits span { background: var(--slate-soft); color: var(--ink); padding: 6px 12px; border-radius: 999px; font-size: .9rem; }
140
+ .honest { border-left: 5px solid var(--red); }
141
+
142
+ /* links */
143
+ .links { display: grid; gap: 10px; padding: 0; list-style: none; margin: 0; }
144
+ @media (min-width: 720px) { .links { grid-template-columns: 1fr 1fr; } }
145
+ .links li a { display: block; padding: 12px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); text-decoration: none; min-height: 44px; }
146
+ .links li a b { display: block; color: var(--ink); } .links li a span { color: var(--muted); font-size: .9rem; }
147
+ .links li a:hover { border-color: var(--teal); }
148
+ footer { margin-top: 56px; color: var(--muted); font-size: .92rem; border-top: 1px solid var(--line); padding-top: 18px; }
149
+ </style>
150
+ </head>
151
+ <body>
152
+ <main>
153
+
154
+ <header class="hero">
155
+ <div class="kicker">{{kicker}}</div>
156
+ <h1>The server holds a locked box.<br><em>The key never reaches it.</em></h1>
157
+ <p class="lede">Need to send a password, an API token or a recovery code? Don't put it in a chat that lives forever. Paste it here: your browser locks it, the server stores the locked box, and only the link you share can open it — once.</p>
158
+ <div class="cta">
159
+ <a class="btn primary" href="{{paste_url}}">Share a secret →</a>
160
+ <a class="btn ghost" href="#how">See how it works</a>
161
+ <a class="btn ghost" href="#threats">What it can't protect</a>
162
+ </div>
163
+ <p class="premise"><strong>Is nothing stored?</strong> Not quite, and it matters. The server <em>does</em> store something: the <b>ciphertext</b>, until it expires or is opened once. It just can't read it. That is why <em>reading</em> can be open to anyone — and why the real risks are abuse and a tampered page, not a database leak. Both are covered below.</p>
164
+ </header>
165
+
166
+ <section id="how" aria-labelledby="how-h">
167
+ <div class="kicker">The idea in six steps</div>
168
+ <h2 id="how-h">Watch a secret travel</h2>
169
+ <div class="card stage">
170
+ <svg id="flow" viewBox="0 0 640 640" role="img" aria-labelledby="flow-t flow-d">
171
+ <title id="flow-t">How a secret travels</title>
172
+ <desc id="flow-d">The sender's browser encrypts the secret and sends only the locked box to the server. The key travels separately in the link. The recipient's browser fetches the box and unlocks it locally.</desc>
173
+ <!-- bands -->
174
+ <rect class="band-sender" x="20" y="20" width="600" height="170" rx="16" stroke-width="2"/>
175
+ <text class="band-label" x="40" y="48">SENDER'S BROWSER</text>
176
+ <rect class="band-server" x="20" y="235" width="480" height="170" rx="16" stroke-width="2"/>
177
+ <text class="band-label" x="40" y="263">THE SERVER</text>
178
+ <rect class="band-recip" x="20" y="450" width="600" height="170" rx="16" stroke-width="2"/>
179
+ <text class="band-label" x="40" y="478">RECIPIENT'S BROWSER</text>
180
+ <!-- the link lane -->
181
+ <path class="lane" d="M560 190 V450"/>
182
+ <text class="lane-label" transform="translate(590 320) rotate(90)" text-anchor="middle">the link, via chat or email</text>
183
+ <!-- what the server says -->
184
+ <text id="srv" class="srv-say" x="212" y="318">Waiting…</text>
185
+ <text id="srv2" class="svg-muted" font-size="14" x="212" y="344"></text>
186
+
187
+ <!-- items; positions are set by script -->
188
+ <g id="note" class="item">
189
+ <rect x="-72" y="-34" width="144" height="68" rx="8" fill="#fde68a" stroke="#b45309" stroke-width="2"/>
190
+ <text x="0" y="-10" text-anchor="middle" font-family="ui-monospace,Menlo,monospace" font-size="18" font-weight="700" fill="#4a2a05">hunter2</text>
191
+ <text x="0" y="10" text-anchor="middle" font-size="12" fill="#7a4a10">the secret,</text>
192
+ <text x="0" y="25" text-anchor="middle" font-size="12" fill="#7a4a10">in plain words</text>
193
+ </g>
194
+ <g id="box" class="item">
195
+ <rect x="-70" y="-38" width="140" height="76" rx="12" fill="#0f766e" stroke="#064e48" stroke-width="2"/>
196
+ <text x="0" y="-12" text-anchor="middle" font-family="ui-monospace,Menlo,monospace" font-size="15" fill="#a7f3e8">x9Fq·2Lm0·Zr8…</text>
197
+ <g transform="translate(0 14)"><rect x="-13" y="-4" width="26" height="20" rx="4" fill="#fbbf24"/><path d="M-8 -4 V-9 a8 8 0 0 1 16 0 V-4" fill="none" stroke="#f1f5f9" stroke-width="3.5" stroke-linecap="round"/></g>
198
+ </g>
199
+ <g id="key" class="item">
200
+ <rect x="-62" y="-24" width="124" height="48" rx="24" fill="#fff7e0" stroke="#f2b01e" stroke-width="3"/>
201
+ <g transform="translate(-40 0)"><circle r="9" fill="none" stroke="#b45309" stroke-width="4"/><path d="M9 0 H30 M22 0 V8 M29 0 V6" stroke="#b45309" stroke-width="4" fill="none" stroke-linecap="round"/></g>
202
+ <text x="22" y="5" font-family="ui-monospace,Menlo,monospace" font-size="15" font-weight="700" fill="#7a4a10" text-anchor="middle">#key</text>
203
+ </g>
204
+ <text id="keynote" class="svg-muted" font-size="14" x="330" y="168" text-anchor="middle"></text>
205
+ </svg>
206
+ <div class="controls" role="group" aria-label="Diagram steps">
207
+ <button class="btn ghost small" id="prev" type="button">← Back</button>
208
+ <div class="dots" id="dots"></div>
209
+ <button class="btn small" id="next" type="button">Next →</button>
210
+ <button class="btn ghost small" id="play" type="button" aria-pressed="false">▶ Play</button>
211
+ </div>
212
+ <div class="caption" id="caption" aria-live="polite"></div>
213
+ </div>
214
+ </section>
215
+
216
+ <section id="demo" aria-labelledby="demo-h">
217
+ <div class="kicker">Try it, for real</div>
218
+ <h2 id="demo-h">Lock something in this page</h2>
219
+ <p class="lede">This uses your browser's built-in encryption (Web Crypto, AES-256-GCM) right here. Nothing you type is sent anywhere — open your browser's network tab to check.</p>
220
+ <div class="card">
221
+ <label for="demo-text"><b>A pretend secret</b></label>
222
+ <textarea id="demo-text" spellcheck="false">The wifi password is correct-horse-battery-staple</textarea>
223
+ <div class="row">
224
+ <button class="btn small" id="demo-lock" type="button">Lock it</button>
225
+ <button class="btn ghost small" id="demo-right" type="button" disabled>Open with the link's key</button>
226
+ <button class="btn ghost small" id="demo-wrong" type="button" disabled>Try a wrong key</button>
227
+ </div>
228
+ <div class="out" id="demo-out" hidden>
229
+ <div><div class="tag server">The server would receive</div><pre class="blob" id="demo-server"></pre></div>
230
+ <div><div class="tag link">The link would be</div><pre class="blob" id="demo-link"></pre></div>
231
+ <div id="demo-result" hidden><div class="tag result">Result</div><div class="verdict" id="demo-verdict"></div></div>
232
+ </div>
233
+ <p class="fine" id="demo-nosupport" hidden>This browser has no Web Crypto here (it needs https). The real service won't work in it either.</p>
234
+ <p class="fine">Simplified: PrivateBin also compresses the text and derives the working key through PBKDF2 (100,000 rounds), and can add an optional password. The shape is the same.</p>
235
+ </div>
236
+ </section>
237
+
238
+ <section aria-labelledby="url-h">
239
+ <div class="kicker">Why the key can't leak to the server</div>
240
+ <h2 id="url-h">The two halves of a link</h2>
241
+ <p class="lede">A link has a part your browser sends and a part it keeps. The part after <code>#</code> — the <em>fragment</em> — is never put in the HTTP request. That is the whole trick.</p>
242
+ <div class="url mono" aria-label="Example secret link"><span class="a">{{paste_url}}</span><span class="a">?</span><span class="i">8f3a1c9d2b7e4a60</span><span class="h">#</span><span class="kk">5ZkQ3vNfT9xLmB2cR7aYwE4pHs8dGuJ6tKn1VeXq</span></div>
243
+ <div class="legend">
244
+ <div><i style="background:#9fb6b1"></i><span><b>Address</b> — goes to the server, as it must for the page to load.</span></div>
245
+ <div><i style="background:#8fd3ff"></i><span><b>Paste id</b> — goes to the server. It's the name of the locked box on its shelf. Useless without the key.</span></div>
246
+ <div><i style="background:#f2b01e"></i><span><b>Key after <code>#</code></b> — stays in the browser. It is read by the page's JavaScript to unlock the box, and never travels.</span></div>
247
+ </div>
248
+ <h3 style="margin-top:22px">What the server literally receives when you open that link</h3>
249
+ <div class="url mono" style="font-size:.92rem;line-height:1.6">GET {{paste_path}}?<span class="i">8f3a1c9d2b7e4a60</span> HTTP/2<br>Host: {{paste_host}}<br><span class="a">(no key anywhere in the request)</span></div>
250
+ <p class="fine" style="margin-top:12px">This is specified in <a href="https://www.rfc-editor.org/rfc/rfc3986#section-3.5">RFC 3986 §3.5</a> and described on <a href="https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Fragment">MDN</a>. Browsers do not send the fragment in requests or in the <code>Referer</code> header, so it doesn't reach server logs either.</p>
251
+ </section>
252
+
253
+ <section aria-labelledby="see-h">
254
+ <div class="kicker">Who knows what</div>
255
+ <h2 id="see-h">What the server sees, and what the link holds</h2>
256
+ <div class="three">
257
+ <div class="card server"><h3>The server sees</h3><ul>
258
+ <li>That a paste exists, and its id</li>
259
+ <li>The ciphertext (random-looking bytes)</li>
260
+ <li>Roughly how big it is</li>
261
+ <li>When it was made, and when it's read</li>
262
+ <li>The IP address of whoever connects (the paste service keeps no request log)</li></ul></div>
263
+ <div class="card link"><h3>The link holds</h3><ul>
264
+ <li>The paste id (which box)</li>
265
+ <li>The key after <code>#</code> (how to open it)</li>
266
+ <li>Nothing else: no words, no username</li></ul>
267
+ <p class="fine" style="margin-top:10px">Anyone with the <em>whole</em> link can read the secret. Treat the link as the secret.</p></div>
268
+ <div class="card both"><h3>Half is useless</h3><ul>
269
+ <li>Server without the key: a box it can't open</li>
270
+ <li>Key without the box: nothing to open</li>
271
+ <li>Optional password: a second lock, shared another way</li></ul></div>
272
+ </div>
273
+ </section>
274
+
275
+ <section id="threats" aria-labelledby="threat-h">
276
+ <div class="kicker">Threat model</div>
277
+ <h2 id="threat-h">What it protects, and what it can't</h2>
278
+ <div class="threats">
279
+ <div class="threat ok"><div class="ic">✓</div><div><div class="verdict-tag">Protected</div><h3>The server's disk, backups or database leak</h3><p>An attacker gets locked boxes and no keys. AES-256-GCM is also tamper-evident: a changed box simply fails to open.</p></div></div>
280
+ <div class="threat ok"><div class="ic">✓</div><div><div class="verdict-tag">Protected</div><h3>Web-server and proxy logs</h3><p>They contain the paste id, never the key, because the fragment is never sent.</p></div></div>
281
+ <div class="threat ok"><div class="ic">✓</div><div><div class="verdict-tag">Protected</div><h3>{{operator_title}}</h3><p>{{operator_can_see}}</p></div></div>
282
+ <div class="threat part"><div class="ic">~</div><div><div class="verdict-tag">Partly</div><h3>The link being intercepted in transit</h3><p>Whoever sees the whole link can open it. Burn-after-reading, on by default, turns that into <em>detection</em>: if you open it and it's gone, someone else did. Send the optional password through a different channel for a real second factor.</p></div></div>
283
+ <div class="threat part"><div class="ic">~</div><div><div class="verdict-tag">Partly</div><h3>Chat apps that preview links</h3><p>Preview bots fetch URLs. A burn-after-reading paste asks “Yes, see it” first, so a bot can't burn it — and the bot never gets the key anyway.</p></div></div>
284
+ <div class="threat part"><div class="ic">~</div><div><div class="verdict-tag">Exposed</div><h3>Metadata</h3><p>When a paste was created, its size, and the IP addresses that connected are visible to the server. The content is not.</p></div></div>
285
+ <div class="threat no honest"><div class="ic">✕</div><div><div class="verdict-tag">Not protected — read this one</div><h3>A compromised server serving malicious JavaScript</h3><p>The code that encrypts is delivered by the same server, every visit. An attacker who controls the server could ship a page that copies your secret <em>before</em> it is encrypted. “Zero-knowledge” holds only while the server is honest about the page it serves. What reduces the risk here: the stock, unmodified PrivateBin image, pinned by digest so it can't change on its own; a strict Content-Security-Policy; a read-only container with no extra privileges. What it can't remove: you are trusting this server to serve the right page. For secrets whose loss would be severe, use software you install and verify yourself (Signal, <code>age</code>, GPG).</p></div></div>
286
+ <div class="threat part"><div class="ic">+</div><div><div class="verdict-tag">Narrowed, not removed</div><h3>Injected script and tampered files: CSP and SRI</h3><p>Both are left at PrivateBin's strict defaults, with no relaxations (the page template that adds the “How this works” link adds no script and no style). The <b>Content-Security-Policy</b> allows scripts only from the page's own origin: no inline script, and no <code>eval</code> (the one exception is WebAssembly compilation, which the page's compression needs). It also forbids framing and form posts, so an injected snippet in an attacker's markup can't run. It does <em>not</em> stop script that is already part of the page from sending data elsewhere, because the page may connect to any address. <b>Subresource Integrity</b> pins a hash for every script file, so a file swapped or corrupted in transit or in a cache is refused by the browser. Neither helps if the server itself serves a new page with new hashes, which is the card above.</p></div></div>
287
+ <div class="threat no"><div class="ic">✕</div><div><div class="verdict-tag">Not protected</div><h3>Your device, or the recipient's</h3><p>Malware, a shoulder-surfer, or a screenshot defeats any encryption in transit.</p></div></div>
288
+ </div>
289
+ <h3 style="margin-top:26px">Who can create, who can read</h3>
290
+ <p><b>Opening a link needs no account</b>, so a recipient never has to sign up. <b>Creating a paste needs {{signin_phrase}}</b>: the site's edge checks your session before it lets any write reach the service. That closes the main abuse door, since an open pastebin is free storage for anyone. It does not change what the server can read, which is still nothing. Anyone without a sign-in who wants to send you a secret can't use this; ask for a link instead.</p>
291
+ <p>The service is also bounded, as a second line:</p>
292
+ <div class="limits"><span>256 KB per paste</span><span>text only, no uploads</span><span>expires within 1 week (default 1 day)</span><span>1 paste per 30 s per network address</span><span>burn after reading by default</span></div>
293
+ </section>
294
+
295
+ <section aria-labelledby="habits-h">
296
+ <div class="kicker">Using it well</div>
297
+ <h2 id="habits-h">Four habits</h2>
298
+ <div class="three" style="grid-template-columns:1fr">
299
+ <div class="card"><b>1. Keep burn-after-reading on.</b> A secret read once is a secret that can't be read twice by someone else.</div>
300
+ <div class="card"><b>2. Shortest expiry that works.</b> An unopened paste you forgot about is a liability; let it expire in an hour or a day.</div>
301
+ <div class="card"><b>3. Use the password for anything serious.</b> Send the link in one channel and the password in another.</div>
302
+ <div class="card"><b>4. Rotate what you shared.</b> A shared password is only as private as the recipient's device. Change it after.</div>
303
+ </div>
304
+ <div class="cta"><a class="btn primary" href="{{paste_url}}">Share a secret →</a></div>
305
+ </section>
306
+
307
+ <section aria-labelledby="more-h">
308
+ <div class="kicker">Go deeper</div>
309
+ <h2 id="more-h">Read the primary sources</h2>
310
+ <ul class="links">
311
+ <li><a href="https://privatebin.info/"><b>PrivateBin</b><span>The project behind this service</span></a></li>
312
+ <li><a href="https://github.com/PrivateBin/PrivateBin"><b>PrivateBin on GitHub</b><span>Source code, releases, issues</span></a></li>
313
+ <li><a href="https://github.com/PrivateBin/PrivateBin/wiki/FAQ"><b>PrivateBin FAQ</b><span>Security model and common questions</span></a></li>
314
+ <li><a href="https://github.com/PrivateBin/PrivateBin/wiki"><b>PrivateBin wiki</b><span>Configuration, hardening, operation</span></a></li>
315
+ <li><a href="https://privatebin.info/reports/zerobin-audit.html"><b>The 2014 ZeroBin security audit</b><span>An independent audit of PrivateBin's ancestor, and what was fixed after it</span></a></li>
316
+ <li><a href="https://privatebin.info/category/reports.html"><b>PrivateBin's published vulnerability reports</b><span>Past issues, disclosed openly</span></a></li>
317
+ <li><a href="https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Fragment"><b>MDN: the URL fragment</b><span>Why the part after # stays in the browser</span></a></li>
318
+ <li><a href="https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/encrypt"><b>MDN: Web Crypto, AES-GCM</b><span>The encryption primitive in your browser</span></a></li>
319
+ <li><a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API"><b>MDN: Web Crypto API</b><span>The whole API, and when it is available</span></a></li>
320
+ <li><a href="https://www.rfc-editor.org/rfc/rfc3986#section-3.5"><b>RFC 3986 §3.5: Fragment</b><span>The specification</span></a></li>
321
+ <li><a href="https://cheatsheetseries.owasp.org/cheatsheets/Cryptographic_Storage_Cheat_Sheet.html"><b>OWASP: Cryptographic Storage</b><span>Cheat sheet on how to encrypt stored data</span></a></li>
322
+ <li><a href="https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html"><b>OWASP: Secrets Management</b><span>Where secrets should and shouldn't live</span></a></li>
323
+ </ul>
324
+ <p class="fine" style="margin-top:14px">{{we_looked}} for a recent independent audit of current PrivateBin and did not find one; the links above are what is public. Judge accordingly.</p>
325
+ </section>
326
+
327
+ <footer>
328
+ <p>Run by {{operator}} on {{site}}. The service is the official PrivateBin container image (pinned by digest), unmodified except for one page template that adds the “How this works” link to its page (it wraps PrivateBin's own page and changes nothing else), {{address_clause}}listening only on the server's loopback behind the site's HTTPS edge. This page loads nothing from other sites. <a href="{{paste_url}}">Share a secret →</a></p>
329
+ </footer>
330
+ </main>
331
+
332
+ <script>
333
+ (function () {
334
+ "use strict";
335
+ var reduce = window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
336
+
337
+ /* ---------- the flow diagram: one table of where each item is at each step ---------- */
338
+ var HIDE = { o: 0 };
339
+ var STEPS = [
340
+ { t: "Your secret, in plain words", d: "You type it into the page. So far it exists only in your browser.",
341
+ note: { x: 120, y: 125, o: 1 }, box: { x: 120, y: 125, o: 0 }, key: { x: 330, y: 125, o: 0 },
342
+ srv: "Waiting…", srv2: "", kn: "" },
343
+ { t: "Your browser makes a random key", d: "256 random bits, made on your device just now. Nobody else has ever seen this key.",
344
+ note: { x: 120, y: 125, o: 1 }, box: { x: 120, y: 125, o: 0 }, key: { x: 330, y: 125, o: 1 },
345
+ srv: "Waiting…", srv2: "", kn: "" },
346
+ { t: "It locks the secret with that key", d: "AES-256-GCM scrambles the words into a locked box. Without the key it is noise; with a single changed bit it won't open at all.",
347
+ note: { x: 120, y: 125, o: 0 }, box: { x: 120, y: 125, o: 1 }, key: { x: 330, y: 125, o: 1 },
348
+ srv: "Waiting…", srv2: "", kn: "" },
349
+ { t: "Only the locked box is sent to the server", d: "The key is not in the request. The server shelves the box under a random id and has no way to open it.",
350
+ note: { x: 120, y: 125, o: 0 }, box: { x: 120, y: 320, o: 1 }, key: { x: 330, y: 125, o: 1 },
351
+ srv: "I'm holding a locked box.", srv2: "I can't open it: no key.", kn: "" },
352
+ { t: "The key rides in the link, by a different road", d: "You share the link with the person: address + paste id + #key. The key goes by chat or email, never through this server.",
353
+ note: { x: 120, y: 125, o: 0 }, box: { x: 120, y: 320, o: 1 }, key: { x: 535, y: 150, o: 1 },
354
+ srv: "Still just a locked box.", srv2: "No key. Ever.", kn: "" },
355
+ { t: "They open the link: the box comes down, the server forgets it", d: "Their browser asks for the box by its id. The server hands it over and, because it's burn-after-reading, deletes it.",
356
+ note: { x: 120, y: 125, o: 0 }, box: { x: 120, y: 535, o: 1 }, key: { x: 535, y: 535, o: 1 },
357
+ srv: "Handed over, and deleted.", srv2: "The shelf is empty.", kn: "" },
358
+ { t: "Their browser unlocks it, locally", d: "The page reads the key from the #fragment, opens the box on their device, and shows the words. The server never saw the key, or the words.",
359
+ note: { x: 120, y: 535, o: 1 }, box: { x: 120, y: 535, o: 0 }, key: { x: 330, y: 535, o: 1 },
360
+ srv: "I never knew what it said.", srv2: "Empty: burned after one read.", kn: "" }
361
+ ];
362
+ var ids = ["note", "box", "key"];
363
+ var els = {}; ids.forEach(function (i) { els[i] = document.getElementById(i); });
364
+ var srv = document.getElementById("srv"), srv2 = document.getElementById("srv2");
365
+ var caption = document.getElementById("caption"), dotsBox = document.getElementById("dots");
366
+ var cur = 0, timer = null, dots = [];
367
+
368
+ function place(el, p) { el.style.transform = "translate(" + p.x + "px," + p.y + "px)"; el.style.opacity = p.o; }
369
+ function show(n) {
370
+ cur = Math.max(0, Math.min(STEPS.length - 1, n));
371
+ var s = STEPS[cur];
372
+ ids.forEach(function (i) { place(els[i], s[i]); });
373
+ srv.textContent = s.srv; srv2.textContent = s.srv2;
374
+ caption.innerHTML = "";
375
+ var b = document.createElement("b"); b.textContent = (cur + 1) + ". " + s.t;
376
+ var p = document.createElement("span"); p.textContent = s.d;
377
+ caption.appendChild(b); caption.appendChild(p);
378
+ dots.forEach(function (d, i) { if (i === cur) d.setAttribute("aria-current", "step"); else d.removeAttribute("aria-current"); });
379
+ document.getElementById("prev").disabled = cur === 0;
380
+ document.getElementById("next").disabled = cur === STEPS.length - 1;
381
+ }
382
+ STEPS.forEach(function (_, i) {
383
+ var d = document.createElement("button");
384
+ d.type = "button"; d.className = "dot"; d.setAttribute("aria-label", "Step " + (i + 1));
385
+ d.innerHTML = "<i></i>"; d.addEventListener("click", function () { stop(); show(i); });
386
+ dotsBox.appendChild(d); dots.push(d);
387
+ });
388
+ var playBtn = document.getElementById("play");
389
+ function stop() { if (timer) { clearInterval(timer); timer = null; } playBtn.textContent = "▶ Play"; playBtn.setAttribute("aria-pressed", "false"); }
390
+ function start() {
391
+ if (cur === STEPS.length - 1) show(0);
392
+ playBtn.textContent = "❚❚ Pause"; playBtn.setAttribute("aria-pressed", "true");
393
+ timer = setInterval(function () { if (cur >= STEPS.length - 1) stop(); else show(cur + 1); }, 3600);
394
+ }
395
+ playBtn.addEventListener("click", function () { timer ? stop() : start(); });
396
+ document.getElementById("prev").addEventListener("click", function () { stop(); show(cur - 1); });
397
+ document.getElementById("next").addEventListener("click", function () { stop(); show(cur + 1); });
398
+ show(0);
399
+ // Play once when the diagram first scrolls into view (never with reduced motion).
400
+ if (!reduce && "IntersectionObserver" in window) {
401
+ var io = new IntersectionObserver(function (entries) {
402
+ if (entries[0].isIntersecting) { io.disconnect(); if (cur === 0) start(); }
403
+ }, { threshold: 0.6 });
404
+ io.observe(document.getElementById("flow"));
405
+ }
406
+
407
+ /* ---------- the live demo: real AES-256-GCM, entirely in this tab ---------- */
408
+ var subtle = window.crypto && window.crypto.subtle;
409
+ var lockBtn = document.getElementById("demo-lock"), rightBtn = document.getElementById("demo-right"), wrongBtn = document.getElementById("demo-wrong");
410
+ if (!subtle) { document.getElementById("demo-nosupport").hidden = false; lockBtn.disabled = true; }
411
+ function b64u(buf) {
412
+ var s = ""; new Uint8Array(buf).forEach(function (c) { s += String.fromCharCode(c); });
413
+ return btoa(s).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
414
+ }
415
+ function esc(t) { return t.replace(/[&<>]/g, function (c) { return { "&": "&amp;", "<": "&lt;", ">": "&gt;" }[c]; }); }
416
+ var state = null;
417
+ function verdict(ok, text) {
418
+ document.getElementById("demo-result").hidden = false;
419
+ var v = document.getElementById("demo-verdict"); v.className = "verdict " + (ok ? "ok" : "bad"); v.textContent = text;
420
+ }
421
+ lockBtn.addEventListener("click", async function () {
422
+ var text = document.getElementById("demo-text").value || " ";
423
+ var key = await subtle.generateKey({ name: "AES-GCM", length: 256 }, true, ["encrypt", "decrypt"]);
424
+ var iv = crypto.getRandomValues(new Uint8Array(12));
425
+ var ct = await subtle.encrypt({ name: "AES-GCM", iv: iv }, key, new TextEncoder().encode(text));
426
+ var raw = await subtle.exportKey("raw", key);
427
+ var pasteId = b64u(crypto.getRandomValues(new Uint8Array(8)));
428
+ state = { key: key, iv: iv, ct: ct, text: text };
429
+ document.getElementById("demo-out").hidden = false;
430
+ document.getElementById("demo-result").hidden = true;
431
+ document.getElementById("demo-server").innerHTML =
432
+ '<span class="dim">id </span>' + esc(pasteId) + '\n<span class="dim">iv </span>' + esc(b64u(iv)) + '\n<span class="dim">box </span>' + esc(b64u(ct)) +
433
+ '\n\n<span class="dim">(no key. no words.)</span>';
434
+ document.getElementById("demo-link").innerHTML =
435
+ esc({{paste_url_js}}) + '?<span class="id">' + esc(pasteId) + '</span><span class="k">#' + esc(b64u(raw)) + '</span>';
436
+ rightBtn.disabled = false; wrongBtn.disabled = false;
437
+ });
438
+ rightBtn.addEventListener("click", async function () {
439
+ if (!state) return;
440
+ try {
441
+ var pt = await subtle.decrypt({ name: "AES-GCM", iv: state.iv }, state.key, state.ct);
442
+ verdict(true, "Opened with the key from the link: “" + new TextDecoder().decode(pt) + "”");
443
+ } catch (e) { verdict(false, "Could not open it."); }
444
+ });
445
+ wrongBtn.addEventListener("click", async function () {
446
+ if (!state) return;
447
+ var other = await subtle.generateKey({ name: "AES-GCM", length: 256 }, false, ["decrypt"]);
448
+ try { await subtle.decrypt({ name: "AES-GCM", iv: state.iv }, other, state.ct); verdict(true, "Unexpectedly opened."); }
449
+ catch (e) { verdict(false, "Wrong key: the box refuses to open and reveals nothing. This is all the server could ever do with it."); }
450
+ });
451
+ })();
452
+ </script>
453
+ </body>
454
+ </html>
@@ -0,0 +1,34 @@
1
+ <?php
2
+ /*
3
+ * A PrivateBin template that is upstream's bootstrap5 template plus one link near the top:
4
+ * "How this works", to the explainer page. Rendered by secret_paste; do not edit the copy
5
+ * a platform installs, edit secret_paste/data/secretpaste.php and re-render.
6
+ *
7
+ * Install it read-only next to upstream's template (/srv/tpl/secretpaste.php in the
8
+ * privatebin/nginx-fpm-alpine image) and set `template = "secretpaste"` in conf.php.
9
+ * It includes upstream's file and inserts the link after the first anchor below, so an
10
+ * image bump keeps upstream's page as it is. If upstream renames the anchor, the page
11
+ * is served unchanged, without the link: check for id="secretpaste-howto" on the live page
12
+ * after every image bump (the platforms' end-to-end scripts do). If upstream's file itself
13
+ * is gone, `require` fails the page loudly rather than serving an empty one.
14
+ *
15
+ * The link is on the create page only (no query string), never on a page showing a paste:
16
+ * a recipient of a burn-after-reading paste who tapped it before copying the secret would
17
+ * navigate away from the only copy. A new tab is no way out, since PrivateBin's CSP sandbox
18
+ * has no allow-popups. Upstream's footer link stays on every page, as before.
19
+ *
20
+ * Bootstrap classes only: PrivateBin's CSP allows no inline style or script.
21
+ */
22
+ ob_start();
23
+ require __DIR__ . '/bootstrap5.php';
24
+ $secretPastePage = (string) ob_get_clean();
25
+ $secretPasteAnchor = '<section class="container-fluid mt-2">';
26
+ $secretPasteLink = '<p id="secretpaste-howto" class="alert alert-secondary py-2 mb-2">'
27
+ . '<a class="alert-link" href="{{explainer_url}}">How this works, and what it cannot protect &rarr;</a>'
28
+ . '</p>';
29
+ $secretPasteAt = ($_SERVER['QUERY_STRING'] ?? '') === ''
30
+ ? strpos($secretPastePage, $secretPasteAnchor)
31
+ : false;
32
+ echo $secretPasteAt === false
33
+ ? $secretPastePage
34
+ : substr_replace($secretPastePage, $secretPasteAnchor . $secretPasteLink, $secretPasteAt, strlen($secretPasteAnchor));
@@ -0,0 +1,59 @@
1
+ Metadata-Version: 2.5
2
+ Name: secret_paste
3
+ Version: 0.0.4
4
+ Summary: The explainer and the paste-page link around a self-hosted, zero-knowledge secret paste (PrivateBin), rendered per site from one source
5
+ Project-URL: Homepage, https://github.com/thorwhalen/secret_paste
6
+ Project-URL: Repository, https://github.com/thorwhalen/secret_paste
7
+ Author: Thor Whalen
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: encryption,explainer,pastebin,privatebin,secrets,zero-knowledge
11
+ Requires-Python: >=3.11
12
+ Provides-Extra: dev
13
+ Requires-Dist: pytest>=7; extra == 'dev'
14
+ Description-Content-Type: text/markdown
15
+
16
+ # secret_paste
17
+
18
+ The pages around a self-hosted, zero-knowledge secret paste ([PrivateBin](https://privatebin.info/)), rendered per site from one source.
19
+
20
+ ```bash
21
+ secret-paste explainer site.toml -o frontend/index.html
22
+ secret-paste privatebin-template site.toml -o server/secretpaste.php
23
+ ```
24
+
25
+ `site.toml` holds what differs between sites:
26
+
27
+ ```toml
28
+ operator = "Ada Lovelace"
29
+ site = "example.org"
30
+ paste_url = "https://secrets.apps.example.org/" # where PrivateBin answers; its own host is best
31
+ explainer_url = "https://apps.example.org/secrets/" # where the explainer is served
32
+ voice = "I" # "we" for a team
33
+ signin_phrase = "a sign-in" # "Creating a paste needs <this>"
34
+ brand = "" # optional prefix in the page's kicker
35
+ og_image = "" # optional social-card image URL
36
+ ```
37
+
38
+ ## What you get
39
+
40
+ - **The explainer** (`explainer`): one self-contained HTML page, no external loads. How the key stays in the link's `#fragment` and never reaches the server, an animated walk-through, a live in-page demo with the browser's Web Crypto, an honest threat model (a compromised server defeats it), and what the service stores and for how long.
41
+ - **The paste-page link** (`privatebin-template`): a PrivateBin template that includes upstream's `bootstrap5.php` unchanged and adds one "How this works" link near the top of the page. Mount it read-only at `/srv/tpl/secretpaste.php` in the official `privatebin/nginx-fpm-alpine` image and set `template = "secretpaste"` in `conf.php`. No fork: an image bump keeps upstream's page; if upstream ever renames the anchor, the page is served without the link rather than broken.
42
+
43
+ ## Keeping copies current
44
+
45
+ A platform that commits the rendered files can check them in its tests:
46
+
47
+ ```bash
48
+ secret-paste explainer site.toml -o frontend/index.html --check # exit 1 when stale
49
+ ```
50
+
51
+ or from Python:
52
+
53
+ ```python
54
+ from secret_paste import Site, render_explainer
55
+
56
+ assert Path("frontend/index.html").read_text() == render_explainer(
57
+ Site.from_mapping(tomllib.load(f))
58
+ )
59
+ ```
@@ -0,0 +1,9 @@
1
+ secret_paste/__init__.py,sha256=12EbGbG6xjvKCB3ygUgcXeEIjNhKUXIVlOLvsq5YIX0,6727
2
+ secret_paste/__main__.py,sha256=4GG5iOt5sX9Ty4H7ReEU4zkCIqq1ZX2o4bFK4h9Dts0,1572
3
+ secret_paste/data/explainer.html,sha256=jAQxsbXzaYiaEUFRf9lz5g1jutTXrsMPl-FhPLzPtUg,35398
4
+ secret_paste/data/secretpaste.php,sha256=tM3r037P_Hjv-EiyoAcypSOThi4DAuTJ3MvAcbIt5Fs,1987
5
+ secret_paste-0.0.4.dist-info/METADATA,sha256=I3UbUiY4BRZFLQVN3U8pISG0D2gukz6g1hjDbsDUrao,2742
6
+ secret_paste-0.0.4.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
7
+ secret_paste-0.0.4.dist-info/entry_points.txt,sha256=eQfEXtakyn3OMI6CdtyKV57ur7q8lUJ0lYJlYZaoync,60
8
+ secret_paste-0.0.4.dist-info/licenses/LICENSE,sha256=ekE13yCE9fWWEJfP1NPnUJabZ_Wwrc6coKJV2ZZx27w,1068
9
+ secret_paste-0.0.4.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ secret-paste = secret_paste.__main__:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Thor Whalen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.