Finish the audit leftovers
- One mediaUrl in media.ts instead of 12 identical aliases and a kind map; orgPath builds on hrefs.ts's orgHref - One Logo component (hides itself or shows a fallback when the file is missing) for event cards, org lists and chapter marks - useHistory is a thin wrapper over useRecord - adminSchema.ts split into adminSchema/, one file per entity plus shared.ts; the registry is unchanged (checked by loading both) - JS smooth scrolls respect reduced motion (lib/motion.ts) - Content-Security-Policy in Report-Only, with /api/csp-report logging what it would block Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c74ad746f5
commit
e4a9c96f7e
42 changed files with 1968 additions and 2043 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue