Skip to content

Commit

Permalink
fix: prevent unleash header overwrite (#708)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew authored Feb 6, 2025
1 parent 6eaff7e commit 165ea52
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ export const buildHeaders = ({
head['User-Agent'] = appName;
head['unleash-appname'] = appName;
}
if (connectionId) {
head['unleash-connection-id'] = connectionId;
}

if (instanceId) {
head['UNLEASH-INSTANCEID'] = instanceId;
}
Expand All @@ -98,11 +96,15 @@ export const buildHeaders = ({
if (specVersionSupported) {
head['Unleash-Client-Spec'] = specVersionSupported;
}
const version = details.version;
head['unleash-sdk'] = `unleash-client-node:${version}`;
if (custom) {
Object.assign(head, custom);
}
// unleash-connection-id and unleash-sdk should not be overwritten
if (connectionId) {
head['unleash-connection-id'] = connectionId;
}
const version = details.version;
head['unleash-sdk'] = `unleash-client-node:${version}`;
return head;
};

Expand Down
2 changes: 2 additions & 0 deletions src/test/repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ test('should request with correct custom and unleash headers', (t) =>
storageProvider: new InMemStorageProvider(),
headers: {
randomKey,
'unleash-sdk': 'ignore',
'unleash-connection-id': 'ignore',
},
});

Expand Down

0 comments on commit 165ea52

Please sign in to comment.