From 06a4bc2517cc73bc4bfd5ed9f1bc6397e6f93e0f Mon Sep 17 00:00:00 2001 From: aaydinks Date: Wed, 27 May 2026 20:04:55 -0700 Subject: [PATCH] fix(ai-quiz): cap verify payload question length 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 6580a0a28c63..33267165f4e9 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', },