Skip to content

Commit ef45855

Browse files
Bugfix - Sanitize the header value to avoid exceptions on HTTP/S requests
1 parent 8378a63 commit ef45855

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
- Updated the Redis storage to avoid lazy require of the `ioredis` dependency when the SDK is initialized.
33
- Bugfix - Enhanced HTTP client module to implement timeouts for failing requests that might otherwise remain pending indefinitely on some Fetch API implementations, pausing the SDK synchronization process.
44
- Bugfix - Properly handle rejected promises when using targeting rules with segment matchers in consumer modes (e.g., Redis and Pluggable storages).
5+
- Bugfix - Sanitize the `SplitSDKMachineName` header value to avoid exceptions on HTTP/S requests when it contains non ISO-8859-1 characters (Related to issue https://github.com/splitio/javascript-client/issues/847).
56

67
1.17.0 (September 6, 2024)
78
- Added `sync.requestOptions.getHeaderOverrides` configuration option to enhance SDK HTTP request Headers for Authorization Frameworks.

src/services/__tests__/decorateHeaders.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ISettings } from '../../types';
2-
import { decorateHeaders } from '../decorateHeaders';
2+
import { decorateHeaders, removeNonISO88591 } from '../decorateHeaders';
33

44
const HEADERS = {
55
Authorization: 'Bearer SDK-KEY',
@@ -48,3 +48,10 @@ describe('decorateHeaders', () => {
4848
expect(settings.log.error).toHaveBeenCalledWith('Problem adding custom headers to request decorator: Error: Unexpected error');
4949
});
5050
});
51+
52+
test('removeNonISO88591', () => {
53+
expect(removeNonISO88591('')).toBe('');
54+
expect(removeNonISO88591('This is a test')).toBe('This is a test');
55+
expect(removeNonISO88591('This is a test ó \u0FFF 你')).toBe('This is a test ó ');
56+
expect(removeNonISO88591('Emiliano’s-MacBook-Pro')).toBe('Emilianos-MacBook-Pro');
57+
});

src/services/decorateHeaders.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,8 @@ export function decorateHeaders(settings: ISettings, headers: Record<string, str
3131
}
3232
return headers;
3333
}
34+
35+
export function removeNonISO88591(input: string) {
36+
// eslint-disable-next-line no-control-regex
37+
return input.replace(/[^\x00-\xFF]/g, '');
38+
}

src/services/splitHttpClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { objectAssign } from '../utils/lang/objectAssign';
33
import { ERROR_HTTP, ERROR_CLIENT_CANNOT_GET_READY } from '../logger/constants';
44
import { ISettings } from '../types';
55
import { IPlatform } from '../sdkFactory/types';
6-
import { decorateHeaders } from './decorateHeaders';
6+
import { decorateHeaders, removeNonISO88591 } from './decorateHeaders';
77
import { timeout } from '../utils/promise/timeout';
88

99
const PENDING_FETCH_ERROR_TIMEOUT = 100;
@@ -32,7 +32,7 @@ export function splitHttpClientFactory(settings: ISettings, { getOptions, getFet
3232
};
3333

3434
if (ip) commonHeaders['SplitSDKMachineIP'] = ip;
35-
if (hostname) commonHeaders['SplitSDKMachineName'] = hostname;
35+
if (hostname) commonHeaders['SplitSDKMachineName'] = removeNonISO88591(hostname);
3636

3737
return function httpClient(url: string, reqOpts: IRequestOptions = {}, latencyTracker: (error?: NetworkError) => void = () => { }, logErrorsAsInfo: boolean = false): Promise<IResponse> {
3838

0 commit comments

Comments
 (0)