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): Handle well-known symbol look-alikes #1114

Merged
merged 2 commits into from
Mar 16, 2022

Conversation

mhofman
Copy link
Contributor

@mhofman mhofman commented Mar 15, 2022

While working on fixing the async_hooks issue, I realized that the whitelisting mechanism for well-known symbols can be tricked into accepting a unique symbol that just has the description of the expected well-known symbol, but is actually unique.

This PR changes the whitelist parsing logic to generate a map of well-known symbols from the intrinsics and the permit list (similar to marshal's logic), and checks that a symbol matches the well-known symbol when found in the permits of an object. It does so by returning a name in the shape of UniqueSymbol(description) when finding a symbol that isn't well-known, and only returning the @@name if the symbol is found in the map. This technically would allow unique symbols to be permitted on intrinsics if named similarly (there is technically a chance of collision with string props, but that was already the case with the @@ prefix anyway).

Added a unit test for this (renaming the existing test, which seemed to be testing a different file). Verified manually that before the fix, the test would fail (didn't create separate commit with failing test)

if (wellKnownSymbol) {
return wellKnownSymbol;
} else {
return `Unique${String(prop)}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to document the nature of UniqueSymbol(…) (and string representation of property keys in general) somewhere, although I'm not sure where.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t.is(
ArrayProto[RogueSymbolIterator],
undefined,
`Well-known Symbol look-alike should have been removed`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there also be an assertion about SymbolIterator, e.g. that it is not removed from an object where it is expected?

Copy link
Contributor Author

@mhofman mhofman Mar 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 8fc6c2b

Copy link
Contributor

@erights erights left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@mhofman mhofman force-pushed the mhofman/fix-well-known-symbol-whitelist branch 2 times, most recently from 9d2b638 to 6f6fffb Compare March 16, 2022 01:59
@mhofman
Copy link
Contributor Author

mhofman commented Mar 16, 2022

@erights after our discussion I added support for Registered symbols in 6f6fffb

@@ -72,6 +72,8 @@ export const {
toStringTag: toStringTagSymbol,
iterator: iteratorSymbol,
matchAll: matchAllSymbol,
keyFor: SymbolKeyFor,
for: SymbolFor,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elsewhere, as in arrayPrototype, there’s precedent for camelCase over PascalCase.

Copy link
Contributor Author

@mhofman mhofman Mar 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually thinking about this more, that means we don't differentiate between static and proto methods?

Edit: answering my own question, with examples like reflectSet, the answer seem to be "no".

@mhofman mhofman force-pushed the mhofman/fix-well-known-symbol-whitelist branch from 6f6fffb to 899a957 Compare March 16, 2022 23:43
@mhofman mhofman force-pushed the mhofman/fix-well-known-symbol-whitelist branch from 899a957 to 5139dad Compare March 16, 2022 23:46
@mhofman mhofman enabled auto-merge March 16, 2022 23:47
@mhofman mhofman merged commit a808fec into master Mar 16, 2022
@mhofman mhofman deleted the mhofman/fix-well-known-symbol-whitelist branch March 16, 2022 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants