-
Notifications
You must be signed in to change notification settings - Fork 207
Autoselect owner/repo on homepage via query params #200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional Suggestion:
Same issue as in the chat page: parseInt without NaN validation can produce NaN if the cookie contains an invalid value.
View Details
📝 Patch Details
diff --git a/app/chat/[owner]/[repo]/page.tsx b/app/chat/[owner]/[repo]/page.tsx
index 55d71a0..7c703ed 100644
--- a/app/chat/[owner]/[repo]/page.tsx
+++ b/app/chat/[owner]/[repo]/page.tsx
@@ -21,7 +21,8 @@ export default async function ChatPage({ params }: ChatPageProps) {
// Get max sandbox duration for this user (user-specific > global > env var)
const maxSandboxDuration = await getMaxSandboxDuration(session?.user?.id)
- const maxDuration = parseInt(cookieStore.get('max-duration')?.value || maxSandboxDuration.toString(), 10)
+ const maxDurationValue = parseInt(cookieStore.get('max-duration')?.value || maxSandboxDuration.toString(), 10)
+ const maxDuration = isNaN(maxDurationValue) ? maxSandboxDuration : maxDurationValue
const stars = await getGitHubStars()
diff --git a/app/page.tsx b/app/page.tsx
index 137899a..ee6877c 100644
--- a/app/page.tsx
+++ b/app/page.tsx
@@ -15,7 +15,8 @@ export default async function Home() {
// Get max sandbox duration for this user (user-specific > global > env var)
const maxSandboxDuration = await getMaxSandboxDuration(session?.user?.id)
- const maxDuration = parseInt(cookieStore.get('max-duration')?.value || maxSandboxDuration.toString(), 10)
+ const maxDurationValue = parseInt(cookieStore.get('max-duration')?.value || maxSandboxDuration.toString(), 10)
+ const maxDuration = isNaN(maxDurationValue) ? maxSandboxDuration : maxDurationValue
const stars = await getGitHubStars()
Analysis
parseInt without NaN validation allows invalid maxDuration in cookie
What fails: parseInt() on invalid cookie values returns NaN instead of the fallback maxSandboxDuration, causing the UI Select component to render without a valid selected value and breaking the task form initialization.
How to reproduce:
- Navigate to the home page or chat page
- Manually tamper with the browser's 'max-duration' cookie and set it to a non-numeric value, e.g.:
max-duration=invalid_value - Reload the page
- The Maximum Duration select component renders without a selected value
Result: The component receives NaN for initialMaxDuration, which causes:
- Line 685 in
components/task-form.tsx:maxDuration.toString()produces"NaN" - The Select component can't match
"NaN"against valid options like"5","10", etc. - The UI displays an empty select field instead of a valid duration
Expected behavior: When a cookie contains an invalid value, the code should fall back to maxSandboxDuration (a valid number guaranteed by getMaxSandboxDuration()), ensuring maxDuration is always a valid number.
Fix: Added NaN validation after parsing:
const maxDurationValue = parseInt(cookieStore.get('max-duration')?.value || maxSandboxDuration.toString(), 10)
const maxDuration = isNaN(maxDurationValue) ? maxSandboxDuration : maxDurationValueThis matches the pattern used in lib/utils/cookies.ts getMaxDuration() function and ensures server-side consistency with client-side validation.
Affected files:
app/page.tsx(line 18)app/chat/[owner]/[repo]/page.tsx(line 23)
|
|
||
| // Get max sandbox duration for this user (user-specific > global > env var) | ||
| const maxSandboxDuration = await getMaxSandboxDuration(session?.user?.id) | ||
| const maxDuration = parseInt(cookieStore.get('max-duration')?.value || maxSandboxDuration.toString(), 10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| const maxDuration = parseInt(cookieStore.get('max-duration')?.value || maxSandboxDuration.toString(), 10) | |
| const parsedDuration = parseInt(cookieStore.get('max-duration')?.value || '', 10) | |
| const maxDuration = !isNaN(parsedDuration) ? parsedDuration : maxSandboxDuration |
The parseInt call without NaN validation can produce NaN if the cookie contains an invalid value, which will cause UI issues in the form component where NaN.toString() won't match any valid select options.
View Details
Analysis
NaN value from unvalidated parseInt on invalid cookie breaks Select component in task form
What fails: ChatPage server component in app/chat/[owner]/[repo]/page.tsx at line 24 fails to validate the result of parseInt() when parsing the max-duration cookie. If the cookie contains any non-empty invalid string (e.g., "abc", "xyz"), parseInt returns NaN. This NaN value is then passed to ChatPageContent as initialMaxDuration and used in the task form's Select component at components/task-form.tsx line 685, where NaN.toString() produces the string "NaN" which doesn't match any valid SelectItem value, causing the form to display without a selected value.
How to reproduce:
- Open browser DevTools and set the cookie:
max-duration=abc - Navigate to the chat page (e.g.,
/chat/owner/repo) - Open the Settings dropdown (⚙️ icon)
- Look at the "Maximum Duration" select field
Result: The Maximum Duration select field shows no selected value (empty placeholder instead of a valid duration like "5 minutes"). The field value is set to the invalid string "NaN" which doesn't match any option.
Expected: The Maximum Duration select should always display a valid value. According to the established pattern in lib/utils/cookies.ts lines 206-209 (getMaxDuration() function), invalid cookie values should fall back to the valid maxSandboxDuration value, ensuring the select always has a matching option.
Root cause: The code uses parseInt(cookieStore.get('max-duration')?.value || maxSandboxDuration.toString(), 10) which only applies the fallback to empty strings. Non-empty invalid strings like "abc" are parsed by parseInt, producing NaN without any validation. The fix applies the same validation pattern used throughout the codebase: parse the value with parseInt(), check isNaN(), and fall back to the default if the result is invalid.
No description provided.