fix: prevent TypeError in TTS useEffect by capturing text in local variable #10536
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related GitHub Issue
Closes: #10468
Description
This PR attempts to address Issue #10468. Feedback and guidance are welcome.
The error
TypeError: Q.text.startsWith is not a functionoccurred in the TTS (text-to-speech)useEffecthook inChatView.tsx. The root cause was a TOCTOU (time-of-check-time-of-use) vulnerability where:typeof lastMessage.text === "string"on line 1019lastMessage.text.startsWith("{")on line 1022Between these two evaluations,
lastMessage.textcould potentially change to a non-string value (possibly from malformed API responses from certain models like qwen3-coder).The fix: Capture
lastMessage.textin a local variable (messageText) before performing any type checks or operations on it. This ensures we check and use the same value throughout, preventing any potential race conditions or type mismatches.Test Procedure
webview-ui/src/components/chatpassThe fix is defensive and maintains the existing behavior while adding robustness against edge cases where the message text might not be a string.
Pre-Submission Checklist
Screenshots / Videos
N/A - This is a bug fix in the TTS logic with no UI changes.
Documentation Updates
Additional Notes
This is a minimal, defensive fix that prevents the TOCTOU issue by ensuring we use a stable reference to the text value throughout the condition evaluation and subsequent processing.
Important
Fixes TypeError in TTS useEffect in
ChatView.tsxby capturinglastMessage.textin a local variable to prevent TOCTOU issues.TypeError: Q.text.startsWith is not a functionin TTSuseEffectinChatView.tsx.lastMessage.textin a local variablemessageTextto prevent TOCTOU issues.messageTextis checked and used consistently to avoid type mismatches.webview-ui/src/components/chatpass.This description was created by
for f4eb1e1. You can customize this summary. It will automatically update as commits are pushed.