From 64d19438042921e89c522f022327ead85b286e9f Mon Sep 17 00:00:00 2001 From: Thodoris Greasidis Date: Wed, 26 Feb 2025 14:24:57 +0200 Subject: [PATCH] Fix CORS issue with X-Balena-Client header Change-type: patch See: https://balena.fibery.io/Work/Project/Extend-the-X-Balena-Client-header-to-include-the-UI-CLI-version-as-well-1174 --- src/utils/lazy.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/utils/lazy.ts b/src/utils/lazy.ts index b50d7dd8..a8ca2ed0 100644 --- a/src/utils/lazy.ts +++ b/src/utils/lazy.ts @@ -46,9 +46,13 @@ export const onceAsync = (fn: () => Promise) => { const cliXBalenaClientHeaderInterceptor: BalenaSdk.Interceptor = { request($request) { - // We intentionally overwrite the sdk version string from the header - // to conserve bandwidth. - $request.headers['X-Balena-Client'] = `balena-cli/${version}`; + if ($request.headers['X-Balena-Client']) { + // We intentionally overwrite the sdk version string from the header + // to conserve bandwidth. We only do that when the SDK already has specified + // the X-Balena-Client header, since that signals that this is a safe url to + // include the extra header and will not cause CORS errors. + $request.headers['X-Balena-Client'] = `balena-cli/${version}`; + } return $request; }, };