fix: Remove Exposed Speech Service API Key from Network Calls #1869
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.
Purpose
The purpose of this pull request is to enhance the security of the Speech Synthesis integration by eliminating the exposure of the Azure Speech API key in browser network calls.
Previously, the frontend received and used the Speech API subscription key directly to initialize the speech synthesizer, which could be viewed in browser developer tools. While access to the app is restricted via Entra ID, exposing sensitive keys in client-side code is still a security risk.
To resolve this, we have:
This change ensures sensitive credentials are no longer exposed to end users and follows best practices for secure API consumption.
Backend changes:
key
field from thespeech_config
response incode/create_app.py
, as the backend no longer provides the subscription key.Frontend changes:
key
field withtoken
in thesynthesizerData
state inAnswer.tsx
.initializeSynthesizer
function to useSpeechConfig.fromAuthorizationToken
instead ofSpeechConfig.fromSubscription
, reflecting the switch to token-based authentication.useEffect
logic to check for a non-emptytoken
instead ofkey
before initializing the synthesizer.fetchSynthesizerData
function to set thetoken
field insynthesizerData
instead ofkey
. Minor formatting improvement was also made to the error logging.Does this introduce a breaking change?
How to Test
What to Check
Verify that the following are valid: