Skip to content

Commit 165ea52

Browse files
authored
fix: prevent unleash header overwrite (#708)
1 parent 6eaff7e commit 165ea52

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/request.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ export const buildHeaders = ({
8383
head['User-Agent'] = appName;
8484
head['unleash-appname'] = appName;
8585
}
86-
if (connectionId) {
87-
head['unleash-connection-id'] = connectionId;
88-
}
86+
8987
if (instanceId) {
9088
head['UNLEASH-INSTANCEID'] = instanceId;
9189
}
@@ -98,11 +96,15 @@ export const buildHeaders = ({
9896
if (specVersionSupported) {
9997
head['Unleash-Client-Spec'] = specVersionSupported;
10098
}
101-
const version = details.version;
102-
head['unleash-sdk'] = `unleash-client-node:${version}`;
10399
if (custom) {
104100
Object.assign(head, custom);
105101
}
102+
// unleash-connection-id and unleash-sdk should not be overwritten
103+
if (connectionId) {
104+
head['unleash-connection-id'] = connectionId;
105+
}
106+
const version = details.version;
107+
head['unleash-sdk'] = `unleash-client-node:${version}`;
106108
return head;
107109
};
108110

src/test/repository.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ test('should request with correct custom and unleash headers', (t) =>
207207
storageProvider: new InMemStorageProvider(),
208208
headers: {
209209
randomKey,
210+
'unleash-sdk': 'ignore',
211+
'unleash-connection-id': 'ignore',
210212
},
211213
});
212214

0 commit comments

Comments
 (0)