Skip to content

Commit 656733c

Browse files
authored
fix: Resilient to prototype pollution of Intl (#517)
1 parent ff8d907 commit 656733c

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/fake-timers-src.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,12 @@ function withGlobal(_global) {
206206
}
207207

208208
const NativeDate = _global.Date;
209-
const NativeIntl = _global.Intl;
209+
const NativeIntl = isPresent.Intl
210+
? Object.defineProperties(
211+
Object.create(null),
212+
Object.getOwnPropertyDescriptors(_global.Intl),
213+
)
214+
: undefined;
210215
let uniqueTimerId = idCounterStart;
211216

212217
if (NativeDate === undefined) {
@@ -1107,7 +1112,7 @@ function withGlobal(_global) {
11071112
}
11081113

11091114
if (isPresent.Intl) {
1110-
timers.Intl = _global.Intl;
1115+
timers.Intl = NativeIntl;
11111116
}
11121117

11131118
const originalSetTimeout = _global.setImmediate || _global.setTimeout;

test/issue-516-test.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"use strict";
2+
3+
const { FakeTimers } = require("./helpers/setup-tests");
4+
5+
describe("issue #516 - not resilient to changes on Intl", function () {
6+
it("should successfully install the timer", function () {
7+
const originalIntlProperties = Object.getOwnPropertyDescriptors(
8+
global.Intl,
9+
);
10+
for (const key of Object.keys(originalIntlProperties)) {
11+
delete global.Intl[key];
12+
}
13+
try {
14+
const clock = FakeTimers.createClock();
15+
clock.tick(16);
16+
} finally {
17+
Object.defineProperties(global.Intl, originalIntlProperties);
18+
}
19+
});
20+
});

0 commit comments

Comments
 (0)