-
Notifications
You must be signed in to change notification settings - Fork 72
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): fix #2598 with cauterizeProperty reuse #2624
Merged
+129
−36
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6aa1605
fix(ses): fix #2598 with cauterizeProperty reuse
erights ba5b3eb
fixup! doccomment
erights 9609166
fixup! review suggestion
erights 4f7a7fc
fixup! partially thread proper reporter into intrinsics.js
erights 6b9c271
fixup! move `console` ref around because XS error
erights 81482e7
fixup! partial review suggestion
erights b9c806a
fixup! review suggestion
erights File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { objectHasOwnProperty } from './commons.js'; | ||
|
||
/** | ||
* @import {Reporter} from './reporting-types.js' | ||
*/ | ||
|
||
/** | ||
* Delete `obj[prop]` or at least make it harmless. | ||
* | ||
* If the property was not expected, then emit a reporter-dependent warning | ||
* to bring attention to this case, so someone can determine what to do with it. | ||
* | ||
* If the property to be deleted is a function's `.prototype` property, this | ||
* will normally be because the function was supposed to be a | ||
* - builtin method or non-constructor function | ||
* - arrow function | ||
* - concise method | ||
* | ||
* all of whom are not supposed to have a `.prototype` property. Nevertheless, | ||
* on some platforms (like older versions of Hermes), or as a result of | ||
* some shim-based mods to the primordials (like core-js?), some of these | ||
* functions may accidentally be more like `function` functions with | ||
* an undeletable `.prototype` property. In these cases, if we can | ||
* set the value of that bogus `.prototype` property to `undefined`, | ||
* we do so, issuing a warning, rather than failing to initialize ses. | ||
* | ||
* @param {object} obj | ||
* @param {PropertyKey} prop | ||
* @param {boolean} known If deletion is expected, don't warn | ||
* @param {string} subPath Used for warning messages | ||
* @param {Reporter} reporter Where to issue warning or error. | ||
* @returns {void} | ||
*/ | ||
export const cauterizeProperty = ( | ||
obj, | ||
prop, | ||
known, | ||
subPath, | ||
{ warn, error }, | ||
) => { | ||
// Either the object lacks a permit or the object doesn't match the | ||
// permit. | ||
// If the permit is specifically false, not merely undefined, | ||
// this is a property we expect to see because we know it exists in | ||
// some environments and we have expressly decided to exclude it. | ||
// Any other disallowed property is one we have not audited and we log | ||
// that we are removing it so we know to look into it, as happens when | ||
// the language evolves new features to existing intrinsics. | ||
if (!known) { | ||
warn(`Removing ${subPath}`); | ||
} | ||
try { | ||
delete obj[prop]; | ||
} catch (err) { | ||
if (objectHasOwnProperty(obj, prop)) { | ||
if (typeof obj === 'function' && prop === 'prototype') { | ||
obj.prototype = undefined; | ||
erights marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (obj.prototype === undefined) { | ||
warn(`Tolerating undeletable ${subPath} === undefined`); | ||
return; | ||
} | ||
} | ||
error(`failed to delete ${subPath}`, err); | ||
} else { | ||
error(`deleting ${subPath} threw`, err); | ||
} | ||
throw err; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/ses/test/tolerate-empty-prototype-toplevel.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* global globalThis */ | ||
import test from 'ava'; | ||
import '../index.js'; | ||
|
||
// See https://github.com/zloirock/core-js/issues/1092 | ||
// See https://github.com/endojs/endo/issues/2598 | ||
const originalEscape = globalThis.escape; | ||
globalThis.escape = function escape(...args) { | ||
return Reflect.apply(originalEscape, this, args); | ||
}; | ||
|
||
lockdown(); | ||
|
||
test('tolerate empty escape.prototype', t => { | ||
t.is(globalThis.escape, escape); | ||
t.assert('prototype' in escape); | ||
t.is(escape.prototype, undefined); | ||
t.deepEqual(Object.getOwnPropertyDescriptor(escape, 'prototype'), { | ||
value: undefined, | ||
writable: !!harden.isFake, | ||
enumerable: false, | ||
configurable: false, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not have the details paged into active brain right now, but this looks like it might be relevant to a mitigation @leotm needs for Hermes support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@leotm , care to comment? Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#2563 (and #2334 ?), right?