Skip to content

Commit 15f0120

Browse files
fix(svg): sanitize hex colors in monthly badge to prevent XSS
1 parent e15a46a commit 15f0120

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

lib/svg/generator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,9 @@ export function generateMonthlySVG(stats: MonthlyStats, params: BadgeParams): st
340340
}
341341

342342
const safeUser = escapeXML(params.user || 'GitHub User');
343-
const bg = `#${(params.bg || '0d1117').replace('#', '')}`;
344-
const accent = `#${(params.accent || '00ffaa').replace('#', '')}`;
345-
const text = `#${(params.text || 'ffffff').replace('#', '')}`;
343+
const bg = `#${sanitizeHexColor(params.bg, '0d1117')}`;
344+
const accent = `#${sanitizeHexColor(params.accent, '00ffaa')}`;
345+
const text = `#${sanitizeHexColor(params.text, 'ffffff')}`;
346346

347347
const sanitizeFont = (name: string) => name.replace(/[^a-zA-Z0-9\s-]/g, '').trim();
348348
const sanitizedFont = params.font ? sanitizeFont(params.font) : null;

0 commit comments

Comments
 (0)