You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Missing napi_type_tag_object for Napi::External? #1293
This PR added support for napi_type_tag_object, but it did so for Napi::Object.
This API is mostly useful for Napi::Externals which do no inherit from Napi::Object.
We discussed this in the 10 March Node.js Node-API meeting. The documentation for the underlying napi_type_tag_object call says:
[in] js_object: The JavaScript object to be marked.
This implies that the API is limited to objects and not externals. The team needs to clarify the semantics of this function because it may have implications on other engines that implement Node-API.
Although I can see a usage of tagging for any javascript value (a bit like using the topmost bits of a c pointer), for externals it is a question of life of segfault.
I think the underlying api should be way more strict
only create an external with a tag
only extract the void * if the tag matches
otherwise, how do I differentiate an external created by my library and one created elsewhere? and how do they do the same? probably a big security hole.
@audetto type-tagging externals and wrapped objects is certainly a good practice. The problem is that type tags came along later than the wrapped objects and externals themselves. Thus, we can no longer go back and restrict their usage, because that would break all the code out there that already uses them, potentially unrestricted. We can certainly advocate for the usage of type tags so add-on authors eventually adopt the practice of type-tagging the pointers they expose to JS.
Activity
audetto commentedon Feb 27, 2023
I can still call it but I need
external.As<Object>().CheckTypeTag()which means the API works for things that are not just
Objects.KevinEady commentedon Mar 10, 2023
We discussed this in the 10 March Node.js Node-API meeting. The documentation for the underlying
napi_type_tag_objectcall says:This implies that the API is limited to objects and not externals. The team needs to clarify the semantics of this function because it may have implications on other engines that implement Node-API.
KevinEady commentedon Mar 10, 2023
Path forward:
napi_type_tag_objectandnapi_check_type_tagcan be used on externals. We expect this to work since a workaround was pointed out on Missing napi_type_tag_object for Napi::External? #1293 (comment)audetto commentedon Mar 11, 2023
Although I can see a usage of tagging for any javascript value (a bit like using the topmost bits of a c pointer), for externals it is a question of life of segfault.
I think the underlying api should be way more strict
void *if the tag matchesotherwise, how do I differentiate an external created by my library and one created elsewhere? and how do they do the same? probably a big security hole.
gabrielschulhof commentedon Mar 17, 2023
Opened nodejs/node#47141 for the core portion.
src: interject class TypeTaggable
src: interject class TypeTaggable
src: interject class TypeTaggable
gabrielschulhof commentedon Mar 21, 2023
@audetto type-tagging externals and wrapped objects is certainly a good practice. The problem is that type tags came along later than the wrapped objects and externals themselves. Thus, we can no longer go back and restrict their usage, because that would break all the code out there that already uses them, potentially unrestricted. We can certainly advocate for the usage of type tags so add-on authors eventually adopt the practice of type-tagging the pointers they expose to JS.
audetto commentedon Mar 21, 2023
I full understand the constraints.
I think as well the lack of tags must be a source of many vulnerabilities.
src: interject class TypeTaggable
gabrielschulhof commentedon Mar 28, 2023
Fixed this in #1298. If you think more work needs to be done, please reopen this issue!
src: interject class TypeTaggable