Skip to content

Commit

Permalink
fix(ses): warn on unsupported lockdownOptions mathTaming + dateTaming
Browse files Browse the repository at this point in the history
  • Loading branch information
kumavis committed Nov 20, 2024
1 parent b3f0c56 commit 50c924f
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 20 deletions.
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

0 comments on commit 50c924f

Please sign in to comment.