Skip to content

Commit

Permalink
feat: [FFM-10455]: Add defensive code around btoa usage (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
knagurski authored Jan 24, 2024
1 parent dd1f952 commit fc679ab
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/preact/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/react-redux/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/react/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@harnessio/ff-javascript-client-sdk",
"version": "1.22.0",
"version": "1.23.0",
"author": "Harness",
"license": "Apache-2.0",
"main": "dist/sdk.cjs.js",
Expand Down
12 changes: 7 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Streamer } from './stream'
import { getVariation } from './variation'
import Poller from './poller'

const SDK_VERSION = '1.22.0'
const SDK_VERSION = '1.23.0'
const SDK_INFO = `Javascript ${SDK_VERSION} Client`
const METRICS_VALID_COUNT_INTERVAL = 500
const fetch = globalThis.fetch
Expand Down Expand Up @@ -309,11 +309,13 @@ const initialize = (apiKey: string, target: Target, options?: Options): Result =
'Harness-SDK-Info': SDK_INFO
}

const targetHeader = btoa(JSON.stringify(target))
if (globalThis.btoa) {
const targetHeader = globalThis.btoa(JSON.stringify(target))

// ensure encoded target is less than 1/4 of 1 MB
if (targetHeader.length < 262144) {
standardHeaders['Harness-Target'] = targetHeader
// ensure encoded target is less than 1/4 of 1 MB
if (targetHeader.length < 262144) {
standardHeaders['Harness-Target'] = targetHeader
}
}

logDebug('Authenticated', decoded)
Expand Down

0 comments on commit fc679ab

Please sign in to comment.