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:
@@ -1,15 +1,11 @@
|
||||
<script setup>
|
||||
/**
|
||||
* "Consumption" widget on /stp (books/films/games logged as activities). Same
|
||||
* shape as Favorites.vue: AutoScroll list + admin-only lazy create form.
|
||||
* shape as Favorites.vue — both are ListWidget.vue with a different store.
|
||||
*/
|
||||
import AutoScroll from "@/components/util/AutoScroll.vue";
|
||||
import Modal from "@/components/util/Modal.vue";
|
||||
import LinkTable from "@/components/util/LinkTable.vue";
|
||||
import Header from "@/components/text/Header.vue";
|
||||
import CreateToggle from "@/components/input/CreateToggle.vue";
|
||||
import ListWidget from "@/views/home/ListWidget.vue";
|
||||
|
||||
import { ref, defineAsyncComponent } from "vue";
|
||||
import { defineAsyncComponent } from "vue";
|
||||
import { useActivityStore } from "@/stores/activity";
|
||||
|
||||
const CreateActivity = defineAsyncComponent(
|
||||
@@ -17,27 +13,12 @@ const CreateActivity = defineAsyncComponent(
|
||||
);
|
||||
|
||||
const activityStore = useActivityStore();
|
||||
const showCreate = ref(false);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col items-center">
|
||||
<Header>
|
||||
Consumption
|
||||
<template #action><CreateToggle v-model="showCreate" /></template>
|
||||
</Header>
|
||||
<AutoScroll class="flex-1 w-full">
|
||||
<LinkTable
|
||||
variant="table"
|
||||
class="w-full"
|
||||
:items="activityStore.activity"
|
||||
/>
|
||||
</AutoScroll>
|
||||
<Modal v-model="showCreate">
|
||||
<CreateActivity
|
||||
@done="showCreate = false"
|
||||
@cancel="showCreate = false"
|
||||
/>
|
||||
</Modal>
|
||||
</div>
|
||||
<ListWidget
|
||||
title="Consumption"
|
||||
:items="activityStore.activity"
|
||||
:create-form="CreateActivity"
|
||||
/>
|
||||
</template>
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
<script setup>
|
||||
/**
|
||||
* "Favorites" widget on /stp: a self-scrolling <AutoScroll> list, plus an
|
||||
* admin-only create form in a <Modal> (lazily imported).
|
||||
* "Favorites" widget on /stp. All of the markup lives in ListWidget.vue; this
|
||||
* file only binds the favourites store and the (lazily imported) create form.
|
||||
*/
|
||||
import Header from "@/components/text/Header.vue";
|
||||
import CreateToggle from "@/components/input/CreateToggle.vue";
|
||||
import LinkTable from "@/components/util/LinkTable.vue";
|
||||
import AutoScroll from "@/components/util/AutoScroll.vue";
|
||||
import Modal from "@/components/util/Modal.vue";
|
||||
import ListWidget from "@/views/home/ListWidget.vue";
|
||||
|
||||
import { ref, defineAsyncComponent } from "vue";
|
||||
import { defineAsyncComponent } from "vue";
|
||||
import { useFavoritesStore } from "@/stores/favorites";
|
||||
|
||||
const CreateFavorite = defineAsyncComponent(
|
||||
@@ -17,27 +13,12 @@ const CreateFavorite = defineAsyncComponent(
|
||||
);
|
||||
|
||||
const favoritesStore = useFavoritesStore();
|
||||
const showCreate = ref(false);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col items-center">
|
||||
<Header>
|
||||
favs
|
||||
<template #action><CreateToggle v-model="showCreate" /></template>
|
||||
</Header>
|
||||
<AutoScroll class="w-full flex-1">
|
||||
<LinkTable
|
||||
variant="table"
|
||||
class="w-full"
|
||||
:items="favoritesStore.favorites"
|
||||
/>
|
||||
</AutoScroll>
|
||||
<Modal v-model="showCreate">
|
||||
<CreateFavorite
|
||||
@done="showCreate = false"
|
||||
@cancel="showCreate = false"
|
||||
/>
|
||||
</Modal>
|
||||
</div>
|
||||
<ListWidget
|
||||
title="favs"
|
||||
:items="favoritesStore.favorites"
|
||||
:create-form="CreateFavorite"
|
||||
/>
|
||||
</template>
|
||||
|
||||
@@ -28,8 +28,9 @@ const leftCap = computed(() => idx.value === 0);
|
||||
const rightCap = computed(() => idx.value === postsStore.postsCount - 1);
|
||||
|
||||
const post = computed(() => postsStore.posts[idx.value]);
|
||||
// Guarded: `post` can be a placeholder or a row fetched without an author.
|
||||
const userOwnsPost = computed(
|
||||
() => post.value.author.username == authStore.user.username,
|
||||
() => post.value?.author?.username == authStore.user?.username,
|
||||
);
|
||||
|
||||
function nextPost() {
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<script setup>
|
||||
/**
|
||||
* Shared shape of the "favs" and "Consumption" widgets on /stp: a header with a
|
||||
* create toggle, a self-scrolling <AutoScroll> list rendered through
|
||||
* <LinkTable>, and an admin-only create form in a <Modal>.
|
||||
*
|
||||
* `createForm` is the component to show in the modal. The hosts pass a
|
||||
* defineAsyncComponent() so the admin form is still only fetched when a widget
|
||||
* is actually opened.
|
||||
*/
|
||||
import Header from "@/components/text/Header.vue";
|
||||
import CreateToggle from "@/components/input/CreateToggle.vue";
|
||||
import LinkTable from "@/components/util/LinkTable.vue";
|
||||
import AutoScroll from "@/components/util/AutoScroll.vue";
|
||||
import Modal from "@/components/util/Modal.vue";
|
||||
|
||||
import { ref } from "vue";
|
||||
|
||||
defineProps({
|
||||
title: { type: String, required: true },
|
||||
items: { type: Array, required: true },
|
||||
createForm: { type: [Object, Function], required: true },
|
||||
});
|
||||
|
||||
const showCreate = ref(false);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col items-center">
|
||||
<Header>
|
||||
{{ title }}
|
||||
<template #action><CreateToggle v-model="showCreate" /></template>
|
||||
</Header>
|
||||
<AutoScroll class="flex-1 w-full">
|
||||
<LinkTable variant="table" class="w-full" :items="items" />
|
||||
</AutoScroll>
|
||||
<Modal v-model="showCreate">
|
||||
<component
|
||||
:is="createForm"
|
||||
@done="showCreate = false"
|
||||
@cancel="showCreate = false"
|
||||
/>
|
||||
</Modal>
|
||||
</div>
|
||||
</template>
|
||||
@@ -2,38 +2,28 @@
|
||||
/**
|
||||
* "Listening" widget on /stp: rotates through recent Spotify plays.
|
||||
*
|
||||
* Two timers: a 5s rotation (self-rearming setTimeout, so a manual change would
|
||||
* reset the full interval) and a 2-minute re-poll of Spotify. Both are cleared on
|
||||
* unmount.
|
||||
* Two timers, both owned by useRotation(): a 5s rotation and a 2-minute re-poll
|
||||
* of Spotify.
|
||||
*/
|
||||
import Header from "@/components/text/Header.vue";
|
||||
import { ref, computed, onMounted, onUnmounted } from "vue";
|
||||
import { computed, onMounted } from "vue";
|
||||
import { useSongsStore } from "@/stores/songs";
|
||||
import { useRotation } from "@/js/useRotation";
|
||||
|
||||
const ROTATE_MS = 5000;
|
||||
const REFRESH_MS = 120000;
|
||||
|
||||
const songsStore = useSongsStore();
|
||||
const idx = ref(0);
|
||||
|
||||
const { idx, next: nextSong } = useRotation(() => songsStore.songs, ROTATE_MS, {
|
||||
refresh: () => songsStore.fetchSongs(),
|
||||
refreshMs: REFRESH_MS,
|
||||
});
|
||||
|
||||
const song = computed(() => songsStore.songs[idx.value]);
|
||||
|
||||
let nextId = null;
|
||||
let refreshId = null;
|
||||
|
||||
// Self-rearming timeout rather than setInterval, so the full 5s is restarted
|
||||
// whenever the song changes rather than leaving a short remainder.
|
||||
function nextSong() {
|
||||
clearTimeout(nextId);
|
||||
nextId = setTimeout(nextSong, 5000);
|
||||
idx.value = (idx.value + 1) % songsStore.songsCount;
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
songsStore.fetchSongs();
|
||||
nextId = setTimeout(nextSong, 5000);
|
||||
refreshId = setInterval(songsStore.fetchSongs, 120000);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
clearTimeout(nextId);
|
||||
clearInterval(refreshId);
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,43 +1,33 @@
|
||||
<script setup>
|
||||
/**
|
||||
* Steam widget on /stp: online status plus a rotation through recent games
|
||||
* (5s rotation, 5-minute re-poll). `loaded` comes from homeData so the widget can
|
||||
* tell "not fetched yet" from "fetched, nothing to show".
|
||||
* (5s rotation, 5-minute re-poll, both from useRotation()). `loaded` comes from
|
||||
* homeData so the widget can tell "not fetched yet" from "fetched, nothing to
|
||||
* show".
|
||||
*/
|
||||
import { ref, computed, onMounted, onUnmounted } from "vue";
|
||||
import { computed } from "vue";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { useSteamStore } from "@/stores/steam";
|
||||
import { useHomeDataStore } from "@/stores/homeData";
|
||||
import Header from "@/components/text/Header.vue";
|
||||
import { useRotation } from "@/js/useRotation";
|
||||
|
||||
const ROTATE_MS = 5000;
|
||||
const REFRESH_MS = 5 * 60 * 1000;
|
||||
|
||||
const steamStore = useSteamStore();
|
||||
const { steamStatus } = storeToRefs(steamStore);
|
||||
const homeData = useHomeDataStore();
|
||||
const { loaded } = storeToRefs(homeData);
|
||||
|
||||
const idx = ref(0);
|
||||
const { idx, next: nextGame } = useRotation(
|
||||
() => steamStatus.value.recentGames,
|
||||
ROTATE_MS,
|
||||
{ refresh: () => steamStore.fetchSteam(), refreshMs: REFRESH_MS },
|
||||
);
|
||||
|
||||
const game = computed(() => steamStatus.value.recentGames[idx.value]);
|
||||
|
||||
let nextId = null;
|
||||
let refreshId = null;
|
||||
|
||||
function nextGame() {
|
||||
clearTimeout(nextId);
|
||||
nextId = setTimeout(nextGame, 5000);
|
||||
if (steamStatus.value.recentGames.length) {
|
||||
idx.value = (idx.value + 1) % steamStatus.value.recentGames.length;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
nextId = setTimeout(nextGame, 5000);
|
||||
refreshId = setInterval(() => steamStore.fetchSteam(), 5 * 60 * 1000);
|
||||
});
|
||||
onUnmounted(() => {
|
||||
clearTimeout(nextId);
|
||||
clearInterval(refreshId);
|
||||
});
|
||||
|
||||
function formatHours(minutes) {
|
||||
const hrs = (minutes / 60).toFixed(1);
|
||||
return `${hrs}h`;
|
||||
|
||||
Reference in New Issue
Block a user