fix: Redis expire guard, transferOwnership prev-owner, SVG regex

- Redis get() rejects legacy expire=0 entries and cleans them up
- transferOwnership invalidates previous owner in addition to new
- SVG regex uses non-greedy match and handles self-closing <svg />
- SVG fallback returns empty string instead of HTML wrapper
- Memory channel comment: FIFO eviction, not timestamp-based
This commit is contained in:
Thomas Camlong committed 2026-08-07 20:57:07 +02:00
1 parent fbb2eddd87
commit 67ac2bbc7c
4 files changed
+17 -3

No files matched your search

@@ -86,8 +86,8 @@ export const sanitizeSvg = (svgText: string) => {
// linkedom's DOMParser omits html/body for fragment-only SVG; DOMPurify needs a body root. // linkedom's DOMParser omits html/body for fragment-only SVG; DOMPurify needs a body root.
const wrapped = `<html><body>${svgText}</body></html>`; const wrapped = `<html><body>${svgText}</body></html>`;
const sanitized = purify.sanitize(wrapped, svgSanitizeOptions); const sanitized = purify.sanitize(wrapped, svgSanitizeOptions);
const svgMatch = sanitized.match(/<svg[\s\S]*<\/svg>/i); const svgMatch = sanitized.match(/<svg[\s\S]*?(?:<\/svg>|\/>)/i);
return svgMatch ? svgMatch[0] : sanitized; return svgMatch ? svgMatch[0] : "";
}; };
export { svgSanitizeOptions, purify }; export { svgSanitizeOptions, purify };
+9
View File
@@ -327,13 +327,22 @@ export const groupRouter = createTRPCRouter({
await throwIfGroupNotFoundAsync(ctx.db, input.groupId); await throwIfGroupNotFoundAsync(ctx.db, input.groupId);
await throwIfGroupNameIsReservedAsync(ctx.db, input.groupId); await throwIfGroupNameIsReservedAsync(ctx.db, input.groupId);
const group = await ctx.db.query.groups.findFirst({
columns: { ownerId: true },
where: eq(groups.id, input.groupId),
});
await ctx.db await ctx.db
.update(groups) .update(groups)
.set({ .set({
ownerId: input.userId, ownerId: input.userId,
}) })
.where(eq(groups.id, input.groupId)); .where(eq(groups.id, input.groupId));
invalidateUserCache(input.userId); invalidateUserCache(input.userId);
if (group?.ownerId && group.ownerId !== input.userId) {
invalidateUserCache(group.ownerId);
}
}), }),
deleteGroup: permissionRequiredProcedure deleteGroup: permissionRequiredProcedure
.requiresPermission("admin") .requiresPermission("admin")
@@ -56,6 +56,11 @@ export class RedisCacheHandler implements CacheHandler {
body: number[]; body: number[];
}; };
if (parsed.expire <= 0) {
await this.redis.del(this.entryKey(cacheKey)).catch(() => {});
return undefined;
}
const allTags = [...parsed.tags, ...softTags]; const allTags = [...parsed.tags, ...softTags];
const expiration = await this.getExpiration(allTags); const expiration = await this.getExpiration(allTags);
if (expiration !== 0 && expiration > parsed.timestamp) { if (expiration !== 0 && expiration > parsed.timestamp) {
+1 -1
View File
@@ -12,7 +12,7 @@ export const memoryPublish = (channel: string, data: unknown) => {
const serialized = superjson.stringify(data); const serialized = superjson.stringify(data);
lastData.set(channel, { data: serialized, timestamp: Date.now() }); lastData.set(channel, { data: serialized, timestamp: Date.now() });
// Bounded: evict oldest if over limit // ponytail: FIFO eviction by Map insertion order, not timestamp.
if (lastData.size > MAX_ENTRIES) { if (lastData.size > MAX_ENTRIES) {
const oldest = lastData.keys().next().value; const oldest = lastData.keys().next().value;
if (oldest) lastData.delete(oldest); if (oldest) lastData.delete(oldest);