Skip to content

Commit cb18c17

Browse files
fix: hide raw error message from public SVG in streak API (JhaSourav07#862)
## Description Fixes JhaSourav07#567 The `/api/streak` endpoint was embedding the raw exception message directly inside the fallback error SVG using `escapeXML(message)`. This exposed internal details like GitHub PAT hints, API status codes, and timeout values to anyone who embedded the badge or visited the URL. **Fix:** Replaced the raw error message in the public SVG with a generic user-friendly string. The real error is now logged server-side only via `console.error` so debugging is still possible without leaking internals. ```ts // ❌ Before Error: ${escapeXML(message)} // raw error visible publicly // ✅ After console.error('[streak] Unhandled error:', message); // server-side only // SVG now shows: "Something went wrong. Please try again later." ``` **File changed:** `app/api/streak/route.ts` (~line 165) — 3 line diff. --- ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) --- ## Visual Preview **Before** (with invalid PAT): ``` ┌──────────────────────────────────────┐ │ Error: GitHub PAT is invalid or │ ← internal detail leaked ❌ │ missing │ └──────────────────────────────────────┘ ``` **After** (with invalid PAT): ``` ┌──────────────────────────────────────┐ │ Something went wrong. │ ← clean generic message ✅ │ Please try again later. │ └──────────────────────────────────────┘ ``` --- ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). - [x] My commits follow the Conventional Commits format (e.g., `fix(streak): hide raw error message from public SVG`). - [ ] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have starred the repo. - [x] I have made sure that I have only one commit to merge in this PR. - [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). - [ ] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
1 parent 0c75cf1 commit cb18c17

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

app/api/streak/route.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,8 @@ describe('GET /api/streak', () => {
533533
const response = await GET(makeRequest({ user: 'octocat' }));
534534
const body = await response.text();
535535

536-
expect(body).toContain('API is down');
536+
expect(body).toContain('Something went wrong. Please try again later.');
537+
expect(body).not.toContain('API is down');
537538
});
538539

539540
it('never caches an error response', async () => {
@@ -553,7 +554,8 @@ describe('GET /api/streak', () => {
553554

554555
expect(response.status).toBe(500);
555556
const body = await response.text();
556-
expect(body).toContain('Unknown error');
557+
expect(body).toContain('Something went wrong. Please try again later.');
558+
expect(body).not.toContain('Unknown error');
557559
});
558560

559561
it('returns a well-formed SVG structure even in the error state', async () => {

app/api/streak/route.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,16 @@ function buildErrorResponse(error: unknown, parseResult: ParseResult): NextRespo
204204
});
205205
}
206206

207+
console.error('[streak] Unhandled error:', message);
208+
207209
const errorSvg = `
208-
<svg xmlns="http://www.w3.org/2000/svg" width="400" height="150">
209-
<rect width="100%" height="100%" fill="#2d0000" rx="8"/>
210-
<text x="50%" y="50%" text-anchor="middle" fill="#ffcccc">
211-
Error: ${escapeXML(message)}
212-
</text>
213-
</svg>
214-
`;
210+
<svg xmlns="http://www.w3.org/2000/svg" width="400" height="150">
211+
<rect width="100%" height="100%" fill="#2d0000" rx="8"/>
212+
<text x="50%" y="50%" text-anchor="middle" fill="#ffcccc">
213+
Something went wrong. Please try again later.
214+
</text>
215+
</svg>
216+
`;
215217

216218
return new NextResponse(errorSvg, {
217219
status: 500,

0 commit comments

Comments
 (0)