Skip to content

Commit

Permalink
fix: strip private attributes from bootstrap user (#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
tore-statsig authored Aug 6, 2024
1 parent 4c6c6c4 commit 7bdbd13
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/Evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import SpecStore, { APIEntityNames } from './SpecStore';
import { ExplicitStatsigOptions, InitStrategy } from './StatsigOptions';
import { ClientInitializeResponseOptions } from './StatsigServer';
import { StatsigUser } from './StatsigUser';
import { getSDKType, getSDKVersion, notEmpty } from './utils/core';
import { cloneEnforce, getSDKType, getSDKVersion } from './utils/core';
import {
djb2Hash,
HashingAlgorithm,
Expand Down Expand Up @@ -219,14 +219,15 @@ export default class Evaluator {
}

public getClientInitializeResponse(
user: StatsigUser,
inputUser: StatsigUser,
_ctx: StatsigContext,
clientSDKKey?: string,
options?: ClientInitializeResponseOptions,
): ClientInitializeResponse | null {
if (!this.store.isServingChecks()) {
return null;
}
const user = cloneEnforce(inputUser);
const clientKeyToAppMap = this.store.getClientKeyToAppMap();
let targetAppID: string | null = null;
let targetEntities: APIEntityNames | null = null;
Expand Down Expand Up @@ -364,6 +365,7 @@ export default class Evaluator {
evaluatedKeys['customIDs'] = user.customIDs;
}

delete user.privateAttributes;
this.deleteUndefinedFields(user);

return {
Expand Down
3 changes: 1 addition & 2 deletions src/LogEventProcessor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ConfigEvaluation from './ConfigEvaluation';
import Diagnostics, { ContextType, Marker } from './Diagnostics';
import Diagnostics, { Marker } from './Diagnostics';
import ErrorBoundary from './ErrorBoundary';
import { StatsigLocalModeNetworkError } from './Errors';
import { EvaluationDetails } from './EvaluationDetails';
import LogEvent, { LogEventData } from './LogEvent';
import OutputLogger from './OutputLogger';
Expand Down
5 changes: 5 additions & 0 deletions src/utils/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ function clone<T>(obj: T | null): T | null {
return JSON.parse(JSON.stringify(obj));
}

function cloneEnforce<T>(obj: T): T {
return JSON.parse(JSON.stringify(obj));
}

// Return a number if num can be parsed to a number, otherwise return null
function getNumericValue(num: unknown): number | null {
if (num == null) {
Expand Down Expand Up @@ -112,6 +116,7 @@ function getTypeOf(value: unknown) {

export {
clone,
cloneEnforce,
getBoolValue,
getNumericValue,
getSDKVersion,
Expand Down

0 comments on commit 7bdbd13

Please sign in to comment.