Skip to content

Commit 789a454

Browse files
committed
Fix possible prototype pollution bug.
1 parent 6274032 commit 789a454

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

shared/AppInsightsCore/src/core/SdkStatsNotificationCbk.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export function createSdkStatsNotifCbk(cfg: ISdkStatsConfig): ISdkStatsNotifCbk
9494

9595
function _getTelType(item: ITelemetryItem): string {
9696
var bt = item.baseType;
97-
return (bt && _typeMap[bt]) || "CUSTOM_EVENT";
97+
return (bt && objHasOwn(_typeMap, bt) && _typeMap[bt]) || "CUSTOM_EVENT";
9898
}
9999

100100
function _isSdkStatsMetric(item: ITelemetryItem): boolean {
@@ -113,10 +113,13 @@ export function createSdkStatsNotifCbk(cfg: ISdkStatsConfig): ISdkStatsNotifCbk
113113
}
114114

115115
function _incDropped(items: ITelemetryItem[], code: string) {
116-
if (!_droppedCounts[code]) {
117-
_droppedCounts[code] = {};
116+
var bucket: { [telType: string]: number };
117+
if (objHasOwn(_droppedCounts, code)) {
118+
bucket = _droppedCounts[code];
119+
} else {
120+
bucket = {};
121+
_droppedCounts[code] = bucket;
118122
}
119-
var bucket = _droppedCounts[code];
120123
for (var i = 0; i < items.length; i++) {
121124
if (!_isSdkStatsMetric(items[i])) {
122125
var t = _getTelType(items[i]);
@@ -127,10 +130,13 @@ export function createSdkStatsNotifCbk(cfg: ISdkStatsConfig): ISdkStatsNotifCbk
127130
}
128131

129132
function _incRetry(items: ITelemetryItem[], code: string) {
130-
if (!_retryCounts[code]) {
131-
_retryCounts[code] = {};
133+
var bucket: { [telType: string]: number };
134+
if (objHasOwn(_retryCounts, code)) {
135+
bucket = _retryCounts[code];
136+
} else {
137+
bucket = {};
138+
_retryCounts[code] = bucket;
132139
}
133-
var bucket = _retryCounts[code];
134140
for (var i = 0; i < items.length; i++) {
135141
if (!_isSdkStatsMetric(items[i])) {
136142
var t = _getTelType(items[i]);

0 commit comments

Comments
 (0)