diff --git a/CLAUDE.md b/CLAUDE.md index 82d4c0f..a3e7a9d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -66,11 +66,12 @@ In dev, Vite proxies `/api` to the target set in `vite.config.ts`, so the API mu - **Imports need explicit extensions** (`.ts`, `.tsx`, `.js`) everywhere. - **Vite resolves `.js` before `.ts`**, so a `.js` and `.ts` file with the same base name will import the wrong one. Give new hooks distinct names. - **Don't use `fallback: EMPTY` in api.ts hooks.** It silently returns empty arrays and hides server errors; let the error state surface. +- **Colours are tokens, not hex.** Use the utilities from `src/index.css` (`text-ink`, `text-body`, `text-muted`, `text-link`, `bg-surface`, `bg-tint`, `bg-action`, `border-brand/20`...) so dark mode works; a literal only for something that must look the same in both modes (white on a dark band, a platform's colour). Data colours (accents, event and region colours) go through `withAlpha`, `accentText` and `readableOn` in `src/lib/color.ts`, never `${color}55`. - **No em-dashes** (U+2014) anywhere: UI text, help text, comments, docs, commit messages. Use a colon, comma or parentheses. An empty table cell shows `-`. - **Admin editor text:** blank select options read `Default: …` (what blank means), examples in help text start with `eg.`, and record ids are called "URL ID". Cut-off preview text uses `preview()` from `src/lib/text.ts`, which ends it with an ellipsis. See `docs/updating-data-in-code.md`. ## Admin CRUD engine -Descriptor-driven: `server/src/admin-crud.js` and `server/src/admin-schema.js` (server) and `adminSchema.ts` (client) generate SQL and form fields from declarative entity configs. Adding an entity should mean adding a descriptor, not new CRUD code. +Descriptor-driven: `server/src/admin-crud.js` and `server/src/admin-schema.js` (server) and `src/lib/adminSchema/` (client, one file per entity, registered in `adminSchema.ts`) generate SQL and form fields from declarative entity configs. Adding an entity should mean adding a descriptor, not new CRUD code. - Child collections are deleted and reinserted wholesale. Unsafe for entities referenced by foreign keys elsewhere. - `reindex: false` prevents cross-entity sort order collisions. - The `OMIT` sentinel distinguishes unsent fields from deliberate clears. diff --git a/docs/security-headers.md b/docs/security-headers.md index b84647d..40b5081 100644 --- a/docs/security-headers.md +++ b/docs/security-headers.md @@ -12,9 +12,15 @@ carries Hono's `secureHeaders()` (`server/src/index.js`): - `Referrer-Policy: strict-origin-when-cross-origin`: kept to the origin, because YouTube embeds refuse to play without a referrer. - `Cross-Origin-Opener-Policy` and `Cross-Origin-Resource-Policy: same-origin` -- no HSTS (nginx sends it, below) and no Content-Security-Policy yet - (it needs trying in Report-Only first: pages carry an inline - `window.__NGU_SITE__` script and YouTube, Facebook and Maps iframes). +- no HSTS (nginx sends it, below) +- `Content-Security-Policy-Report-Only`: blocks nothing yet. Browsers + post what it would have blocked to `/api/csp-report`, which logs one + line per report (`journalctl -u ngu-api | grep csp`). The allowed + embed hosts are `EMBEDS` in `server/src/index.js`. After a while of + real use with nothing unexpected in the log, rename + `contentSecurityPolicyReportOnly` to `contentSecurityPolicy` there to + enforce it. A new embed host (a new video site, say) has to be added + to `EMBEDS` first. The API also refuses a form-style write (`text/plain`, form or multipart body) sent from another site, including a sibling subdomain diff --git a/docs/updating-data-in-code.md b/docs/updating-data-in-code.md index bd861f7..881389f 100644 --- a/docs/updating-data-in-code.md +++ b/docs/updating-data-in-code.md @@ -33,7 +33,7 @@ what a dropdown in the admin editor says. | The **label** a dropdown shows in the admin | code | [one file](#renaming-what-a-dropdown-shows) | | The **list of allowed values** behind a fixed dropdown | database CHECK + code | [a migration and three files](#adding-removing-or-renaming-a-stored-value) | | Navigation, page section titles, colours, the site banner, history decades, the map grid | code | [the file named below](#other-content-that-lives-in-code) | -| A static page's title and intro (also its search title and description), the site's name, description, preview image, icons, search indexing | the database, over `site.json` | Admin → Panel → Site settings (superadmins). Blank uses `site.json`, which also holds the site's address and the pages' defaults. See `docs/seo.md` | +| A static page's title and intro (also its search title and description), the site's name, description, preview image, icons, search indexing, privacy contact email | the database, over `site.json` | Admin → Panel → Site settings (superadmins). Blank uses `site.json`, which also holds the site's address and the pages' defaults. See `docs/seo.md` | | Uploaded images | disk + the `media` table | Admin → Tools → Media, or any image field. See `docs/media-uploads.md` | The rule of thumb from `CLAUDE.md`: data belongs in the database, @@ -49,7 +49,7 @@ each entity: | File | What it holds | | ----------------------------- | ----------------------------------------------------- | -| `src/lib/adminSchema.ts` | The **form**: field labels, help text, dropdown labels, list columns and filters | +| `src/lib/adminSchema/` (one file per entity, `shared.ts` for common fields; `src/lib/adminSchema.ts` lists them) | The **form**: field labels, help text, dropdown labels, list columns and filters | | `server/src/admin-schema.js` | What the server **accepts**: columns, types, the allowed values of each `enumeration(...)` | And the database itself holds the final word: most fixed lists are a @@ -76,7 +76,7 @@ organization name in the label, as the `awards` query does. > are changed with a migration: `UPDATE event_scopes SET name = '…' WHERE id = '…';` **2. A fixed list in code (`options`).** The choices are written in -`src/lib/adminSchema.ts`. Each option is one of two shapes: +the entity's file in `src/lib/adminSchema/`. Each option is one of two shapes: ```ts options: ["speaker", "leader", "host"] // shows: speaker, leader, host @@ -90,7 +90,7 @@ relabelling cheap. ### Renaming what a dropdown shows If the stored value stays the same and you only want the dropdown to -read differently, **only `src/lib/adminSchema.ts` changes**. No +read differently, **only the file in `src/lib/adminSchema/` changes**. No migration, no server change, and every existing row keeps working. Find the field (search for its column name) and give the option a @@ -147,7 +147,7 @@ together, in one branch: decide what existing rows become first. 2. **`server/src/admin-schema.js`**: the `enumeration("column", [...])` list for that column. -3. **`src/lib/adminSchema.ts`**: the `options` on the form field, and on +3. **`src/lib/adminSchema/.ts`**: the `options` on the form field, and on the list filter if there is one. 4. **Anywhere the public site renders or relies on the value**, listed in the table below (for example `EVENT_TYPES` for event types, or the @@ -160,7 +160,7 @@ wrong rather than working around it. ### Every dropdown in the editor -**Fixed lists** (`options`: labels in `src/lib/adminSchema.ts`, values +**Fixed lists** (`options`: labels in `src/lib/adminSchema/`, values also in `admin-schema.js` and a CHECK): | Entity → field | Stored values | Labelled? | Also used on the public site by | @@ -176,7 +176,7 @@ also in `admin-schema.js` and a CHECK): | Links → Kind (on organizations, events, people, teams) | action, social, website, email | no | `splitLinks` in `server/src/shape.js` | | Links → Platform | instagram, facebook, discord, youtube, tiktok, x, substack, spotify, linkedin | **yes**, `PLATFORMS` | `PlatformIcon.tsx` draws the icon on the button. **No CHECK and no `enumeration`**: the column is plain text, so adding one is an entry in `PLATFORMS` (`src/lib/platforms.ts`) and its icon in `src/components/PlatformIcon.tsx`, no migration. | | Content blocks → Shown in (slot) | card, body | **yes** | `paragraphs()` in `server/src/shape.js` (card), `ContentBlocks.tsx` (body) | -| Content blocks → Type | heading, subheading, paragraph, list, links, quote, image, divider, video, button, callout, schedule | **yes**, `BLOCK_TYPES` (with each type's description) | `ContentBlocks.tsx` (one renderer per type). Which fields each type shows is `when` on the fields in `blocksChild` (`src/lib/adminSchema.ts`). | +| Content blocks → Type | heading, subheading, paragraph, list, links, quote, image, divider, video, button, callout, schedule | **yes**, `BLOCK_TYPES` (with each type's description) | `ContentBlocks.tsx` (one renderer per type). Which fields each type shows is `when` on the fields in `blocksChild` (`src/lib/adminSchema/shared.ts`). | | Timeline → Kind (+ list filter) | milestone, event, organization, award, people | no | `KIND_NAMES` in `src/pages/sections/history/TimelineEntry.tsx` | | Timeline → Points at (+ list filter) | event, organization, award, person, team | no | `refHref` in `src/lib/hrefs.ts` | | Timeline → Precision (and on events/orgs) | year, month, day | no | the history page's grouping | @@ -219,7 +219,7 @@ each is changed in a different place: | --- | --- | | **The heading on the page** ("National Retreats", "What's on") | **Admin → Pages → Front page → Page sections → Heading.** Blank uses the default below. | | The default heading when that field is blank | `SECTIONS` in `src/pages/Home.tsx`, the `title` of each entry | -| **The name in the admin's Section dropdown** ("Events Carousel (National Retreats)") | `FRONT_PAGE_SECTIONS` in `src/lib/adminSchema.ts` | +| **The name in the admin's Section dropdown** ("Events Carousel (National Retreats)") | `FRONT_PAGE_SECTIONS` in `src/lib/adminSchema/frontPage.ts` | | The subnav links under the header ("#Retreats", "#Calendar") | `PAGE_SECTIONS["/"]` in `src/navConfig.ts` | To rename a band **for visitors**, use the admin. To rename how it @@ -253,7 +253,7 @@ CHECK on `front_page_sections.section` via a migration. The numbers band's "Number Source" dropdown works the same way: -- **Relabel a source:** `STAT_SOURCES` in `src/lib/adminSchema.ts`. +- **Relabel a source:** `STAT_SOURCES` in `src/lib/adminSchema/frontPage.ts`. - **Change what a count counts:** its query in `STAT_QUERIES` in `server/src/routes/home.js`. Keep it counting exactly what the matching public page shows (published rows), or the number and the @@ -273,7 +273,9 @@ The numbers band's "Number Source" dropdown works the same way: | Site-wide announcement banner | `src/data/bannerConfig.ts` | `enabled: false` hides it. Bump `id` when the message changes, so people who dismissed the old one see the new one. | | History page decade headers | `src/data/historyDecades.ts` | Title, tagline and blurb per decade. | | Chapter map tiles and area names | `src/data/mapGrid.ts` | `AREAS` (tile positions) and `AREA_NAMES`. Which region paints which tile is in the database (Admin → Data → Organizations → a region → Map areas). | -| Feedback form types | `src/data/feedbackTypes.ts` **and** `TYPES` in `server/src/routes/feedback.js` | Keep the ids identical in both; the server stores unknown ids as `general`. Labels and hints are client-only. | +| Feedback form types | `src/data/feedbackTypes.ts` **and** `TYPES` in `server/src/routes/feedback.js` | Keep the ids identical in both; the server stores unknown ids as `general`. Labels and hints are client-only. `DATA_REQUEST` ('privacy') isn't a tile: the Privacy page's form sends it, and the server requires an email for it. | +| The site's colours, light and dark | `src/index.css` (`@theme` tokens and the dark overrides under them) | Change a token's value in both modes and every use follows. Use the token utilities (`text-muted`, `bg-surface`, `border-brand/20`) or `var(--color-…)`, not hex. A colour that arrives as data (a page accent, an event's or region's colour) goes through `src/lib/color.ts`: `withAlpha` for tints, `accentText` for text in it, `readableOn` for text on it. | +| Privacy Policy and Terms wording | `src/pages/Privacy.tsx`, `src/pages/Terms.tsx` | The `PARTS` list, and `LAST_UPDATED` whenever the wording changes. The Privacy page must stay true of the code: what the feedback form stores, what the browser keeps, which embeds wait for a click. | | Event type labels and plurals (public site) | `src/lib/eventTypes.ts` | Also the order of the type filter chips. | | Event and person role labels (public site) | `ROLE_LABEL` in `src/pages/EventDetail.tsx` and `src/pages/PersonDetail.tsx` | | | Organization kind labels ("Region", "Chapter") | `ORG_KIND_LABEL` in `src/lib/hrefs.ts` | | diff --git a/index.html b/index.html index d51965e..c10f0c2 100644 --- a/index.html +++ b/index.html @@ -5,6 +5,15 @@ <!-- site:title --> + + diff --git a/server/src/admin-schema.js b/server/src/admin-schema.js index 18ec7ab..b25e2aa 100644 --- a/server/src/admin-schema.js +++ b/server/src/admin-schema.js @@ -378,7 +378,6 @@ const events = { text("org_logo"), text("event_logo"), text("color"), - text("gradient"), text("card_image"), bool("is_published"), bool("is_listed"), @@ -935,6 +934,7 @@ const siteSettings = { text("favicon"), text("apple_touch_icon"), enumeration("indexing", ["on", "off"]), + text("privacy_email"), ], children: [ diff --git a/server/src/index.js b/server/src/index.js index e0ba46e..5a5bf70 100644 --- a/server/src/index.js +++ b/server/src/index.js @@ -62,17 +62,64 @@ app.use("*", logger()); /* Headers for every response. Referrer kept to the origin (YouTube embeds refuse to play without one). No HSTS here: nginx sends it on everything, including the files it serves from disk - (docs/security-headers.md). No CSP yet: pages carry an inline - window.__NGU_SITE__ script and YouTube, Facebook and Maps iframes, - so one needs trying in Report-Only first. */ + (docs/security-headers.md). + + The Content-Security-Policy is Report-Only for now: nothing is + blocked, and each thing it would have blocked is logged by + /api/csp-report (journalctl -u ngu-api). Once a while of real use + logs nothing unexpected, switch contentSecurityPolicyReportOnly to + contentSecurityPolicy. 'unsafe-inline' scripts cover the page's + window.__NGU_SITE__ and the theme script in index.html. */ +const EMBEDS = [ + "https://www.youtube-nocookie.com", + "https://www.youtube.com", + "https://www.facebook.com", + "https://player.vimeo.com", + "https://www.google.com", + "https://maps.google.com", + "https://*.churchcenter.com", + "https://*.churchcenteronline.com", +]; + app.use( "*", secureHeaders({ referrerPolicy: "strict-origin-when-cross-origin", strictTransportSecurity: false, + contentSecurityPolicyReportOnly: { + defaultSrc: ["'self'"], + scriptSrc: ["'self'", "'unsafe-inline'", "https://js.churchcenter.com"], + styleSrc: ["'self'", "'unsafe-inline'"], + imgSrc: ["'self'", "data:", "https:"], + mediaSrc: ["'self'"], + fontSrc: ["'self'"], + connectSrc: ["'self'"], + frameSrc: EMBEDS, + frameAncestors: ["'self'"], + baseUri: ["'self'"], + formAction: ["'self'"], + objectSrc: ["'none'"], + reportUri: "/api/csp-report", + }, }), ); +/* What the policy above would have blocked. Browsers post these on + their own; a short line per report is plenty to go on. */ +app.use("/api/csp-report", rateLimit({ windowMs: 60_000, max: 30 })); +app.post("/api/csp-report", async (c) => { + const text = (await c.req.text()).slice(0, 4000); + try { + const report = JSON.parse(text)["csp-report"] ?? {}; + console.warn( + `csp ${report["violated-directive"] ?? "?"} blocked ${report["blocked-uri"] ?? "?"} on ${report["document-uri"] ?? "?"}`, + ); + } catch { + // Not a report; nothing to log. + } + return c.body(null, 204); +}); + /* Refuse a form-style write (text/plain, form or multipart body) that another site sent, including a sibling subdomain, which SameSite=Lax cookies don't stop. Browsers mark their own requests diff --git a/server/src/migrations/039_privacy_contact.sql b/server/src/migrations/039_privacy_contact.sql new file mode 100644 index 0000000..4e37428 --- /dev/null +++ b/server/src/migrations/039_privacy_contact.sql @@ -0,0 +1,11 @@ +-- ═══════════════════════════════════════════════════════════════ +-- 039 PRIVACY CONTACT +-- +-- The address the Privacy page gives for privacy questions and data +-- requests (Panel → Site settings). Null falls back to site.json's +-- privacyEmail; blank in both, the page points to its request form +-- only. Data requests themselves are feedback rows of type +-- 'privacy' (routes/feedback.js), triaged in Admin → Feedback. +-- ═══════════════════════════════════════════════════════════════ + +ALTER TABLE site_settings ADD COLUMN privacy_email TEXT; diff --git a/server/src/migrations/040_drop_event_gradient.sql b/server/src/migrations/040_drop_event_gradient.sql new file mode 100644 index 0000000..3282ab1 --- /dev/null +++ b/server/src/migrations/040_drop_event_gradient.sql @@ -0,0 +1,12 @@ +-- ═══════════════════════════════════════════════════════════════ +-- 040 NO MORE CARD GRADIENTS +-- +-- An event card is its photo (card_image) under a light veil, or a +-- plain card, always with the event's colour as its border. The +-- gradient layer went over the photo and hid it, and gradients are +-- leaving the design, so the column goes. Any gradient saved on an +-- event is dropped with it; the card falls back to its photo or the +-- plain surface. +-- ═══════════════════════════════════════════════════════════════ + +ALTER TABLE events DROP COLUMN gradient; diff --git a/server/src/pageMeta.js b/server/src/pageMeta.js index 5eb85ba..d0a21c8 100644 --- a/server/src/pageMeta.js +++ b/server/src/pageMeta.js @@ -102,12 +102,13 @@ export function siteFor(db) { ...base.robots, index: row.indexing ? row.indexing === "on" : base.robots?.index !== false, }, + privacyEmail: row.privacy_email || base.privacyEmail || "", pages, }; } /* What the browser app reads for headings and titles. */ -const forBrowser = (site) => ({ title: site.title, pages: site.pages }); +const forBrowser = (site) => ({ title: site.title, pages: site.pages, privacyEmail: site.privacyEmail }); /* robots.txt for this database's setting, as the build writes it. */ export function robotsTxt(site) { diff --git a/server/src/routes/content.js b/server/src/routes/content.js index a8dd3f6..e232246 100644 --- a/server/src/routes/content.js +++ b/server/src/routes/content.js @@ -147,7 +147,6 @@ function shapeEvent(row, links, cardBlocks, hosts = []) { org_logo: row.effective_org_logo, event_logo: row.event_logo, color: row.effective_color, - gradient: row.gradient, card_image: row.card_image, hosts: hosts.map(shapeHost), diff --git a/server/src/routes/feedback.js b/server/src/routes/feedback.js index 25fb7f2..0c377a4 100644 --- a/server/src/routes/feedback.js +++ b/server/src/routes/feedback.js @@ -29,10 +29,10 @@ const LIMITS = { const MIN_MESSAGE = 10; -// Must match FEEDBACK_TYPES in src/pages/sections/FeedbackForm.jsx. +// Must match FEEDBACK_TYPES and DATA_REQUEST in src/data/feedbackTypes.ts. // Anything else falls back to 'general' rather than being rejected, // a renamed option shouldn't lose someone's submission. -const TYPES = ["broken", "confusing", "outdated", "request", "praise", "other"]; +const TYPES = ["broken", "confusing", "outdated", "request", "praise", "other", "privacy"]; /* ── Input cleaning ──────────────────────────────────────────── */ @@ -76,6 +76,10 @@ feedback.post("/", async (c) => { const errors = {}; if (message.length < MIN_MESSAGE) errors.message = "Please write a little more."; if (!looksLikeEmail(email)) errors.email = "That email doesn't look right."; + // A data request (Privacy page) has to be answerable. + else if (feedbackType === "privacy" && !email) { + errors.email = "We need an email address to reply to a data request."; + } if (Object.keys(errors).length > 0) { return c.json({ error: "Validation failed", fields: errors }, 422); diff --git a/server/src/seed-showcase.js b/server/src/seed-showcase.js index 41bcb3b..c592ed9 100644 --- a/server/src/seed-showcase.js +++ b/server/src/seed-showcase.js @@ -352,7 +352,6 @@ tx(db, () => { org_logo: IMAGE, event_logo: IMAGE, color: "#d62976", - gradient: "linear-gradient(160deg, rgba(214,41,118,0.10), rgba(19,139,160,0.10))", card_image: IMAGE, is_published: 1, is_listed: LISTED, diff --git a/site.json b/site.json index 786515f..8d330e0 100644 --- a/site.json +++ b/site.json @@ -2,6 +2,7 @@ "title": "Next Generation of Unity", "url": "https://nextgenerationofunity.org", "description": "", + "privacyEmail": "", "robots": { "index": true }, diff --git a/src/components/ContentBlocks.tsx b/src/components/ContentBlocks.tsx index 30d3199..ddd31f1 100644 --- a/src/components/ContentBlocks.tsx +++ b/src/components/ContentBlocks.tsx @@ -33,13 +33,14 @@ visible even if the renderer hasn't caught up with it. ═══════════════════════════════════════════════════════════════ */ -import { blockMedia } from '../lib/media.ts' +import { mediaUrl } from '../lib/media.ts' import type { ContentBlock } from '../lib/useContent.ts' import { Anchor, Inline, Paragraphs } from './InlineText.tsx' import VideoPlayer from './VideoPlayer.tsx' import ScheduleBlock from './ScheduleBlock.tsx' +import { accentText } from '../lib/color.ts' -const BODY = '#4a6b72' +const BODY = 'var(--color-muted)' export default function ContentBlocks({ blocks, @@ -76,14 +77,14 @@ function Block({ block, accent }: { block: ContentBlock; accent: string }) { switch (block.type) { case 'heading': return ( -

+

{text}

) case 'subheading': return ( -

+

{text}

) @@ -93,12 +94,12 @@ function Block({ block, accent }: { block: ContentBlock; accent: string }) {