mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 09:36:08 +00:00
The suite that landed in #43/#44 was written against existing behaviour, so a number of tests pinned bugs rather than asserting correct behaviour. This fixes the production code and moves each of those tests onto the fixed behaviour in the same change. Security: - project-download: derive the archive entry extension from the last path segment and restrict it to a short alphanumeric run, so an extensionless allowlisted url can no longer contribute a path separator; validate the r2 branch against the strict proxy-path pattern instead of a `startsWith`, which let `/api/upload/video/clip.mp4/../../etc/passwd` through verbatim. - rate-limit: hash a key or action wider than its column instead of skipping the query. Both the guard and the failing INSERT used to answer "allowed", so the limit stopped applying entirely. Warn at startup when TRUSTED_PROXY_MODE is unset in production. - video uploads: the file name decides the content type; a client-declared video mime no longer makes `payload.exe` acceptable. - email templates: escape in the helpers rather than relying on every caller, with an explicit `rawEmailHtml()` opt-out for the one call site that builds markup. `escapeHtml` now covers the single quote. - CSP: allow loopback object storage outside production only. - route-access: reach the billing redirect only for the workspace owner. Keying it off the owner's billing status alone made the redirect target an oracle for whose subscription had lapsed, and sent members to a page they cannot act on. - search: carry the same billing condition every other read path carries. - logger: check `err.name` as well as `err.constructor.name`, so a re-thrown, deserialised or minified Prisma error is still redacted. - upload tokens: resolve the signing secret outside the try, so a server booted without one fails loudly instead of reporting every grant as a forgery. - invitations: never downgrade an existing membership, and report a scoped invitation that points at nothing as not_found rather than accepted. - auth: resolve the workspace role for every signed-in caller, so checkProjectAccess and computeProjectAccess stop disagreeing about the owner who also owns the workspace. The `intent` option is gone with it. - r2-media-proxy: validate the object key inside the proxy so the guard travels with the function; delete the unused, unanchored `mediaUrlToR2Key`. - r2: sign the content type into presigned PUT grants. Correctness: - frame rate snapping picks the nearest standard, not the first within tolerance, so 24, 30 and 60 fps are reachable at all. - a version upload registers its Bunny cleanup as soon as bunny-init answers, so a failed tus upload no longer leaves a billed video behind. - deleting videos clears storage before the rows, so a refused DELETE leaves a retryable row rather than an orphaned object. - an expired upload session can be cancelled, which is what releases its quota. - `voice/` joins the delete allowlist, so a voice note can be removed by the module that wrote it. - a failed CORS write propagates instead of being mistaken for an empty config and replacing the bucket's rules. - filtering projects by workspace no longer hides projects the unfiltered call returns. - upload retries skip aborts and permanent 4xx; progress no longer divides by zero. - reply edits no longer clear the comment's tag; optimistic resolve rolls back to the state it replaced; the delete snapshot is captured once. - assorted UI fixes: duplicate React keys, double-click guards reading stale closures, the tag list fetched twice per load, a failed member list rendering as an empty one, a stale "Initializing upload..." beside a failure, and a registration banner pointing at an email that never arrives. Consistency and access: - the two download routes answer 404 for an id belonging to another tenant, as the comment export route already did. A caller who does belong still gets 403. - accessible names for the share-link password field, the guest name gates, the version dialog inputs and the comment-tag controls. Repository health: - the runner image installs production dependencies only. - a setup file for the unit project restores stubbed env centrally. - native tsconfig path resolution replaces vite-tsconfig-paths. - `uploadBytesWithProgress` exists once. - admin stats bill Bunny storage to the workspace owner like every other quota, gate on the configured flag, wire up the single-flight guard and count the statuses that belonged to no bucket. - `r2Client.destroy()` releases the presign client too. - `prepare` tolerates a production install, where husky is absent.
133 lines
5.6 KiB
TypeScript
133 lines
5.6 KiB
TypeScript
export const EMAIL_COLORS = {
|
|
bg: '#171717',
|
|
card: '#252525',
|
|
cardInner: '#2f2f2f',
|
|
border: '#3a3a3a',
|
|
accent: '#7aa7ff',
|
|
accentDark: '#243656',
|
|
text: '#f5f5f5',
|
|
textSecondary: '#c6c6cc',
|
|
textDim: '#8d8d95',
|
|
} as const;
|
|
|
|
function brandLogoSvg(): string {
|
|
return `<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" style="display:block;pointer-events:none;">
|
|
<rect x="2" y="6" width="14" height="12" rx="2" stroke="${EMAIL_COLORS.accent}" stroke-width="2" />
|
|
<path d="m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5" stroke="${EMAIL_COLORS.accent}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
|
|
</svg>`;
|
|
}
|
|
|
|
export function escapeHtml(str: string): string {
|
|
return str
|
|
.replace(/&/g, '&')
|
|
.replace(/</g, '<')
|
|
.replace(/>/g, '>')
|
|
.replace(/"/g, '"')
|
|
.replace(/'/g, ''');
|
|
}
|
|
|
|
const RAW_EMAIL_HTML = Symbol('rawEmailHtml');
|
|
|
|
/** Markup a caller has already built and vouches for. See {@link rawEmailHtml}. */
|
|
export type RawEmailHtml = { readonly [RAW_EMAIL_HTML]: string };
|
|
|
|
/**
|
|
* Opt a value out of escaping. The helpers below escape everything they are given, so a
|
|
* caller that genuinely needs markup, a `<span>` around one half of a label, has to say
|
|
* so here. That keeps the default safe: a project name or a display name passed straight
|
|
* into a helper is escaped whether or not the caller remembered to.
|
|
*/
|
|
export function rawEmailHtml(html: string): RawEmailHtml {
|
|
return { [RAW_EMAIL_HTML]: html };
|
|
}
|
|
|
|
export type EmailText = string | RawEmailHtml;
|
|
|
|
function renderEmailText(value: EmailText): string {
|
|
return typeof value === 'string' ? escapeHtml(value) : value[RAW_EMAIL_HTML];
|
|
}
|
|
|
|
export function escapeAttr(str: string): string {
|
|
return str
|
|
.replace(/&/g, '&')
|
|
.replace(/"/g, '"')
|
|
.replace(/</g, '<')
|
|
.replace(/>/g, '>');
|
|
}
|
|
|
|
/**
|
|
* `bodyHtml` is markup, not text: it is assembled from the helpers below, so it is the one
|
|
* value here that is inserted verbatim. Everything a caller supplies as text, the footer
|
|
* included, is escaped.
|
|
*/
|
|
export function brandedEmailTemplate(
|
|
bodyHtml: string,
|
|
options?: {
|
|
footerText?: string;
|
|
footerLinkText?: string;
|
|
footerLinkUrl?: string;
|
|
}
|
|
): string {
|
|
const body = bodyHtml;
|
|
const footerText = options?.footerText || '';
|
|
const footerLinkText = options?.footerLinkText || '';
|
|
const footerLinkUrl = options?.footerLinkUrl || '';
|
|
|
|
return `<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1.0"><meta name="color-scheme" content="dark"></head>
|
|
<body style="margin:0;padding:0;background-color:${EMAIL_COLORS.bg};font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;color:${EMAIL_COLORS.text};">
|
|
<table width="100%" cellpadding="0" cellspacing="0" style="background-color:${EMAIL_COLORS.bg};padding:40px 16px;">
|
|
<tr><td align="center">
|
|
<table width="100%" cellpadding="0" cellspacing="0" style="max-width:560px;">
|
|
<tr><td style="padding:0 0 24px;">
|
|
<table cellpadding="0" cellspacing="0"><tr>
|
|
<td style="padding-right:10px;vertical-align:middle;">${brandLogoSvg()}</td>
|
|
<td style="vertical-align:middle;font-size:16px;font-weight:700;color:${EMAIL_COLORS.text};letter-spacing:0.08em;">OpenFrame</td>
|
|
</tr></table>
|
|
</td></tr>
|
|
|
|
<tr><td style="background-color:${EMAIL_COLORS.card};border:1px solid ${EMAIL_COLORS.border};padding:0;">
|
|
${body}
|
|
</td></tr>
|
|
|
|
${
|
|
footerText || (footerLinkText && footerLinkUrl)
|
|
? `
|
|
<tr><td style="padding:20px 0 0;text-align:center;">
|
|
${footerText ? `<p style="margin:0 0 6px;font-size:11px;color:${EMAIL_COLORS.textDim};">${escapeHtml(footerText)}</p>` : ''}
|
|
${footerLinkText && footerLinkUrl ? `<a href="${escapeAttr(footerLinkUrl)}" style="font-size:11px;color:${EMAIL_COLORS.accent};text-decoration:underline;">${escapeHtml(footerLinkText)}</a>` : ''}
|
|
</td></tr>`
|
|
: ''
|
|
}
|
|
</table>
|
|
</td></tr>
|
|
</table>
|
|
</body>
|
|
</html>`;
|
|
}
|
|
|
|
export function emailHeading(icon: EmailText, title: EmailText): string {
|
|
return `<td style="padding:16px 20px;border-bottom:1px solid ${EMAIL_COLORS.border};background-color:${EMAIL_COLORS.accentDark};">
|
|
<span style="font-size:14px;font-weight:600;color:${EMAIL_COLORS.accent};">${renderEmailText(icon)} ${renderEmailText(title)}</span>
|
|
</td>`;
|
|
}
|
|
|
|
export function emailRow(label: EmailText, value: EmailText, isHighlight = false): string {
|
|
const valStyle = isHighlight
|
|
? `color:${EMAIL_COLORS.text};font-weight:600;`
|
|
: `color:${EMAIL_COLORS.textSecondary};`;
|
|
return `<tr>
|
|
<td style="padding:6px 16px 6px 0;color:${EMAIL_COLORS.textDim};font-size:13px;white-space:nowrap;vertical-align:top;">${renderEmailText(label)}</td>
|
|
<td style="padding:6px 0;font-size:13px;${valStyle}">${renderEmailText(value)}</td>
|
|
</tr>`;
|
|
}
|
|
|
|
export function emailButton(text: EmailText, url: string): string {
|
|
return `<a href="${escapeAttr(url)}" style="display:inline-block;padding:9px 22px;background-color:${EMAIL_COLORS.accent};color:#0f1114;font-size:13px;font-weight:700;text-decoration:none;letter-spacing:0.2px;">${renderEmailText(text)}</a>`;
|
|
}
|
|
|
|
export function emailHighlight(text: EmailText): string {
|
|
return `<div style="border:1px solid ${EMAIL_COLORS.border};padding:10px 12px;margin:0 0 16px;background-color:${EMAIL_COLORS.cardInner};color:${EMAIL_COLORS.text};font-size:13px;line-height:1.5;">${renderEmailText(text)}</div>`;
|
|
}
|