From 3262e7a588e13e84f34f2d0091a4d2db6e807892 Mon Sep 17 00:00:00 2001 From: aaydinks Date: Thu, 25 Jun 2026 07:19:04 -0700 Subject: [PATCH] fix(ai-quiz): cap verify payload question length (#10026) The verify endpoint rejects questions longer than 500 characters. Trim the question payload to the server limit to avoid blocking quiz attempts. Fixes #10019 Co-authored-by: Cursor --- src/hooks/use-verify-answer.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/hooks/use-verify-answer.ts b/src/hooks/use-verify-answer.ts index 6580a0a28..33267165f 100644 --- a/src/hooks/use-verify-answer.ts +++ b/src/hooks/use-verify-answer.ts @@ -18,6 +18,8 @@ type UseVerifyAnswerOptions = { onFinish?: (data: VerifyAnswerResponse) => void; }; +const MAX_QUIZ_QUESTION_LENGTH = 500; + export function useVerifyAnswer(options: UseVerifyAnswerOptions) { const { quizSlug, question, userAnswer, onError, onFinish } = options; @@ -36,6 +38,11 @@ export function useVerifyAnswer(options: UseVerifyAnswerOptions) { abortControllerRef.current?.abort(); abortControllerRef.current = new AbortController(); + const safeQuestion = + question.length > MAX_QUIZ_QUESTION_LENGTH + ? question.slice(0, MAX_QUIZ_QUESTION_LENGTH) + : question; + const response = await fetch( `${import.meta.env.PUBLIC_API_URL}/v1-verify-quiz-answer/${quizSlug}`, { @@ -43,7 +50,7 @@ export function useVerifyAnswer(options: UseVerifyAnswerOptions) { headers: { 'Content-Type': 'application/json', }, - body: JSON.stringify({ question, userAnswer }), + body: JSON.stringify({ question: safeQuestion, userAnswer }), signal: abortControllerRef.current?.signal, credentials: 'include', },