Skip to content

Commit 6f2fa00

Browse files
authored
fix: enforce strict boundary limits on grace and opacity inputs (JhaSourav07#3421)
## Description Implements robust runtime boundary validation and value clamping using `Math.max` and `Math.min` for both the `grace` (0-7) and `opacity` (0.1-1.0) URL query parameters inside the primary streak API route (`app/api/streak/route.ts`). This safely normalizes unexpected or extreme inputs before they are passed down to the SVG geometry renderer. ## Related Issue Closes JhaSourav07#3413 ## Type of Change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ## Checklist - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] My changes generate no new warnings
2 parents 78e59fc + 7c530f6 commit 6f2fa00

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

app/api/streak/route.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,12 @@ export async function GET(request: Request) {
197197
width,
198198
height,
199199
size,
200-
grace,
200+
201+
grace: Math.max(
202+
0,
203+
Math.min(7, typeof grace === 'number' ? grace : parseInt(String(grace || 1), 10))
204+
),
205+
201206
mode,
202207
repo,
203208
org,
@@ -208,7 +213,12 @@ export async function GET(request: Request) {
208213
gradient,
209214
gradient_stops,
210215
gradient_dir,
211-
opacity,
216+
217+
opacity: Math.max(
218+
0.1,
219+
Math.min(1.0, typeof opacity === 'number' ? opacity : parseFloat(String(opacity || 1.0)))
220+
),
221+
212222
disable_particles,
213223
glow,
214224
animate,

0 commit comments

Comments
 (0)