An Azure service that integrates speech processing into apps and services.
Hi Brett Jewell
Welcome to Microsoft Q&A,
Passing an Azure AD access token directly to a browser client for Cognitive Services (e.g., Speech SDK) is not recommended for security reasons. Here’s why and what you should do instead:
It’s Risky
- Exposure of a powerful token: An Azure AD access token typically grants broad permissions tied to the user or app identity. If leaked (e.g., via browser dev tools, logs, or XSS), it could be misused to access other Azure resources.
- Longer lifetime than /issueToken: Unlike the short-lived token from
/issueToken(usually ~10 minutes), Azure AD tokens often last 1 hour or more, increasing the attack window. - No resource scoping: The token might allow access beyond Speech services unless you strictly scope it to the Speech resource.
Recommended Alternatives
- Use a Backend Token Broker
- Implement a secure server-side component that:
- Authenticates with Azure AD.
- Exchanges the token for a short-lived Speech service token (or signs requests if using private endpoints).
- Returns only the minimal token to the browser.
- This mimics
/issueTokenbehavior and keeps sensitive credentials off the client.
- Enable Managed Identity or Service Principal
- For private endpoints, authenticate your backend using a managed identity or service principal.
- The backend then calls Speech service and streams audio results to the client (instead of exposing tokens).
- If Direct Token Use Is Unavoidable
- Scope the token: Request an access token for the Speech resource only (
https://cognitiveservices.azure.com/.default). - Use HTTPS and secure storage: Never store tokens in localStorage; keep them in memory.
- Shorten lifetime: Use conditional access or token lifetime policies to minimize exposure.
- Scope the token: Request an access token for the Speech resource only (
Notes:
- Never expose long-lived or broadly scoped tokens to the browser.
- Always prefer a backend proxy pattern for private endpoints.
- If you must use Azure AD tokens in the browser, apply strict scoping and lifetime controls.
I Hope this helps. Do let me know if you have any further queries.
Thank you!