aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason McCormick <jason@mfamily.org>2026-10-16 17:43:03 -0400
committerJason McCormick <jason@mfamily.org>2026-10-16 17:43:03 -0400
commit67383e6863fcff8b49e680b5b861b3154f8cb518 (patch)
treed5c09bf85857783eb7a50dfff6cb47e80bd88118
parent7edb33c87cb1d3ad3421a6fb33247dc871828d7a (diff)
prod 1
-rw-r--r--Makefile34
-rw-r--r--README.md9
-rw-r--r--deploy/blind-uploader.service5
-rw-r--r--deploy/nginx-blind-uploader.conf6
-rw-r--r--pyproject.toml2
-rw-r--r--server.py90
-rw-r--r--static/app.js34
-rw-r--r--static/index.html61
-rw-r--r--static/styles.css231
-rw-r--r--tests/test_server.py74
10 files changed, 384 insertions, 162 deletions
diff --git a/Makefile b/Makefile
index 411a519..436587b 100644
--- a/Makefile
+++ b/Makefile
@@ -2,9 +2,10 @@ SHELL := /bin/sh
APP_DIR := /opt/blind-uploader
SYSTEMD_UNIT := /etc/systemd/system/blind-uploader.service
-NGINX_CONFIG := /etc/nginx/conf.d/blind-uploader.conf
TARGETS_FILE := /etc/blind-uploader/allowed-uris
+UPLOAD_STATE_DIR := /var/lib/blind-uploader/uploads
DOMAIN ?= upload.example.com
+NGINX_CONFIG := /etc/nginx/sites-available/$(DOMAIN)
.PHONY: help check prerequisites install
@@ -18,24 +19,31 @@ check:
prerequisites:
@test "$$(id -u)" -eq 0 || { echo "Run installation as root: sudo make install DOMAIN=upload.example.com" >&2; exit 1; }
- @for command in python3 install systemctl nginx sed; do \
+ @for command in python3 install systemctl nginx sed id chown chmod; do \
command -v "$$command" >/dev/null 2>&1 || { echo "Required command not found: $$command" >&2; exit 1; }; \
done
+ @id -u www-data >/dev/null 2>&1 || { echo "Required service account not found: www-data" >&2; exit 1; }
install: prerequisites
- install -d -m 0755 $(APP_DIR) $(APP_DIR)/static
- install -m 0755 server.py $(APP_DIR)/server.py
- install -m 0644 README.md $(APP_DIR)/README.md
- install -m 0644 static/index.html static/styles.css static/app.js $(APP_DIR)/static/
- install -d -m 0755 $$(dirname $(TARGETS_FILE))
- @test -e $(TARGETS_FILE) || install -m 0644 allowed-uris.txt $(TARGETS_FILE)
- install -m 0644 deploy/blind-uploader.service $(SYSTEMD_UNIT)
- install -d -m 0755 $$(dirname $(NGINX_CONFIG))
- sed 's/upload\.example\.com/$(DOMAIN)/g' deploy/nginx-blind-uploader.conf > $(NGINX_CONFIG)
- chmod 0644 $(NGINX_CONFIG)
+ install -d -o root -g root -m 0755 $(APP_DIR) $(APP_DIR)/static
+ install -o root -g root -m 0755 server.py $(APP_DIR)/server.py
+ install -o root -g root -m 0644 README.md $(APP_DIR)/README.md
+ install -o root -g root -m 0644 static/index.html static/styles.css static/app.js $(APP_DIR)/static/
+ install -d -o root -g www-data -m 0750 $$(dirname $(TARGETS_FILE))
+ @test -e $(TARGETS_FILE) || install -o root -g www-data -m 0640 allowed-uris.txt $(TARGETS_FILE)
+ chown root:www-data $(TARGETS_FILE)
+ chmod 0640 $(TARGETS_FILE)
+ install -d -o www-data -g www-data -m 0700 /var/lib/blind-uploader $(UPLOAD_STATE_DIR)
+ install -o root -g root -m 0644 deploy/blind-uploader.service $(SYSTEMD_UNIT)
+ @if test ! -e $(NGINX_CONFIG); then \
+ sed 's/upload\.example\.com/$(DOMAIN)/g' deploy/nginx-blind-uploader.conf > $(NGINX_CONFIG); \
+ chown root:root $(NGINX_CONFIG); \
+ chmod 0644 $(NGINX_CONFIG); \
+ fi
nginx -t
systemctl daemon-reload
- systemctl enable --now blind-uploader.service
+ systemctl enable blind-uploader.service
+ systemctl restart blind-uploader.service
systemctl reload nginx
@echo "Private Drop installed for http://$(DOMAIN)"
@echo "Uploads will be stored privately under /var/lib/blind-uploader/uploads"
diff --git a/README.md b/README.md
index 8df418c..47bdfc7 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# Private Drop
-A small, dependency-free web application for anonymous single-image submissions. It accepts JPG, PNG, and HEIC files up to 10 MiB, verifies the file signature, replaces the original filename, and stores the image outside the HTTP-served directory.
+A small, dependency-free web application for private single-image submissions. It collects the submitter's amateur radio callsign, name, email address, and a brief file description. It accepts JPG, PNG, and HEIC files up to 10 MiB, verifies the file signature, replaces the original filename, and stores the image outside the HTTP-served directory. The submission details are stored in a UTF-8 `.txt` sidecar with the same private basename as the image.
Upload forms are available only at named, single-segment targets listed in `allowed-uris.txt`, such as `/logo-contest` or `/911u19jasdl`. Blank lines and lines beginning with `#` are ignored. The bare `/` path is rejected with HTTP 418. Each target stores its submissions in a separate private directory beneath the configured upload directory.
@@ -20,7 +20,7 @@ For production, choose a private directory on a persistent disk and bind to the
UPLOAD_DIR=/var/lib/blind-uploader/uploads HOST=0.0.0.0 PORT=8000 python3 server.py
```
-The service creates the upload directory with mode `0700` and each image with mode `0600`. The process user needs write access to `UPLOAD_DIR`.
+The service runs as `www-data:www-data`. The installer makes the upload directory private to that account with mode `0700`; each stored image and metadata sidecar is created with mode `0600`.
## Test
@@ -46,7 +46,8 @@ To install the application, systemd unit, and nginx configuration in one step, r
sudo make install DOMAIN=upload.example.com
```
-This validates the nginx configuration before starting the service and reloading nginx. It requires Python 3, systemd, nginx, `make`, and standard Unix installation tools to already be installed. The generated nginx configuration is `/etc/nginx/conf.d/blind-uploader.conf`. The URI allowlist is installed at `/etc/blind-uploader/allowed-uris`; subsequent installs preserve that file so local URI changes are not overwritten.
+This validates the nginx configuration before starting the service and reloading nginx. It requires Python 3, systemd, nginx, `make`, Debian's `www-data` account, and standard Unix installation tools to already be installed. For `DOMAIN=upload.example.com`, the generated nginx configuration is `/etc/nginx/sites-available/upload.example.com`. Subsequent installs preserve both that nginx configuration and the URI allowlist at `/etc/blind-uploader/allowed-uris`, so local changes are not overwritten.
+Re-running the installer restarts the service so updated server code takes effect.
To run the test suite without installing anything:
@@ -63,7 +64,7 @@ sudo systemctl enable --now blind-uploader.service
sudo systemctl status blind-uploader.service
```
-The unit uses systemd's `DynamicUser` and `StateDirectory` features, so no permanent application user or manual data-directory setup is needed. Optional overrides can be placed in Debian's standard `/etc/default/blind-uploader` environment file, for example:
+The unit runs as Debian's existing `www-data:www-data` account and uses systemd's `StateDirectory` feature for private writable storage. Application files remain root-owned and read-only to the daemon. The URI allowlist is root-owned, group-readable by `www-data`, and otherwise private. Optional overrides can be placed in Debian's standard `/etc/default/blind-uploader` environment file, for example:
```ini
PORT=8080
diff --git a/deploy/blind-uploader.service b/deploy/blind-uploader.service
index 1258131..8bbba05 100644
--- a/deploy/blind-uploader.service
+++ b/deploy/blind-uploader.service
@@ -1,11 +1,12 @@
[Unit]
-Description=Private Drop anonymous image uploader
+Description=Private Drop image uploader
Documentation=file:/opt/blind-uploader/README.md
After=network.target
[Service]
Type=simple
-DynamicUser=yes
+User=www-data
+Group=www-data
WorkingDirectory=/opt/blind-uploader
ExecStart=/usr/bin/python3 /opt/blind-uploader/server.py
Restart=on-failure
diff --git a/deploy/nginx-blind-uploader.conf b/deploy/nginx-blind-uploader.conf
index 0473434..79f7bc7 100644
--- a/deploy/nginx-blind-uploader.conf
+++ b/deploy/nginx-blind-uploader.conf
@@ -1,7 +1,9 @@
# Replace upload.example.com and add your TLS configuration before production use.
server {
- listen 80;
- listen [::]:80;
+ listen 443 ssl;
+ listen [::]:443 ssl;
+ http2 on;
+
server_name upload.example.com;
# Allows a 10 MiB image plus multipart form overhead.
diff --git a/pyproject.toml b/pyproject.toml
index b3ca2d0..50a39c5 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,7 +1,7 @@
[project]
name = "blind-uploader"
version = "0.1.0"
-description = "A private, anonymous single-image upload service"
+description = "A private single-image upload service"
requires-python = ">=3.11"
[tool.pytest.ini_options]
diff --git a/server.py b/server.py
index 34169f9..b6b2e20 100644
--- a/server.py
+++ b/server.py
@@ -19,6 +19,10 @@ from urllib.parse import unquote, urlsplit
MAX_FILE_BYTES = 10 * 1024 * 1024
MAX_REQUEST_BYTES = MAX_FILE_BYTES + 1024 * 1024
+MAX_CALLSIGN_LENGTH = 32
+MAX_NAME_LENGTH = 200
+MAX_EMAIL_LENGTH = 254
+MAX_DESCRIPTION_LENGTH = 1000
STATIC_DIR = Path(__file__).resolve().parent / "static"
DEFAULT_TARGETS_FILE = Path(__file__).resolve().parent / "allowed-uris.txt"
STATIC_FILES = {
@@ -67,8 +71,8 @@ def detect_image_type(data: bytes) -> tuple[str, str] | None:
return None
-def parse_single_upload(content_type: str, body: bytes) -> tuple[str, bytes]:
- """Parse one multipart field named image and reject ambiguous requests."""
+def parse_single_upload(content_type: str, body: bytes) -> tuple[str, bytes, dict[str, str]]:
+ """Parse one image and its required metadata from a multipart request."""
if not content_type.lower().startswith("multipart/form-data;"):
raise ValueError("Expected a multipart form upload.")
@@ -79,16 +83,59 @@ def parse_single_upload(content_type: str, body: bytes) -> tuple[str, bytes]:
raise ValueError("The upload form is malformed.")
file_parts = []
+ text_parts: dict[str, list[object]] = {}
for part in message.iter_parts():
if part.get_content_disposition() != "form-data":
continue
+ field_name = part.get_param("name", header="content-disposition")
filename = part.get_filename()
if filename is not None:
file_parts.append(part)
+ elif isinstance(field_name, str):
+ text_parts.setdefault(field_name, []).append(part)
if len(file_parts) != 1 or file_parts[0].get_param("name", header="content-disposition") != "image":
raise ValueError("Submit exactly one image.")
+ expected_fields = {"callsign", "name", "email", "description"}
+ if set(text_parts) != expected_fields or any(len(parts) != 1 for parts in text_parts.values()):
+ raise ValueError("Submit callsign, name, email address, and file description exactly once.")
+
+ metadata: dict[str, str] = {}
+ for field_name, parts in text_parts.items():
+ part = parts[0]
+ raw_value = part.get_payload(decode=True)
+ if raw_value is None:
+ raise ValueError(f"The {field_name} field is malformed.")
+ try:
+ value = raw_value.decode(part.get_content_charset() or "utf-8")
+ except (LookupError, UnicodeDecodeError) as error:
+ raise ValueError(f"The {field_name} field must contain valid text.") from error
+ metadata[field_name] = value.strip()
+
+ if not metadata["callsign"]:
+ raise ValueError("Enter an amateur radio callsign.")
+ if not metadata["name"]:
+ raise ValueError("Enter your name.")
+ if not metadata["email"]:
+ raise ValueError("Enter your email address.")
+ if not metadata["description"]:
+ raise ValueError("Enter a brief description of the file.")
+ if len(metadata["callsign"]) > MAX_CALLSIGN_LENGTH:
+ raise ValueError(f"The callsign must be {MAX_CALLSIGN_LENGTH} characters or fewer.")
+ if len(metadata["name"]) > MAX_NAME_LENGTH:
+ raise ValueError(f"The name must be {MAX_NAME_LENGTH} characters or fewer.")
+ if len(metadata["email"]) > MAX_EMAIL_LENGTH:
+ raise ValueError(f"The email address must be {MAX_EMAIL_LENGTH} characters or fewer.")
+ if len(metadata["description"]) > MAX_DESCRIPTION_LENGTH:
+ raise ValueError(f"The file description must be {MAX_DESCRIPTION_LENGTH} characters or fewer.")
+ if any(character in metadata[field] for field in ("callsign", "name", "email") for character in "\r\n\x00"):
+ raise ValueError("Callsign, name, and email address must each fit on one line.")
+ if "\x00" in metadata["description"]:
+ raise ValueError("The file description contains an invalid character.")
+ if "@" not in metadata["email"] or metadata["email"].startswith("@") or metadata["email"].endswith("@"):
+ raise ValueError("Enter a valid email address.")
+
part = file_parts[0]
filename = Path(part.get_filename() or "image").name
payload = part.get_payload(decode=True)
@@ -96,7 +143,18 @@ def parse_single_upload(content_type: str, body: bytes) -> tuple[str, bytes]:
raise ValueError("The selected image is empty.")
if len(payload) > MAX_FILE_BYTES:
raise OverflowError("The image must be 10 MB or smaller.")
- return filename, payload
+ return filename, payload, metadata
+
+
+def format_metadata(metadata: dict[str, str]) -> bytes:
+ """Return human-readable UTF-8 content for an upload's sidecar file."""
+ return (
+ f"Callsign: {metadata['callsign']}\n"
+ f"Name: {metadata['name']}\n"
+ f"Email: {metadata['email']}\n"
+ "Description:\n"
+ f"{metadata['description']}\n"
+ ).encode("utf-8")
class UploadHandler(BaseHTTPRequestHandler):
@@ -163,7 +221,7 @@ class UploadHandler(BaseHTTPRequestHandler):
body = self.rfile.read(content_length)
try:
- _original_name, payload = parse_single_upload(self.headers.get("Content-Type", ""), body)
+ _original_name, payload, metadata = parse_single_upload(self.headers.get("Content-Type", ""), body)
detected = detect_image_type(payload)
if detected is None:
raise TypeError("Only JPG, PNG, and HEIC images are accepted.")
@@ -174,9 +232,21 @@ class UploadHandler(BaseHTTPRequestHandler):
target_dir.mkdir(mode=0o700, exist_ok=True)
target_dir.chmod(0o700)
destination = target_dir / f"{storage_id}{extension}"
- descriptor = os.open(destination, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
- with os.fdopen(descriptor, "wb") as output:
- output.write(payload)
+ metadata_destination = target_dir / f"{storage_id}.txt"
+ created_files: list[Path] = []
+ try:
+ for path, content in ((destination, payload), (metadata_destination, format_metadata(metadata))):
+ descriptor = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
+ created_files.append(path)
+ with os.fdopen(descriptor, "wb") as output:
+ output.write(content)
+ except OSError:
+ for path in created_files:
+ try:
+ path.unlink()
+ except OSError:
+ pass
+ raise
except OverflowError as error:
self.send_error_response(HTTPStatus.REQUEST_ENTITY_TOO_LARGE, str(error))
return
@@ -184,8 +254,10 @@ class UploadHandler(BaseHTTPRequestHandler):
self.send_error_response(HTTPStatus.BAD_REQUEST, str(error))
return
except OSError:
- self.log_error("Unable to persist an uploaded image")
- self.send_error_response(HTTPStatus.INTERNAL_SERVER_ERROR, "The image could not be stored. Please try again.")
+ self.log_error("Unable to persist an uploaded submission")
+ self.send_error_response(
+ HTTPStatus.INTERNAL_SERVER_ERROR, "The submission could not be stored. Please try again."
+ )
return
self.send_json(
diff --git a/static/app.js b/static/app.js
index bb09c86..6a93a95 100644
--- a/static/app.js
+++ b/static/app.js
@@ -2,6 +2,12 @@ const MAX_BYTES = 10 * 1024 * 1024;
const ALLOWED_EXTENSIONS = /\.(jpe?g|png|heic)$/i;
const form = document.querySelector('#upload-form');
+const pageTitle = document.querySelector('#page-title');
+const notice = document.querySelector('.notice');
+const requirements = document.querySelector('.requirements');
+const metadataFields = document.querySelector('#metadata-fields');
+const description = document.querySelector('#description');
+const characterCount = document.querySelector('#character-count');
const input = document.querySelector('#image-input');
const dropZone = document.querySelector('#drop-zone');
const fileRow = document.querySelector('#file-row');
@@ -28,6 +34,27 @@ function clearSelection() {
preview.removeAttribute('src');
}
+function showCompletion(message, receipt) {
+ input.value = '';
+ input.disabled = true;
+ fileRow.hidden = true;
+ dropZone.hidden = true;
+ submitButton.hidden = true;
+ removeButton.disabled = true;
+ if (previewUrl) URL.revokeObjectURL(previewUrl);
+ previewUrl = null;
+ preview.removeAttribute('src');
+ pageTitle.textContent = 'Upload complete';
+ notice.textContent = 'Your image was submitted for private review.';
+ requirements.hidden = true;
+ metadataFields.hidden = true;
+ setStatus(`${message} Receipt: ${receipt}`, 'success');
+}
+
+description.addEventListener('input', () => {
+ characterCount.textContent = `${description.value.length} / 1000 characters`;
+});
+
function validate(file) {
if (!file) return 'Choose an image to continue.';
if (!ALLOWED_EXTENSIONS.test(file.name)) return 'Choose a JPG, PNG, or HEIC image.';
@@ -86,19 +113,18 @@ form.addEventListener('submit', async (event) => {
const file = input.files[0];
const error = validate(file);
if (error) { setStatus(error, 'error'); return; }
+ if (!form.reportValidity()) return;
submitButton.disabled = true;
submitButton.querySelector('span').textContent = 'Submitting…';
setStatus('Securely sending your image…');
- const body = new FormData();
- body.append('image', file);
+ const body = new FormData(form);
try {
const response = await fetch(window.location.pathname, { method: 'POST', body });
const result = await response.json();
if (!response.ok) throw new Error(result.message || 'Upload failed.');
- clearSelection();
- setStatus(`${result.message} Receipt: ${result.receipt}`, 'success');
+ showCompletion(result.message, result.receipt);
} catch (error) {
submitButton.disabled = false;
setStatus(error.message || 'Upload failed. Please try again.', 'error');
diff --git a/static/index.html b/static/index.html
index 3100128..779e688 100644
--- a/static/index.html
+++ b/static/index.html
@@ -4,42 +4,38 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Submit one image privately for review.">
- <title>Private Drop</title>
+ <title>Blind Uploader</title>
<link rel="stylesheet" href="/styles.css">
</head>
<body>
- <main class="shell">
- <header class="masthead">
- <a class="brand" href="/" aria-label="Private Drop home">
- <span class="brand-mark" aria-hidden="true"></span>
- Private Drop
- </a>
- <span class="privacy-label"><span aria-hidden="true">●</span> Private intake</span>
- </header>
+ <main class="page">
+ <section class="upload-box" aria-labelledby="page-title">
+ <h1 id="page-title">Blind Uploader</h1>
+ <p class="notice">Submit one image for private review. The file will be renamed, stored outside the public website, and will not be available through a public link.</p>
+ <p class="requirements">Accepted formats: JPG, PNG, or HEIC. Maximum size: 10 MB.</p>
- <section class="intro" aria-labelledby="page-title">
- <p class="eyebrow">Secure image submission</p>
- <h1 id="page-title">Send one image.<br><em>Nothing more.</em></h1>
- <p class="lede">Your image is delivered directly to our private review queue. It is never published or made available through a public link.</p>
- </section>
+ <form id="upload-form">
+ <fieldset class="metadata-fields" id="metadata-fields">
+ <legend>Submission details</legend>
- <section class="upload-card" aria-labelledby="upload-title">
- <div class="card-heading">
- <div>
- <p class="step">01 / Upload</p>
- <h2 id="upload-title">Choose your image</h2>
- </div>
- <p class="formats">JPG · PNG · HEIC<br>10 MB maximum</p>
- </div>
+ <label for="callsign">Amateur radio callsign</label>
+ <input id="callsign" name="callsign" type="text" maxlength="32" autocomplete="off" required>
+
+ <label for="submitter-name">Name</label>
+ <input id="submitter-name" name="name" type="text" maxlength="200" autocomplete="name" required>
+
+ <label for="email">Email address</label>
+ <input id="email" name="email" type="email" maxlength="254" autocomplete="email" required>
+
+ <label for="description">A brief description of the file</label>
+ <textarea id="description" name="description" maxlength="1000" rows="5" required></textarea>
+ <span class="character-count" id="character-count">0 / 1000 characters</span>
+ </fieldset>
- <form id="upload-form" novalidate>
<input id="image-input" name="image" type="file" accept=".jpg,.jpeg,.png,.heic,image/jpeg,image/png,image/heic,image/heif" required>
<label class="drop-zone" for="image-input" id="drop-zone">
- <span class="upload-icon" aria-hidden="true">
- <svg viewBox="0 0 24 24" role="img"><path d="M12 16V4m0 0L7.5 8.5M12 4l4.5 4.5M5 14.5V19h14v-4.5"/></svg>
- </span>
- <span class="drop-title">Drop an image here</span>
- <span class="drop-copy">or <u>browse your device</u></span>
+ <span class="drop-title">Choose an image</span>
+ <span class="drop-copy">or drag and drop it here</span>
</label>
<div class="file-row" id="file-row" hidden>
@@ -53,17 +49,10 @@
<p class="status" id="status" role="status" aria-live="polite"></p>
<button class="submit-button" type="submit" id="submit-button" disabled>
- <span>Submit image</span><span aria-hidden="true">↗</span>
+ <span>Submit image</span>
</button>
</form>
</section>
-
- <aside class="privacy-note">
- <span class="lock" aria-hidden="true">⌁</span>
- <div><strong>Private by design</strong><p>Files are renamed on arrival, stored outside the public website, and available only to the review team.</p></div>
- </aside>
-
- <footer><span>Private Drop</span><span>Confidential image intake</span></footer>
</main>
<script src="/app.js" defer></script>
</body>
diff --git a/static/styles.css b/static/styles.css
index b59e7a3..4a1ffd1 100644
--- a/static/styles.css
+++ b/static/styles.css
@@ -1,120 +1,187 @@
:root {
- --ink: #191815;
- --paper: #f3efe6;
- --card: #fbf8f1;
- --accent: #ddff4f;
- --muted: #756f64;
- --line: #d5cfc2;
- --error: #a63b2b;
- --success: #336440;
+ --background: #f4f4f4;
+ --surface: #ffffff;
+ --text: #202124;
+ --muted: #62666b;
+ --border: #c9ccd1;
+ --primary: #1f5fa9;
+ --primary-hover: #174d8a;
+ --error: #a12622;
+ --success: #23723a;
}
* { box-sizing: border-box; }
+[hidden] { display: none !important; }
+
body {
margin: 0;
min-width: 320px;
- color: var(--ink);
- background:
- radial-gradient(circle at 84% 12%, rgba(221, 255, 79, .22), transparent 23rem),
- var(--paper);
+ min-height: 100vh;
+ color: var(--text);
+ background: var(--background);
font-family: Arial, Helvetica, sans-serif;
+}
+
+button, input, textarea { font: inherit; }
+
+.page {
min-height: 100vh;
+ display: grid;
+ place-items: center;
+ padding: 24px;
}
-body::before {
- content: "";
- position: fixed;
- inset: 0;
- pointer-events: none;
- opacity: .24;
- background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.14'/%3E%3C/svg%3E");
+.upload-box {
+ width: min(100%, 560px);
+ padding: 32px;
+ background: var(--surface);
+ border: 1px solid var(--border);
+ border-radius: 8px;
+ box-shadow: 0 4px 18px rgba(0, 0, 0, .07);
}
-button, input { font: inherit; }
+h1 {
+ margin: 0 0 12px;
+ font-size: 1.65rem;
+ line-height: 1.2;
+}
-.shell { width: min(1120px, calc(100% - 40px)); margin: 0 auto; position: relative; }
+.notice {
+ margin: 0;
+ color: var(--text);
+ line-height: 1.5;
+}
-.masthead {
- height: 90px;
- display: flex;
- align-items: center;
- justify-content: space-between;
- border-bottom: 1px solid var(--ink);
+.requirements {
+ margin: 12px 0 24px;
+ color: var(--muted);
+ font-size: .9rem;
+ line-height: 1.4;
+}
+
+.metadata-fields {
+ display: grid;
+ gap: 8px;
+ margin: 0 0 24px;
+ padding: 0;
+ border: 0;
+}
+
+.metadata-fields legend {
+ margin-bottom: 14px;
+ padding: 0;
+ font-weight: 700;
+}
+
+.metadata-fields label { margin-top: 6px; font-weight: 700; }
+
+.metadata-fields input,
+.metadata-fields textarea {
+ width: 100%;
+ padding: 10px 12px;
+ border: 1px solid var(--border);
+ border-radius: 6px;
+ color: var(--text);
+ background: var(--surface);
}
-.brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; font-weight: 800; letter-spacing: -.03em; }
-.brand-mark { width: 19px; height: 19px; background: var(--ink); border-radius: 50% 50% 2px 50%; transform: rotate(45deg); }
-.privacy-label { font-size: .72rem; letter-spacing: .16em; text-transform: uppercase; }
-.privacy-label span { color: #83a400; margin-right: 7px; }
+.metadata-fields textarea { resize: vertical; }
-.intro { padding: 76px 0 58px; display: grid; grid-template-columns: 1.45fr .72fr; gap: 8vw; align-items: end; }
-.eyebrow, .step { text-transform: uppercase; letter-spacing: .16em; font-size: .68rem; font-weight: 800; margin: 0 0 22px; }
-h1 { font-family: Georgia, 'Times New Roman', serif; font-size: clamp(3.35rem, 7vw, 6.5rem); line-height: .86; letter-spacing: -.065em; font-weight: 400; margin: 0; }
-h1 em { color: transparent; -webkit-text-stroke: 1.5px var(--ink); font-weight: 400; }
-.lede { font-family: Georgia, 'Times New Roman', serif; font-size: 1.18rem; line-height: 1.55; margin: 0 0 3px; max-width: 29rem; }
+.metadata-fields input:focus-visible,
+.metadata-fields textarea:focus-visible {
+ border-color: var(--primary);
+ outline: 3px solid rgba(31, 95, 169, .2);
+}
-.upload-card { background: var(--card); border: 1px solid var(--ink); box-shadow: 10px 10px 0 var(--ink); padding: clamp(24px, 4vw, 50px); }
-.card-heading { display: flex; justify-content: space-between; gap: 30px; align-items: start; margin-bottom: 34px; }
-.step { margin-bottom: 8px; color: var(--muted); }
-h2 { font-family: Georgia, 'Times New Roman', serif; font-size: clamp(1.85rem, 3.5vw, 2.65rem); margin: 0; font-weight: 400; letter-spacing: -.035em; }
-.formats { margin: 0; text-align: right; font-size: .69rem; line-height: 1.55; letter-spacing: .13em; text-transform: uppercase; color: var(--muted); }
-#image-input { position: absolute; inline-size: 1px; block-size: 1px; opacity: 0; }
+.character-count {
+ justify-self: end;
+ color: var(--muted);
+ font-size: .8rem;
+}
+
+#image-input {
+ position: absolute;
+ inline-size: 1px;
+ block-size: 1px;
+ opacity: 0;
+}
.drop-zone {
- min-height: 250px;
- border: 1px dashed #928b80;
+ min-height: 160px;
+ border: 2px dashed var(--border);
+ border-radius: 6px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
+ gap: 8px;
+ padding: 24px;
text-align: center;
cursor: pointer;
- transition: background .18s, border-color .18s, transform .18s;
- background: rgba(243, 239, 230, .55);
+ transition: border-color .15s, background .15s;
+}
+
+.drop-zone:hover,
+.drop-zone.is-dragging,
+#image-input:focus-visible + .drop-zone {
+ border-color: var(--primary);
+ background: #f3f7fc;
+ outline: none;
+}
+
+.drop-title { color: var(--primary); font-weight: 700; }
+.drop-copy { color: var(--muted); font-size: .875rem; }
+
+.file-row {
+ min-height: 88px;
+ align-items: center;
+ border: 1px solid var(--border);
+ border-radius: 6px;
+ padding: 10px;
+ gap: 14px;
}
-.drop-zone:hover, .drop-zone.is-dragging, #image-input:focus-visible + .drop-zone { background: rgba(221, 255, 79, .16); border-color: var(--ink); outline: none; }
-.drop-zone.is-dragging { transform: scale(.992); }
-.upload-icon { width: 52px; height: 52px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; margin-bottom: 20px; }
-.upload-icon svg { width: 24px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: square; }
-.drop-title { font-family: Georgia, 'Times New Roman', serif; font-size: 1.55rem; margin-bottom: 8px; }
-.drop-copy { color: var(--muted); font-size: .82rem; }
-.file-row { min-height: 104px; align-items: center; border: 1px solid var(--line); padding: 12px; gap: 16px; background: white; }
.file-row:not([hidden]) { display: flex; }
-.thumb-wrap { width: 78px; height: 78px; background: #e8e3d9; overflow: hidden; flex: 0 0 auto; }
+.thumb-wrap { width: 64px; height: 64px; background: var(--background); overflow: hidden; flex: 0 0 auto; }
.thumb-wrap img { width: 100%; height: 100%; object-fit: cover; }
-.file-details { min-width: 0; display: flex; flex-direction: column; gap: 8px; flex: 1; }
+.file-details { min-width: 0; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.file-details strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
-.file-details span { font-size: .73rem; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
-.remove-button { background: transparent; border: 0; font-size: 1.8rem; cursor: pointer; width: 44px; height: 44px; }
-.status { min-height: 22px; margin: 16px 0 10px; font-size: .82rem; color: var(--muted); }
+.file-details span { color: var(--muted); font-size: .8rem; }
+.remove-button { width: 40px; height: 40px; border: 0; background: transparent; font-size: 1.6rem; cursor: pointer; }
+
+.status { min-height: 20px; margin: 14px 0 8px; color: var(--muted); font-size: .875rem; line-height: 1.4; }
.status.error { color: var(--error); }
-.status.success { color: var(--success); font-weight: 700; }
-
-.submit-button { width: 100%; min-height: 62px; padding: 0 24px; display: flex; align-items: center; justify-content: space-between; border: 1px solid var(--ink); background: var(--accent); color: var(--ink); font-weight: 800; cursor: pointer; transition: transform .15s, box-shadow .15s, background .15s; }
-.submit-button:not(:disabled):hover { transform: translate(-3px, -3px); box-shadow: 4px 4px 0 var(--ink); }
-.submit-button:disabled { background: #ded9cf; color: #8d877c; border-color: #b5afa4; cursor: not-allowed; }
-
-.privacy-note { display: grid; grid-template-columns: 42px 1fr; gap: 16px; max-width: 600px; margin: 48px auto 88px; }
-.lock { border: 1px solid var(--ink); width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; font-size: 1.3rem; }
-.privacy-note strong { font-size: .72rem; text-transform: uppercase; letter-spacing: .13em; }
-.privacy-note p { margin: 7px 0 0; font-family: Georgia, 'Times New Roman', serif; color: var(--muted); line-height: 1.45; }
-footer { border-top: 1px solid var(--ink); height: 80px; display: flex; justify-content: space-between; align-items: center; font-size: .65rem; letter-spacing: .13em; text-transform: uppercase; }
-
-@media (max-width: 720px) {
- .shell { width: min(100% - 24px, 1120px); }
- .masthead { height: 70px; }
- .privacy-label { font-size: .61rem; }
- .intro { padding: 52px 0 40px; grid-template-columns: 1fr; gap: 32px; }
- .lede { font-size: 1.05rem; max-width: 34rem; }
- .upload-card { box-shadow: 5px 5px 0 var(--ink); }
- .card-heading { display: block; }
- .formats { text-align: left; margin-top: 18px; }
- .drop-zone { min-height: 220px; }
- footer { align-items: start; flex-direction: column; justify-content: center; gap: 8px; }
+.status.success {
+ margin: 20px 0 0;
+ padding: 14px;
+ border: 1px solid #9ac4a5;
+ border-radius: 6px;
+ color: var(--success);
+ background: #f1f8f3;
+ font-weight: 700;
+}
+
+.submit-button {
+ width: 100%;
+ min-height: 46px;
+ border: 0;
+ border-radius: 6px;
+ background: var(--primary);
+ color: white;
+ font-weight: 700;
+ cursor: pointer;
+}
+
+.submit-button:not(:disabled):hover { background: var(--primary-hover); }
+.submit-button:focus-visible { outline: 3px solid rgba(31, 95, 169, .3); outline-offset: 2px; }
+.submit-button:disabled { background: #a9acb0; cursor: not-allowed; }
+
+@media (max-width: 520px) {
+ .page { padding: 12px; }
+ .upload-box { padding: 22px 18px; }
}
@media (prefers-reduced-motion: reduce) {
- * { scroll-behavior: auto !important; transition: none !important; }
+ * { transition: none !important; }
}
diff --git a/tests/test_server.py b/tests/test_server.py
index 78b9bf8..ca6d748 100644
--- a/tests/test_server.py
+++ b/tests/test_server.py
@@ -10,8 +10,26 @@ from server import MAX_FILE_BYTES, detect_image_type, load_allowed_targets, make
PNG = b"\x89PNG\r\n\x1a\n" + b"test-image"
-def multipart(filename: str, payload: bytes, boundary: str = "test-boundary") -> tuple[bytes, str]:
- body = (
+def multipart(
+ filename: str,
+ payload: bytes,
+ boundary: str = "test-boundary",
+ metadata: dict[str, str] | None = None,
+) -> tuple[bytes, str]:
+ fields = metadata if metadata is not None else {
+ "callsign": "W1AW",
+ "name": "Test Operator",
+ "email": "operator@example.com",
+ "description": "A test image.",
+ }
+ body = b"".join(
+ (
+ f"--{boundary}\r\n"
+ f'Content-Disposition: form-data; name="{name}"\r\n\r\n'
+ f"{value}\r\n"
+ ).encode("utf-8")
+ for name, value in fields.items()
+ ) + (
f"--{boundary}\r\n"
f'Content-Disposition: form-data; name="image"; filename="{filename}"\r\n'
"Content-Type: application/octet-stream\r\n\r\n"
@@ -52,21 +70,34 @@ class ServerTests(unittest.TestCase):
self.assertEqual(response.status, 201, data)
target_dir = self.upload_dir / "logo-contest"
files = list(target_dir.iterdir())
- self.assertEqual(len(files), 1)
- self.assertEqual(files[0].read_bytes(), PNG)
- self.assertNotIn("photo", files[0].name)
- self.assertEqual(files[0].stat().st_mode & 0o777, 0o600)
+ self.assertEqual(len(files), 2)
+ image = next(path for path in files if path.suffix == ".png")
+ metadata = next(path for path in files if path.suffix == ".txt")
+ self.assertEqual(image.read_bytes(), PNG)
+ self.assertEqual(metadata.stem, image.stem)
+ self.assertEqual(
+ metadata.read_text(encoding="utf-8"),
+ "Callsign: W1AW\nName: Test Operator\nEmail: operator@example.com\n"
+ "Description:\nA test image.\n",
+ )
+ self.assertNotIn("photo", image.name)
+ self.assertEqual(image.stat().st_mode & 0o777, 0o600)
+ self.assertEqual(metadata.stat().st_mode & 0o777, 0o600)
self.assertEqual(target_dir.stat().st_mode & 0o777, 0o700)
- hidden_response, _ = self.request("GET", f"/logo-contest/{files[0].name}")
+ hidden_response, _ = self.request("GET", f"/logo-contest/{image.name}")
+ hidden_metadata_response, _ = self.request("GET", f"/logo-contest/{metadata.name}")
self.assertEqual(hidden_response.status, 404)
+ self.assertEqual(hidden_metadata_response.status, 404)
def test_root_is_rejected_but_target_page_is_available(self):
root_response, _ = self.request("GET", "/")
target_response, page = self.request("GET", "/911u19jasdl")
self.assertEqual(root_response.status, 418)
self.assertEqual(target_response.status, 200)
- self.assertIn(b"Private Drop", page)
+ self.assertIn(b"Blind Uploader", page)
+ self.assertLess(page.index(b'name="callsign"'), page.index(b'name="image"'))
+ self.assertIn(b'name="description" maxlength="1000"', page)
def test_upload_to_root_is_rejected_as_teapot(self):
body, content_type = multipart("photo.png", PNG)
@@ -82,7 +113,7 @@ class ServerTests(unittest.TestCase):
"POST", f"/{target}", body, {"Content-Type": content_type, "Content-Length": str(len(body))}
)
self.assertEqual(response.status, 201)
- self.assertEqual(len(list((self.upload_dir / target).iterdir())), 1)
+ self.assertEqual(len(list((self.upload_dir / target).iterdir())), 2)
def test_invalid_or_nested_targets_are_rejected(self):
for path in ("/bad.target", "/nested/target", "/%2e%2e", "/healthz"):
@@ -115,6 +146,31 @@ class ServerTests(unittest.TestCase):
self.assertEqual(response.status, 400)
self.assertFalse((self.upload_dir / "logo-contest").exists())
+ def test_rejects_missing_metadata(self):
+ body, content_type = multipart("photo.png", PNG, metadata={})
+ response, _ = self.request(
+ "POST", "/logo-contest", body, {"Content-Type": content_type, "Content-Length": str(len(body))}
+ )
+ self.assertEqual(response.status, 400)
+ self.assertFalse((self.upload_dir / "logo-contest").exists())
+
+ def test_rejects_description_over_1000_characters(self):
+ body, content_type = multipart(
+ "photo.png",
+ PNG,
+ metadata={
+ "callsign": "W1AW",
+ "name": "Test Operator",
+ "email": "operator@example.com",
+ "description": "x" * 1001,
+ },
+ )
+ response, _ = self.request(
+ "POST", "/logo-contest", body, {"Content-Type": content_type, "Content-Length": str(len(body))}
+ )
+ self.assertEqual(response.status, 400)
+ self.assertFalse((self.upload_dir / "logo-contest").exists())
+
def test_rejects_oversized_request_before_reading_body(self):
response, _ = self.request(
"POST", "/logo-contest", b"", {"Content-Type": "multipart/form-data; boundary=x", "Content-Length": str(MAX_FILE_BYTES + 1024 * 1024 + 1)}