fix: prevent TypeError in TTS useEffect by capturing text in local variable#10536
Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
Draft
fix: prevent TypeError in TTS useEffect by capturing text in local variable#10536roomote-v0[bot] wants to merge 1 commit intomainfrom
roomote-v0[bot] wants to merge 1 commit intomainfrom
Conversation
…riable Fixes #10468 The error "Q.text.startsWith is not a function" occurred because lastMessage.text could potentially change between the type check (typeof lastMessage.text === "string") and the startsWith call. This fix captures lastMessage.text in a local variable before performing any operations on it, preventing the TOCTOU (time-of-check-time-of-use) vulnerability.
Contributor
Author
Review complete. No issues found. The fix correctly captures Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.