Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Resilient to prototype pollution of Intl #517

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/fake-timers-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,12 @@ function withGlobal(_global) {
}

const NativeDate = _global.Date;
const NativeIntl = _global.Intl;
const NativeIntl = isPresent.Intl
? Object.defineProperties(
Object.create(null),
Object.getOwnPropertyDescriptors(_global.Intl),
)
: undefined;
let uniqueTimerId = idCounterStart;

if (NativeDate === undefined) {
Expand Down Expand Up @@ -1107,7 +1112,7 @@ function withGlobal(_global) {
}

if (isPresent.Intl) {
timers.Intl = _global.Intl;
timers.Intl = NativeIntl;
}

const originalSetTimeout = _global.setImmediate || _global.setTimeout;
Expand Down
20 changes: 20 additions & 0 deletions test/issue-516-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use strict";

const { FakeTimers } = require("./helpers/setup-tests");

describe("issue #516 - not resilient to changes on Intl", function () {
it("should successfully install the timer", function () {
const originalIntlProperties = Object.getOwnPropertyDescriptors(
global.Intl,
);
for (const key of Object.keys(originalIntlProperties)) {
delete global.Intl[key];
}
try {
const clock = FakeTimers.createClock();
clock.tick(16);
} finally {
Object.defineProperties(global.Intl, originalIntlProperties);
}
});
});