P1-0: V8 heap cap (HOMARR_MAX_OLD_SPACE_SIZE, default 512MB)
P1-1: Module graph cuts
- Dynamic integration imports (55 static → lazy loaders)
- Conditional DB driver loading (only configured driver loaded)
- Replace jsdom with linkedom for SVG sanitization
- Delete eager widget barrel (55 import * as → 0)
- Extract createRetryableLoader to @homarr/common
P1-2: Enable cacheComponents + restructure root layout
- Suspense boundaries around session-dependent providers
- ColorSchemeScript replaces server-side cookie reads
- Board/manage/auth layouts wrapped in Suspense
P1-3: Cache read paths
- Cache tag registry + invalidation helpers
- Cache invalidation wired into all mutation routers
- Translation deep-merge memoized per locale
P1-4: Prerendered shells + loading.tsx files
P1-5: Shared integration data cache (60s TTL, stale-while-revalidate)
P1-6: Redis-backed Next.js cache handler (@homarr/next-cache-handler)
P1-7: Redis optional (memory channel fallback), TTL on pubSub:last:*,
Redis clients consolidated from 6 to 2
91 lines
2.5 KiB
TypeScript
91 lines
2.5 KiB
TypeScript
import createDOMPurify from "dompurify";
|
|
import { parseHTML } from "linkedom";
|
|
|
|
const svgSanitizeOptions = {
|
|
USE_PROFILES: { svg: true, svgFilters: true },
|
|
} as const;
|
|
|
|
// ponytail: linkedom stores DOM tree pointers as own value properties; DOMPurify
|
|
// resolves them via prototype getters (lookupGetter). Without this shim, sanitize
|
|
// is a no-op and XSS payloads pass through unchanged.
|
|
const patchLinkedomNodePrototype = (Node: typeof window.Node) => {
|
|
for (const prop of [
|
|
"ownerDocument",
|
|
"parentNode",
|
|
"nextSibling",
|
|
"previousSibling",
|
|
"nodeName",
|
|
"nodeType",
|
|
"childNodes",
|
|
] as const) {
|
|
if (Object.getOwnPropertyDescriptor(Node.prototype, prop)?.get) {
|
|
continue;
|
|
}
|
|
|
|
if (Object.getOwnPropertyDescriptor(Node.prototype, prop)?.value !== undefined) {
|
|
delete Node.prototype[prop as keyof Node];
|
|
}
|
|
|
|
Object.defineProperty(Node.prototype, prop, {
|
|
configurable: true,
|
|
enumerable: true,
|
|
get() {
|
|
return Object.getOwnPropertyDescriptor(this, prop)?.value ?? null;
|
|
},
|
|
set(value: unknown) {
|
|
Object.defineProperty(this, prop, {
|
|
value,
|
|
writable: true,
|
|
configurable: true,
|
|
enumerable: true,
|
|
});
|
|
},
|
|
});
|
|
}
|
|
};
|
|
|
|
const createDocument = () => parseHTML("<!doctype html><html><head></head><body></body></html>");
|
|
|
|
const { window, document, Node } = createDocument();
|
|
patchLinkedomNodePrototype(Node);
|
|
|
|
if (!document.implementation?.createHTMLDocument) {
|
|
Object.defineProperty(document, "implementation", {
|
|
value: {
|
|
createHTMLDocument() {
|
|
return createDocument().document;
|
|
},
|
|
createDocument() {
|
|
return createDocument().document;
|
|
},
|
|
},
|
|
});
|
|
}
|
|
|
|
window.NodeFilter ??= {
|
|
FILTER_ACCEPT: 1,
|
|
FILTER_REJECT: 2,
|
|
FILTER_SKIP: 3,
|
|
SHOW_ALL: 0xffffffff,
|
|
SHOW_ELEMENT: 1,
|
|
SHOW_ATTRIBUTE: 2,
|
|
SHOW_TEXT: 4,
|
|
SHOW_CDATA_SECTION: 8,
|
|
SHOW_PROCESSING_INSTRUCTION: 64,
|
|
SHOW_COMMENT: 128,
|
|
SHOW_DOCUMENT: 0x100,
|
|
SHOW_DOCUMENT_TYPE: 0x200,
|
|
SHOW_DOCUMENT_FRAGMENT: 0x400,
|
|
SHOW_NOTATION: 0x800,
|
|
} as typeof window.NodeFilter;
|
|
|
|
const purify = createDOMPurify(window as unknown as Parameters<typeof createDOMPurify>[0]);
|
|
|
|
export const sanitizeSvg = (svgText: string) => {
|
|
// linkedom's DOMParser omits html/body for fragment-only SVG; DOMPurify needs a body root.
|
|
const wrapped = `<html><body>${svgText}</body></html>`;
|
|
return purify.sanitize(wrapped, svgSanitizeOptions);
|
|
};
|
|
|
|
export { svgSanitizeOptions, purify };
|