From cb4811e84121b306a640ccdcb96a2dff1448d24b Mon Sep 17 00:00:00 2001 From: dessant Date: Mon, 3 Jun 2024 15:18:57 +0300 Subject: [PATCH] fix: omit cookies from API requests --- src/background/main.js | 20 ++++++++++---------- src/setup/App.vue | 3 --- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/background/main.js b/src/background/main.js index ef50873..be247b5 100644 --- a/src/background/main.js +++ b/src/background/main.js @@ -421,12 +421,12 @@ async function getWitSpeechApiResult(apiKey, audioContent) { const result = {}; const rsp = await fetch('https://api.wit.ai/speech?v=20240304', { - mode: 'cors', method: 'POST', headers: { Authorization: 'Bearer ' + apiKey }, - body: new Blob([audioContent], {type: 'audio/wav'}) + body: new Blob([audioContent], {type: 'audio/wav'}), + credentials: 'omit' }); if (rsp.status !== 200) { @@ -472,9 +472,9 @@ async function getGoogleSpeechApiResult( const rsp = await fetch( `https://speech.googleapis.com/v1p1beta1/speech:recognize?key=${apiKey}`, { - mode: 'cors', method: 'POST', - body: JSON.stringify(data) + body: JSON.stringify(data), + credentials: 'omit' } ); @@ -512,12 +512,12 @@ async function getIbmSpeechApiResult(apiUrl, apiKey, audioContent, model) { if (targetEnv === 'firefox') { const rsp = await fetch('https://iam.cloud.ibm.com/identity/token', { - mode: 'cors', method: 'POST', body: new URLSearchParams({ grant_type: 'urn:ibm:params:oauth:grant-type:apikey', apikey: apiKey - }) + }), + credentials: 'omit' }); if (rsp.status !== 200) { @@ -585,7 +585,6 @@ async function getIbmSpeechApiResult(apiUrl, apiKey, audioContent, model) { const rsp = await fetch( `${apiUrl}/v1/recognize?model=${model}&profanity_filter=false`, { - mode: 'cors', method: 'POST', headers: { Authorization: 'Basic ' + self.btoa('apikey:' + apiKey), @@ -593,7 +592,8 @@ async function getIbmSpeechApiResult(apiUrl, apiKey, audioContent, model) { // Invalid value, see description above Priority: '1' }, - body: new Blob([audioContent], {type: 'audio/wav'}) + body: new Blob([audioContent], {type: 'audio/wav'}), + credentials: 'omit' } ); @@ -617,13 +617,13 @@ async function getMicrosoftSpeechApiResult( const rsp = await fetch( `https://${apiLocation}.stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=${language}&format=detailed&profanity=raw`, { - mode: 'cors', method: 'POST', headers: { 'Ocp-Apim-Subscription-Key': apiKey, 'Content-type': 'audio/wav; codec=audio/pcm; samplerate=16000' }, - body: new Blob([audioContent], {type: 'audio/wav'}) + body: new Blob([audioContent], {type: 'audio/wav'}), + credentials: 'omit' } ); diff --git a/src/setup/App.vue b/src/setup/App.vue index 5c717e7..ceaa780 100644 --- a/src/setup/App.vue +++ b/src/setup/App.vue @@ -136,7 +136,6 @@ export default { data.append('session', this.session); await fetch(`${this.apiUrl}/setup/close`, { - mode: 'cors', method: 'POST', body: data }); @@ -150,7 +149,6 @@ export default { data.append('targetEnv', this.$env.targetEnv); const rsp = await fetch(`${this.apiUrl}/setup/location`, { - mode: 'cors', method: 'POST', body: data }); @@ -175,7 +173,6 @@ export default { data.append('extension', this.getExtensionId()); const rsp = await fetch(`${this.apiUrl}/setup/install`, { - mode: 'cors', method: 'POST', body: data });