Events 3.3.0, Accounts 1.3.0, contracts 1.11.0: Accounts looks like Events, backups; sign-out and upload fixes
- Accounts: account and admin pages in Cross Events' layout (top bar, sidebar, a page per section, dark footer); quick links to the church's sites (GET /me/apps); nightly pg_dump backups with Admin -> Backups (run, keep, download, audited; heartbeat lastBackupAt); a fuller built-in privacy notice with headings and bullets; a fixed favicon. /backups/ ignored (anchored, so src/backups is kept). - Contracts 1.11.0: people.removeDemo (only @example.com, never an admin). - Events: uploads served from the folder they're saved in (a backend started outside backend/ answered 404 for a logo it had just saved); Branding checks the file loads before saving; logout waits for the sign-out call so Accounts signs out too; set-demo removes the last demo's people from Accounts. Tests: Accounts 62 + e2e 8, Events 782, contracts 225; npm run check passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
* deleted people stay Events-only. Recovery codes don't move (decision 2): Accounts shows new ones.
|
||||
*/
|
||||
import crypto from 'node:crypto';
|
||||
import { IMPORT_BATCH_MAX, phoneSchema, type ImportPerson, type ImportResult } from '@crosscode/contracts';
|
||||
import { IMPORT_BATCH_MAX, phoneSchema, REMOVE_DEMO_MAX, type ImportPerson, type ImportResult } from '@crosscode/contracts';
|
||||
import { siteUrl } from '../feed/context';
|
||||
import { accounts, accountsLink, AccountsUnavailable } from './client';
|
||||
import { accountsMessaging } from './messaging';
|
||||
@@ -263,6 +263,26 @@ export async function moveNewPeople(actor: string | null = null): Promise<{ move
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 3.3.0: new demo data replaced the old (set-demo), so the old demo people's church accounts go
|
||||
* too (contracts 1.11.0 `people.removeDemo`). Accounts removes only demo addresses
|
||||
* (`@example.com`) it knows through this site, never an Accounts admin. Only while sign-in goes
|
||||
* through Accounts; returns how many went and how many it kept.
|
||||
*/
|
||||
export async function removeDemoPeople(subs: string[], actor: string | null = null): Promise<{ removed: number; kept: number }> {
|
||||
const unique = [...new Set(subs.filter(Boolean))];
|
||||
if ((await authMode()) !== 'accounts' || !unique.length) return { removed: 0, kept: 0 };
|
||||
const auth = await accounts();
|
||||
let removed = 0;
|
||||
let kept = 0;
|
||||
for (const batch of chunk(unique, REMOVE_DEMO_MAX)) {
|
||||
const r = await auth.request<{ removed: number; kept: unknown[] }>({ type: 'people.removeDemo', actor, subs: batch }, { timeoutMs: 120000 });
|
||||
removed += r.removed;
|
||||
kept += r.kept.length;
|
||||
}
|
||||
return { removed, kept };
|
||||
}
|
||||
|
||||
/** The move. Throws MoveError when it doesn't finish; nothing changes for anyone then. */
|
||||
export async function move(opts: { actor: { id: string; role: string; name?: string }; adminIds: string[]; keepAccountsNotices?: boolean; ip?: string | null }): Promise<MoveReport> {
|
||||
const auth = await connected();
|
||||
|
||||
@@ -196,18 +196,11 @@ app.get('/docs', (req, res) => res.redirect(301, '/api/docs/v2'));
|
||||
// Pre-warm the settings cache so synchronous helpers have DB values from startup
|
||||
const { getSettingSync, warmCache } = require('./utils/settingsCache');
|
||||
warmCache().catch(() => {});
|
||||
// Uploaded branding assets can include SVGs, which may embed <script>/event
|
||||
// handlers. Serving them inline lets a compromised/malicious upload run script
|
||||
// in the site's origin if opened directly, so pin the safe response headers
|
||||
// (no inline execution, no MIME-sniffing to HTML/script) on every asset here.
|
||||
// Uploaded files, with safe headers (utils/uploads.js): served from the folder they're saved in
|
||||
// (3.3.0; before, from one relative to where the process started, so a new logo could be "missing").
|
||||
// Stored paths stay "/uploads/…"; they're given out as /api/uploads/… (v2/schemas.ts absoluteUrl).
|
||||
// /uploads still answers for links made before 2.2.0.
|
||||
const uploads = express.static('public/uploads', {
|
||||
setHeaders: (res) => {
|
||||
res.setHeader('Content-Security-Policy', "default-src 'none'; style-src 'unsafe-inline'; sandbox");
|
||||
res.setHeader('X-Content-Type-Options', 'nosniff');
|
||||
},
|
||||
});
|
||||
const uploads = require('./utils/uploads').serveUploads();
|
||||
app.use('/api/uploads', uploads, notFound); // a missing file is 404, not "API v1 removed"
|
||||
app.use('/uploads', uploads);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ const path = require('path');
|
||||
const fs = require('fs');
|
||||
const crypto = require('crypto');
|
||||
const multer = require('multer');
|
||||
const { UPLOADS_DIR } = require('../utils/uploads');
|
||||
|
||||
// Builds a filename multer can never be tricked into escaping the upload
|
||||
// directory with — extension only, no attacker-controlled path segments.
|
||||
@@ -13,7 +14,7 @@ function safeFilename(prefix, ext) {
|
||||
// Setup multer storage
|
||||
const storage = multer.diskStorage({
|
||||
destination: function (req, file, cb) {
|
||||
const uploadPath = path.join(__dirname, '..', '..','public', 'uploads', 'events');
|
||||
const uploadPath = path.join(UPLOADS_DIR, 'events');
|
||||
|
||||
// Check if the upload location exists
|
||||
try {
|
||||
@@ -52,7 +53,7 @@ const upload = multer({
|
||||
// Logo storage (separate subfolder)
|
||||
const logoStorage = multer.diskStorage({
|
||||
destination: function (req, file, cb) {
|
||||
const uploadPath = path.join(__dirname, '..', '..', 'public', 'uploads', 'branding');
|
||||
const uploadPath = path.join(UPLOADS_DIR, 'branding');
|
||||
try {
|
||||
if (!fs.existsSync(uploadPath)) fs.mkdirSync(uploadPath, { recursive: true });
|
||||
cb(null, uploadPath);
|
||||
@@ -80,7 +81,7 @@ const uploadLogo = multer({
|
||||
// Favicon storage (same subfolder as the logo — both are "branding" assets)
|
||||
const faviconStorage = multer.diskStorage({
|
||||
destination: function (req, file, cb) {
|
||||
const uploadPath = path.join(__dirname, '..', '..', 'public', 'uploads', 'branding');
|
||||
const uploadPath = path.join(UPLOADS_DIR, 'branding');
|
||||
try {
|
||||
if (!fs.existsSync(uploadPath)) fs.mkdirSync(uploadPath, { recursive: true });
|
||||
cb(null, uploadPath);
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// Where uploaded files live, and how they're served (3.3.0). One folder for saving and serving:
|
||||
// backend/public/uploads, the same from src/ and dist/. Before 3.3.0 the files were served from
|
||||
// "public/uploads" relative to wherever the process was started, so a backend started from
|
||||
// another folder saved a logo in one place and answered 404 for it from another.
|
||||
const path = require('path');
|
||||
const express = require('express');
|
||||
|
||||
const UPLOADS_DIR = path.join(__dirname, '..', '..', 'public', 'uploads');
|
||||
|
||||
/** The folder for one kind of upload (e.g. "branding"), made if it isn't there yet. */
|
||||
function uploadsDir(sub) {
|
||||
const dir = path.join(UPLOADS_DIR, sub);
|
||||
require('fs').mkdirSync(dir, { recursive: true });
|
||||
return dir;
|
||||
}
|
||||
|
||||
// Uploaded branding assets can include SVGs, which may embed <script>/event handlers. Serving
|
||||
// them inline lets a malicious upload run script in the site's origin if opened directly, so pin
|
||||
// the safe response headers (no inline execution, no MIME-sniffing to HTML/script) on every file.
|
||||
function serveUploads() {
|
||||
return express.static(UPLOADS_DIR, {
|
||||
setHeaders: (res) => {
|
||||
res.setHeader('Content-Security-Policy', "default-src 'none'; style-src 'unsafe-inline'; sandbox");
|
||||
res.setHeader('X-Content-Type-Options', 'nosniff');
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = { UPLOADS_DIR, uploadsDir, serveUploads };
|
||||
Reference in New Issue
Block a user