Fix security issues, bugs, and convoluted code across the stack
Security: - Token revocation. User gains a TokenVersion counter embedded in both tokens as a "tv" claim; AuthenticateToken rejects a token whose version no longer matches the row. Logout bumps it, so logging out now kills outstanding tokens rather than only clearing cookies. Costs one primary-key SELECT per authenticated request, which is the price of having revocation at all. - Spotify OAuth CSRF. The fixed SPOTIFY_AUTH_STATE constant is replaced by a per-request one-shot nonce, verified and consumed on callback. - Private chat attachments. Attachments on private messages are written to /backend/uploads/private/ and served at /uploads/private/, gated by the same nginx auth_request admin check used for /hasura/ and /notes/. Private uploads are rejected from non-admin callers. - The icecast admin UI (/radio/admin/) is behind the admin gate; listener traffic is untouched. - Store caches are mutex-guarded, so -race is clean. Bugs: - The email pipeline no longer drops emails permanently on transient failure. Failures record an attempt counter and are retried up to 3 times; the fetch window rewinds to the oldest retryable email's ReceivedAt, without which a retry could never re-fetch it. - Rowing duplicate detection distinguishes ErrRecordNotFound from a real DB error, so a transient failure no longer causes a duplicate insert plus a paid Claude call. - DeletePost propagates its delete error instead of reporting success. - RecentlyPlayed populates the cache it reads. - main.go exits non-zero if r.Run fails, so a port conflict is visible. - Python: the scan truncation flag is set on every deadline path; timed_out is reported by the worker rather than inferred from the clock; date validation uses Europe/London rather than server-local time. - Vue: Time.vue and Radio.vue intervals are cleared on unmount; Feed.vue guards a missing author; Timer.vue gets an explicit state machine and compares total elapsed seconds; Elle.vue's comma-operator call and per-frame console.log are fixed. Simplification: - One TTLCache replaces three near-identical cache implementations, with the differing eviction rules as explicit parameters. - run_scan's transport index no longer uses one object as both ordering record and live output; its three phases are separate functions. - _price_hotels submits all work to a single pool, so the nested-executor deadlock hazard is gone by construction. - The NDJSON event generators share one implementation. - IMAP FETCH responses pair each line with its literal in the type, so callers no longer hand-skip alternate entries. - Shared helpers for slice-of-pointers, markdown fences and auth cookies. - Vue: useHotelSearch, createMirrorStore, useRotation, useCreateForm, useLinkAttrs, ListWidget and LinkTableItems replace duplicated blocks. - nginx dev config's duplicated :80/:443 bodies share one partial. Infra: certbot passes --deploy-hook touching a sentinel that nginx's watcher reloads on, so renewed certs are served without a restart, and the watcher also removes the manual restart after first issuance. db is gated on service_healthy, autoheal is pinned, and the unused envsubst entries are dropped. Verified: go build/vet, npx vite build, py_compile, docker compose config for both overlays, bash -n on all scripts, and an envsubst render of every nginx template (no leftover placeholders, runtime vars preserved, braces balanced). Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
// The shared body of the admin "create X" forms (CreatePost, CreateFavorite,
|
||||
// CreateActivity, CreateBookmark): a ref per field, a GraphQL mutation taking a
|
||||
// single `input`, clear the fields on success, then emit "done" so the host
|
||||
// modal can close. Failures are logged and leave the fields alone, exactly as
|
||||
// the hand-written versions did.
|
||||
|
||||
import { ref } from "vue";
|
||||
import { gql } from "@/graphql";
|
||||
|
||||
/**
|
||||
* @param {object} options
|
||||
* @param {string} options.mutation GraphQL mutation with one $input variable
|
||||
* @param {string[]} options.fields input field names, one text ref each
|
||||
* @param {(event: string) => void} options.emit the component's emit
|
||||
* @param {string[]} [options.optional] fields sent as undefined when blank,
|
||||
* so the backend sees "not set" rather than an empty string
|
||||
* @param {string} [options.resultKey] mutation field to log on success
|
||||
* @returns {{ values: Record<string, import("vue").Ref<string>>, submit: () => Promise<void> }}
|
||||
*/
|
||||
export function useCreateForm({
|
||||
mutation,
|
||||
fields,
|
||||
emit,
|
||||
optional = [],
|
||||
resultKey,
|
||||
}) {
|
||||
const values = Object.fromEntries(fields.map((name) => [name, ref("")]));
|
||||
|
||||
async function submit() {
|
||||
try {
|
||||
const input = {};
|
||||
for (const name of fields) {
|
||||
const value = values[name].value;
|
||||
input[name] = optional.includes(name) ? value || undefined : value;
|
||||
}
|
||||
const data = await gql(mutation, { input });
|
||||
for (const name of fields) values[name].value = "";
|
||||
if (resultKey) console.log(data[resultKey]);
|
||||
emit("done");
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
return { values, submit };
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// Rotate through a list on a timer, as the Listening and Steam widgets do.
|
||||
//
|
||||
// A self-rearming setTimeout rather than setInterval, so clicking to advance
|
||||
// manually restarts the full delay instead of leaving whatever was left of the
|
||||
// current tick. An optional periodic refresh callback covers the "re-poll the
|
||||
// source every few minutes" half of the same pattern. Both timers are cleared
|
||||
// on unmount.
|
||||
|
||||
import { ref, unref, onMounted, onUnmounted } from "vue";
|
||||
|
||||
/**
|
||||
* @param {import("vue").Ref<Array>|(() => Array)} items the list being rotated
|
||||
* @param {number} ms delay between rotations
|
||||
* @param {object} [options]
|
||||
* @param {() => void} [options.refresh] called every refreshMs
|
||||
* @param {number} [options.refreshMs] refresh interval
|
||||
* @returns {{ idx: import("vue").Ref<number>, next: () => void }}
|
||||
*/
|
||||
export function useRotation(items, ms, { refresh, refreshMs } = {}) {
|
||||
const idx = ref(0);
|
||||
let nextId = null;
|
||||
let refreshId = null;
|
||||
|
||||
function list() {
|
||||
return (typeof items === "function" ? items() : unref(items)) ?? [];
|
||||
}
|
||||
|
||||
/** Advance one step and re-arm. Leaves the index alone on an empty list. */
|
||||
function next() {
|
||||
clearTimeout(nextId);
|
||||
nextId = setTimeout(next, ms);
|
||||
const count = list().length;
|
||||
if (count) idx.value = (idx.value + 1) % count;
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
nextId = setTimeout(next, ms);
|
||||
if (refresh && refreshMs) refreshId = setInterval(refresh, refreshMs);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
clearTimeout(nextId);
|
||||
clearInterval(refreshId);
|
||||
});
|
||||
|
||||
return { idx, next };
|
||||
}
|
||||
Reference in New Issue
Block a user