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(ses): warn on unsupported lockdownOptions mathTaming + dateTaming #2584

Merged
merged 1 commit into from
Nov 20, 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
4 changes: 4 additions & 0 deletions packages/ses/NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
User-visible changes in `ses`:

# Next version

- Specifying the long discontinued `mathTaming` or `dateTaming` options logs a warning.

# v1.10.0 (2024-11-13)

- Permit [Promise.try](https://github.com/tc39/proposal-promise-try),
Expand Down
22 changes: 18 additions & 4 deletions packages/ses/src/lockdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ export const repairIntrinsics = (options = {}) => {
'safe',
),
__hardenTaming__ = getenv('LOCKDOWN_HARDEN_TAMING', 'safe'),
dateTaming = 'safe', // deprecated
mathTaming = 'safe', // deprecated
dateTaming, // deprecated
mathTaming, // deprecated
...extraOptions
} = options;

Expand All @@ -215,6 +215,20 @@ export const repairIntrinsics = (options = {}) => {
Fail`lockdown(): non supported option ${q(extraOptionsNames)}`;

const reporter = chooseReporter(reporting);
const { warn } = reporter;

if (dateTaming !== undefined) {
// eslint-disable-next-line no-console
warn(
`SES The 'dateTaming' option is deprecated and does nothing. In the future specifying it will be an error.`,
);
}
if (mathTaming !== undefined) {
// eslint-disable-next-line no-console
warn(
`SES The 'mathTaming' option is deprecated and does nothing. In the future specifying it will be an error.`,
);
}

priorRepairIntrinsics === undefined ||
// eslint-disable-next-line @endo/no-polymorphic-call
Expand Down Expand Up @@ -289,9 +303,9 @@ export const repairIntrinsics = (options = {}) => {

addIntrinsics(tameFunctionConstructors());

addIntrinsics(tameDateConstructor(dateTaming));
addIntrinsics(tameDateConstructor());
addIntrinsics(tameErrorConstructor(errorTaming, stackFiltering));
addIntrinsics(tameMathObject(mathTaming));
addIntrinsics(tameMathObject());
addIntrinsics(tameRegExpConstructor(regExpTaming));
addIntrinsics(tameSymbolConstructor());
addIntrinsics(shimArrayBufferTransfer());
Expand Down
5 changes: 1 addition & 4 deletions packages/ses/src/tame-date-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import {
defineProperties,
} from './commons.js';

export default function tameDateConstructor(dateTaming = 'safe') {
if (dateTaming !== 'safe' && dateTaming !== 'unsafe') {
throw TypeError(`unrecognized dateTaming ${dateTaming}`);
}
export default function tameDateConstructor() {
const OriginalDate = Date;
const DatePrototype = OriginalDate.prototype;

Expand Down
5 changes: 1 addition & 4 deletions packages/ses/src/tame-math-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import {
objectPrototype,
} from './commons.js';

export default function tameMathObject(mathTaming = 'safe') {
if (mathTaming !== 'safe' && mathTaming !== 'unsafe') {
throw TypeError(`unrecognized mathTaming ${mathTaming}`);
}
export default function tameMathObject() {
const originalMath = Math;
const initialMath = originalMath; // to follow the naming pattern

Expand Down
2 changes: 0 additions & 2 deletions packages/ses/test/_lockdown-unsafe.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
lockdown({
dateTaming: 'unsafe',
mathTaming: 'unsafe',
errorTaming: 'unsafe',
});
4 changes: 2 additions & 2 deletions packages/ses/test/lockdown-options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { repairIntrinsics } from '../src/lockdown.js';

test('repairIntrinsics throws with non-recognized options', t => {
t.throws(
() => repairIntrinsics({ mathTaming: 'unsafe', abc: true }),
() => repairIntrinsics({ abc: true }),
undefined,
'throws with value true',
);
t.throws(
() => repairIntrinsics({ mathTaming: 'unsafe', abc: false }),
() => repairIntrinsics({ abc: false }),
undefined,
'throws with value false',
);
Expand Down
10 changes: 8 additions & 2 deletions packages/ses/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ export interface RepairOptions {
reporting?: 'platform' | 'console' | 'none';
unhandledRejectionTrapping?: 'report' | 'none';
errorTaming?: 'safe' | 'unsafe' | 'unsafe-debug';
dateTaming?: 'safe' | 'unsafe'; // deprecated
mathTaming?: 'safe' | 'unsafe'; // deprecated
/**
* @deprecated Deprecated and does nothing. In the future specifying it will be an error.
*/
dateTaming?: 'safe' | 'unsafe';
/**
* @deprecated Deprecated and does nothing. In the future specifying it will be an error.
*/
mathTaming?: 'safe' | 'unsafe';
evalTaming?: 'safeEval' | 'unsafeEval' | 'noEval';
stackFiltering?: 'concise' | 'verbose';
overrideTaming?: 'moderate' | 'min' | 'severe';
Expand Down
2 changes: 0 additions & 2 deletions packages/ses/types.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ lockdown();
lockdown({});
lockdown({ errorTaming: 'unsafe' });
lockdown({
mathTaming: 'unsafe',
dateTaming: 'unsafe',
errorTaming: 'unsafe',
localeTaming: 'unsafe',
consoleTaming: 'unsafe',
Expand Down
Loading