Skip to content

Commit 2d9dbde

Browse files
fix: cap github caches and sanitize og user injection
1 parent 6a3d87e commit 2d9dbde

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

app/api/og/route.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@ function getLuminance(hex: string) {
3737

3838
export async function GET(req: NextRequest) {
3939
const { searchParams } = new URL(req.url);
40-
41-
const { user, theme, bg, text, accent } = ogParamsSchema.parse(
40+
const parsed = ogParamsSchema.parse(
4241
Object.fromEntries(searchParams.entries())
4342
);
43+
let { user } = parsed;
44+
const { theme, bg, text, accent } = parsed;
45+
46+
// Sanitize user: limit to 39 chars (GitHub max length) and strip invalid chars
47+
user = user.slice(0, 39).replace(/[^a-zA-Z0-9-]/g, '');
4448

4549
const selectedTheme = themes[theme] || themes.dark;
4650
const resolvedBg = `#${bg || selectedTheme.bg}`;

0 commit comments

Comments
 (0)