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:
+11
-30
@@ -1,11 +1,11 @@
|
||||
/**
|
||||
* Media/activity log for the Consumption widget. A view over homeData.activities;
|
||||
* see stores/posts.js for the placeholder-then-overwrite pattern.
|
||||
* Media/activity log for the Consumption widget. A view over homeData.activities,
|
||||
* built by createMirrorStore(); see stores/createMirrorStore.js for the
|
||||
* placeholder-then-overwrite pattern.
|
||||
*/
|
||||
|
||||
import { defineStore } from "pinia";
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { useHomeDataStore } from "@/stores/homeData";
|
||||
import { createMirrorStore } from "@/stores/createMirrorStore";
|
||||
|
||||
const activity_template = {
|
||||
type: "activity",
|
||||
@@ -14,33 +14,14 @@ const activity_template = {
|
||||
};
|
||||
|
||||
export const useActivityStore = defineStore("activity", () => {
|
||||
const activity = ref([activity_template]);
|
||||
|
||||
const activityCount = computed(() => activity.value.length);
|
||||
|
||||
const homeData = useHomeDataStore();
|
||||
// Mirror the shared home query. `immediate` matters: homeData may already
|
||||
// have loaded by the time this store is first used, and a plain watch would
|
||||
// never fire for that existing value. The `length > 0` test keeps the
|
||||
// placeholder on screen when the backend returns nothing.
|
||||
watch(
|
||||
() => homeData.activities,
|
||||
(newActivities) => {
|
||||
if (newActivities.length > 0) {
|
||||
activity.value = newActivities;
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
/** Refresh by re-running the whole home query; the watch above applies it. */
|
||||
async function fetchActivity() {
|
||||
await homeData.fetchAll();
|
||||
}
|
||||
const { items, count, fetch } = createMirrorStore({
|
||||
slice: "activities",
|
||||
template: activity_template,
|
||||
});
|
||||
|
||||
return {
|
||||
activity,
|
||||
activityCount,
|
||||
fetchActivity,
|
||||
activity: items,
|
||||
activityCount: count,
|
||||
fetchActivity: fetch,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Factory for the "mirror store" pattern shared by stores/posts.js,
|
||||
* favorites.js and activity.js.
|
||||
*
|
||||
* Each of those is a thin view over one slice of the shared home query
|
||||
* (stores/homeData.js): a ref seeded with placeholder content, an `immediate`
|
||||
* watch that copies the homeData slice in, a count computed and a fetch
|
||||
* function that just re-runs the whole home query.
|
||||
*
|
||||
* The state/getter/action names differ per store and components import them by
|
||||
* name, so the caller supplies them explicitly rather than having them derived.
|
||||
*/
|
||||
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { useHomeDataStore } from "@/stores/homeData";
|
||||
|
||||
/**
|
||||
* @param {object} options
|
||||
* @param {string} options.slice key on the homeData store to mirror
|
||||
* @param {*} options.template placeholder item shown before a successful fetch
|
||||
* @returns {{ items: import("vue").Ref, count: import("vue").ComputedRef, fetch: () => Promise<void>, homeData: object }}
|
||||
*/
|
||||
export function createMirrorStore({ slice, template }) {
|
||||
const items = ref([template]);
|
||||
|
||||
const count = computed(() => items.value.length);
|
||||
|
||||
const homeData = useHomeDataStore();
|
||||
// `immediate` matters: homeData may already have loaded by the time this
|
||||
// store is first used, and a plain watch would never fire for that existing
|
||||
// value. The `length > 0` test keeps the placeholder on screen when the
|
||||
// backend returns nothing.
|
||||
watch(
|
||||
() => homeData[slice],
|
||||
(newItems) => {
|
||||
if (newItems.length > 0) {
|
||||
items.value = newItems;
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
/** Refresh by re-running the whole home query; the watch above applies it. */
|
||||
async function fetch() {
|
||||
await homeData.fetchAll();
|
||||
}
|
||||
|
||||
return { items, count, fetch, homeData };
|
||||
}
|
||||
+11
-30
@@ -1,11 +1,11 @@
|
||||
/**
|
||||
* Favourites for the Favorites widget. A view over homeData.favorites; see
|
||||
* stores/posts.js for the placeholder-then-overwrite pattern.
|
||||
* Favourites for the Favorites widget. A view over homeData.favorites, built by
|
||||
* createMirrorStore(); see stores/createMirrorStore.js for the
|
||||
* placeholder-then-overwrite pattern.
|
||||
*/
|
||||
|
||||
import { defineStore } from "pinia";
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { useHomeDataStore } from "@/stores/homeData";
|
||||
import { createMirrorStore } from "@/stores/createMirrorStore";
|
||||
|
||||
const favorite_template = {
|
||||
type: "favorite",
|
||||
@@ -14,33 +14,14 @@ const favorite_template = {
|
||||
};
|
||||
|
||||
export const useFavoritesStore = defineStore("favorites", () => {
|
||||
const favorites = ref([favorite_template]);
|
||||
|
||||
const favoritesCount = computed(() => favorites.value.length);
|
||||
|
||||
const homeData = useHomeDataStore();
|
||||
// Mirror the shared home query. `immediate` matters: homeData may already
|
||||
// have loaded by the time this store is first used, and a plain watch would
|
||||
// never fire for that existing value. The `length > 0` test keeps the
|
||||
// placeholder on screen when the backend returns nothing.
|
||||
watch(
|
||||
() => homeData.favorites,
|
||||
(newFavorites) => {
|
||||
if (newFavorites.length > 0) {
|
||||
favorites.value = newFavorites;
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
/** Refresh by re-running the whole home query; the watch above applies it. */
|
||||
async function fetchFavorites() {
|
||||
await homeData.fetchAll();
|
||||
}
|
||||
const { items, count, fetch } = createMirrorStore({
|
||||
slice: "favorites",
|
||||
template: favorite_template,
|
||||
});
|
||||
|
||||
return {
|
||||
favorites,
|
||||
favoritesCount,
|
||||
fetchFavorites,
|
||||
favorites: items,
|
||||
favoritesCount: count,
|
||||
fetchFavorites: fetch,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -136,11 +136,16 @@ export const useMessagesStore = defineStore("messages", () => {
|
||||
* POST a file to the REST upload endpoint, then send its returned URL over
|
||||
* the socket as a normal message. Two steps because the socket carries JSON
|
||||
* text only. Errors surface via `lastError`.
|
||||
*
|
||||
* `private` is sent with the upload as well as with the message: the backend
|
||||
* stores private attachments under /uploads/private/, which nginx gates
|
||||
* behind an admin check.
|
||||
*/
|
||||
async function uploadAndSendFile(file, isPrivate = false) {
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
formData.append("private", isPrivate ? "true" : "false");
|
||||
const res = await axios.post("/api/messages/upload", formData);
|
||||
const { url } = res.data;
|
||||
if (!socket.value || !isConnected.value) return;
|
||||
|
||||
+12
-31
@@ -1,15 +1,15 @@
|
||||
/**
|
||||
* Blog posts for the Feed widget. A view over homeData.posts.
|
||||
* Blog posts for the Feed widget. A view over homeData.posts, built by
|
||||
* createMirrorStore(); see stores/createMirrorStore.js for the
|
||||
* placeholder-then-overwrite pattern.
|
||||
*
|
||||
* `post_template` is placeholder content rendered before (or instead of) a
|
||||
* successful fetch — the watch only overwrites `posts` when the fetch returned a
|
||||
* non-empty list, so the widget never flashes empty.
|
||||
* successful fetch, so the widget never flashes empty.
|
||||
*/
|
||||
|
||||
import { defineStore } from "pinia";
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { gql } from "@/graphql";
|
||||
import { useHomeDataStore } from "@/stores/homeData";
|
||||
import { createMirrorStore } from "@/stores/createMirrorStore";
|
||||
|
||||
const post_template = {
|
||||
title: "Can't fetch from the db yo",
|
||||
@@ -22,29 +22,10 @@ const post_template = {
|
||||
};
|
||||
|
||||
export const usePostsStore = defineStore("posts", () => {
|
||||
const posts = ref([post_template]);
|
||||
|
||||
const postsCount = computed(() => posts.value.length);
|
||||
|
||||
const homeData = useHomeDataStore();
|
||||
// Mirror the shared home query. `immediate` matters: homeData may already
|
||||
// have loaded by the time this store is first used, and a plain watch would
|
||||
// never fire for that existing value. The `length > 0` test keeps the
|
||||
// placeholder on screen when the backend returns nothing.
|
||||
watch(
|
||||
() => homeData.posts,
|
||||
(newPosts) => {
|
||||
if (newPosts.length > 0) {
|
||||
posts.value = newPosts;
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
/** Refresh by re-running the whole home query; the watch above applies it. */
|
||||
async function fetchPosts() {
|
||||
await homeData.fetchAll();
|
||||
}
|
||||
const { items, count, fetch, homeData } = createMirrorStore({
|
||||
slice: "posts",
|
||||
template: post_template,
|
||||
});
|
||||
|
||||
/** Soft-delete a post, then refetch so every widget sees the new list. */
|
||||
async function deletePost(post) {
|
||||
@@ -61,11 +42,11 @@ export const usePostsStore = defineStore("posts", () => {
|
||||
}
|
||||
|
||||
return {
|
||||
posts,
|
||||
posts: items,
|
||||
|
||||
postsCount,
|
||||
postsCount: count,
|
||||
|
||||
fetchPosts,
|
||||
fetchPosts: fetch,
|
||||
deletePost,
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user