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

DOMException's name->code mapping object observably accesses userland mutable Object.prototype #12927

Closed
ghost opened this issue Nov 28, 2021 · 0 comments · Fixed by #15097
Closed
Labels
bug Something isn't working correctly

Comments

@ghost
Copy link

ghost commented Nov 28, 2021

Erroneous example code:

const new_code = 100;
Object.prototype.s = new_code;
console.log(new_code === new DOMException("", "s").code);

result: true.
This is a result of using a plain JS object here:

const nameToCodeMapping = {
IndexSizeError: INDEX_SIZE_ERR,
HierarchyRequestError: HIERARCHY_REQUEST_ERR,
WrongDocumentError: WRONG_DOCUMENT_ERR,
InvalidCharacterError: INVALID_CHARACTER_ERR,
NoModificationAllowedError: NO_MODIFICATION_ALLOWED_ERR,
NotFoundError: NOT_FOUND_ERR,
NotSupportedError: NOT_SUPPORTED_ERR,
InUseAttributeError: INUSE_ATTRIBUTE_ERR,
InvalidStateError: INVALID_STATE_ERR,
SyntaxError: SYNTAX_ERR,
InvalidModificationError: INVALID_MODIFICATION_ERR,
NamespaceError: NAMESPACE_ERR,
InvalidAccessError: INVALID_ACCESS_ERR,
TypeMismatchError: TYPE_MISMATCH_ERR,
SecurityError: SECURITY_ERR,
NetworkError: NETWORK_ERR,
AbortError: ABORT_ERR,
URLMismatchError: URL_MISMATCH_ERR,
QuotaExceededError: QUOTA_EXCEEDED_ERR,
TimeoutError: TIMEOUT_ERR,
InvalidNodeTypeError: INVALID_NODE_TYPE_ERR,
DataCloneError: DATA_CLONE_ERR,
};

This could be fixed by not using the object prototype, like so:

  const nameToCodeMapping = {
    __proto__: null,
    IndexSizeError: INDEX_SIZE_ERR,
    HierarchyRequestError: HIERARCHY_REQUEST_ERR,
@ghost ghost changed the title DOMException's came->code mapping object accesses userland mutable Object.prototype DOMException's came->code mapping object observably accesses userland mutable Object.prototype Nov 28, 2021
@bartlomieju bartlomieju added the bug Something isn't working correctly label Dec 1, 2021
@ghost ghost changed the title DOMException's came->code mapping object observably accesses userland mutable Object.prototype DOMException's name->code mapping object observably accesses userland mutable Object.prototype Apr 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant