Skip to content

Commit 0da1292

Browse files
fix(github): cap max pages in fetchUserRepos to prevent DoS (JhaSourav07#591)
* fix(svg): sanitize hex colors in monthly badge to prevent XSS * fix(github): cap max pages in fetchUserRepos to prevent DoS
1 parent b6fe25d commit 0da1292

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

lib/github.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ describe('fetchUserRepos', () => {
268268

269269
await fetchUserRepos('octocat');
270270

271-
expect(fetch).toHaveBeenCalledTimes(100);
271+
expect(fetch).toHaveBeenCalledTimes(3);
272272
});
273273
});
274274

lib/github.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ export async function fetchUserRepos(
272272
const allRepos: GitHubRepo[] = [];
273273

274274
let PAGE = 1;
275-
const MAX_PAGES = 100;
275+
const MAX_PAGES = 3; // Hard cap at 3 pages (300 repos) to prevent API rate limit exhaustion (DoS)
276276
while (PAGE <= MAX_PAGES) {
277277
const res = await fetchWithRetry(
278278
`${GITHUB_REST_URL}/users/${username}/repos?per_page=100&page=${PAGE}&sort=pushed`,

lib/svg/generator.ts

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

336336
const safeUser = escapeXML(params.user || 'GitHub User');
337-
const bg = `#${(params.bg || '0d1117').replace('#', '')}`;
338-
const accent = `#${(params.accent || '00ffaa').replace('#', '')}`;
339-
const text = `#${(params.text || 'ffffff').replace('#', '')}`;
337+
const bg = `#${sanitizeHexColor(params.bg, '0d1117')}`;
338+
const accent = `#${sanitizeHexColor(params.accent, '00ffaa')}`;
339+
const text = `#${sanitizeHexColor(params.text, 'ffffff')}`;
340340

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

0 commit comments

Comments
 (0)