Archived
Fix CORS ordering, healthcheck, and root-level name keys
CORS middleware was registered after Vapor's error middleware, so error responses went out without CORS headers and the browser reported every rejection as an opaque "Failed to fetch" — a taken handle or a wrong passphrase became undiagnosable in the client. The container healthcheck called wget, which is not in the runtime image, so it could never pass and an orchestrator would have restarted the container forever. Root-level filenames were decrypted with the session's label key, but a root listing spans labels and each entry is named under the key of its own label. A cleared user saw rows they could not read. They now use the right key per row. Also handles empty response bodies in the accounts client: a 201 with no body is an ordinary answer and calling .json() on one throws. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
09f07e3ef9
commit
2cb84eae03
+1
-1
@@ -35,7 +35,7 @@ RUN BIN="$(swift build --package-path /build -c release --show-bin-path)" \
|
||||
FROM ubuntu:jammy
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends ca-certificates tzdata libcurl4 libxml2 \
|
||||
&& apt-get install -y --no-install-recommends ca-certificates tzdata libcurl4 libxml2 curl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Never run as root. The server needs no write access to its own image.
|
||||
|
||||
+3
-5
@@ -254,11 +254,9 @@ a { color: inherit; }
|
||||
.footer-col a { display: block; text-decoration: none; color: var(--ink-2); font-size: 15px; margin-bottom: 9px; }
|
||||
.footer-col a:hover { color: var(--brand); }
|
||||
.footer-legal { border-top: 1px solid var(--border); padding-top: 26px; color: var(--ink-3); font-size: 14px; display: flex; flex-wrap: wrap; gap: 8px 20px; }
|
||||
.hosted { margin: 22px 0 0; padding-top: 20px; border-top: 1px solid var(--border);
|
||||
text-align: center; color: var(--ink-3); font-size: 14px; }
|
||||
.hosted a { color: var(--brand); font-weight: 650; text-decoration: none; }
|
||||
.hosted a:hover { text-decoration: underline; }
|
||||
.heart { color: #e0245e; font-style: normal; }
|
||||
.footer-legal a { color: var(--brand); font-weight: 650; text-decoration: none; }
|
||||
.footer-legal a:hover { text-decoration: underline; }
|
||||
.heart { color: #e0245e; }
|
||||
|
||||
/* ---------- responsive ---------- */
|
||||
|
||||
|
||||
@@ -90,12 +90,9 @@
|
||||
<span>© 2026 Extant 2000 LLC</span>
|
||||
<span>MIT licensed</span>
|
||||
<span>Files are encrypted in your browser before upload.</span>
|
||||
<span>Proudly hosted at <a href="https://hitthosting.com">Hitt Hosting</a>,
|
||||
with <span class="heart" role="img" aria-label="love">❤</span></span>
|
||||
</div>
|
||||
|
||||
<p class="hosted">
|
||||
Proudly hosted at <a href="https://hitthosting.com">Hitt Hosting</a>,
|
||||
with <span class="heart" aria-label="love" role="img">❤</span>
|
||||
</p>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
|
||||
@@ -51,11 +51,15 @@ func configure(_ app: Application) async throws {
|
||||
.split(separator: ",").map { String($0).trimmingCharacters(in: .whitespaces) }
|
||||
.filter { !$0.isEmpty }
|
||||
if !allowed.isEmpty {
|
||||
// At the beginning, ahead of Vapor's error middleware. Registered after
|
||||
// it, error responses go out without CORS headers and the browser
|
||||
// reports every rejection as an opaque "Failed to fetch" — so a taken
|
||||
// handle or a wrong passphrase becomes undiagnosable in the client.
|
||||
app.middleware.use(CORSMiddleware(configuration: .init(
|
||||
allowedOrigin: .any(allowed),
|
||||
allowedMethods: [.GET, .POST, .OPTIONS],
|
||||
allowedHeaders: [.accept, .authorization, .contentType, .origin]
|
||||
)))
|
||||
)), at: .beginning)
|
||||
}
|
||||
|
||||
app.migrations.add(InstallAccountsSchema())
|
||||
|
||||
@@ -50,7 +50,10 @@ export class AccountsAPI {
|
||||
try { reason = (await response.json()).reason ?? reason; } catch { /* non-JSON body */ }
|
||||
throw new Error(reason);
|
||||
}
|
||||
return response.status === 204 ? null : response.json();
|
||||
// A 201 with no body is a perfectly ordinary answer here, and calling
|
||||
// .json() on one throws. Read the text first and decide.
|
||||
const text = await response.text();
|
||||
return text ? JSON.parse(text) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+22
-8
@@ -195,17 +195,31 @@ export class Session {
|
||||
const rows = await this.api.get(
|
||||
folderID ? `/api/nodes/${folderID}/children` : "/api/nodes/roots"
|
||||
);
|
||||
const key = await this.folderKey(folderID);
|
||||
|
||||
// Inside a folder, every child is named under that folder's node key,
|
||||
// which the caller necessarily holds to have got here at all.
|
||||
//
|
||||
// A root listing is different: it spans labels, and each entry was
|
||||
// named under the key of its *own* label. Using the session's label key
|
||||
// for all of them leaves a cleared user staring at rows they can see but
|
||||
// cannot read — which is worse than not showing them at all.
|
||||
const folderNodeKey = folderID ? await this.folderKey(folderID) : null;
|
||||
|
||||
return Promise.all((rows ?? []).map(async (row) => {
|
||||
const rowLabel = makeLabel(row.classification, row.compartments);
|
||||
let name;
|
||||
try {
|
||||
name = await decryptName(key, unb64(row.nameCiphertext), unb64(row.nameDigest), rowLabel);
|
||||
} catch {
|
||||
// Visible to the database but not decryptable here -- e.g. a
|
||||
// child at a label whose key this session has not loaded.
|
||||
name = null;
|
||||
const key = folderNodeKey ?? this.#labelKeys.get(labelKey(rowLabel));
|
||||
|
||||
let name = null;
|
||||
if (key) {
|
||||
try {
|
||||
name = await decryptName(
|
||||
key, unb64(row.nameCiphertext), unb64(row.nameDigest), rowLabel
|
||||
);
|
||||
} catch {
|
||||
// Visible to the database but not decryptable here — a label
|
||||
// key this session has not been granted.
|
||||
name = null;
|
||||
}
|
||||
}
|
||||
return { ...row, label: rowLabel, name };
|
||||
}));
|
||||
|
||||
@@ -6,3 +6,10 @@ services:
|
||||
db:
|
||||
ports:
|
||||
- "127.0.0.1:5432:5432"
|
||||
|
||||
# Serve templates and static assets from the working tree, so front-end
|
||||
# changes take a container restart rather than an image rebuild.
|
||||
app:
|
||||
volumes:
|
||||
- ./Public:/app/Public:ro
|
||||
- ./Resources:/app/Resources:ro
|
||||
|
||||
+1
-1
@@ -110,7 +110,7 @@ services:
|
||||
ports:
|
||||
- "${ENCLAVE_BIND:-127.0.0.1}:${ENCLAVE_PORT:-8080}:8080"
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8080/healthz || exit 1"]
|
||||
test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:8080/healthz || exit 1"]
|
||||
interval: 15s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
Reference in New Issue
Block a user