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
process: introduce codeGenerationFromString event #35157
base: master
Are you sure you want to change the base?
process: introduce codeGenerationFromString event #35157
Conversation
|
This still feels like the wrong abstraction level. What if we did |
|
A flag won't be usable on many serverless environments, being able to set it at runtime (like this PR proposes) seems more appropriate. |
|
My main concern here is that some random library has no business knowing what i'm passing to How about this: const release = v8.setCodeGenerationFromStringHandler((code) => {});
// ...
release();Once called, it can't be called again until |
|
This is an overall problem with the events we have on |
|
Agreed it would be great to see this kind of stuff moved out into loaders or a similar API as a higher level execution context. We previously discussed disabling high-level permissions on process, I would still like to see us deprecate more and more features from the process global over time. Even a new builtin module import for these features could allow policy scoping for who has access to it. But however it is cut, likely does seem to require a new API away from process and deprecating the old on process. |
|
@mmarchini do you have a constraint that this needs to be a process event? If not, I think we should go with the single-callback api. |
|
No constraints, as long as the handler can be defined during runtime I'm fine with it. |
That's a very fair point. As of today, almost everything in Node.js can be monkeypatched and leak implementation details. For instance. This is true for core modules, but also for built-in such as I am not sure I understand your secondary concern. This current PR does not change the |
|
@vdeturckheim are you saying you want random libraries to be able to tune into all evals and whatnot in the main context? |
|
@devsnek well right now, any library can spy on most of the things other pieces of code do. That's pretty much how APMs work. |
|
@vdeturckheim I can't tell if you're saying you need the event model or not. can you be a bit more direct? afaict the api I proposed above should work. |
|
@devsnek gotcha, sorry I missunderstood the question ^^. I only need to place one callback for my use case. But I am afraid there might be multiple libraries needing it (say, one RASP for security, one enterprise compliance tool and an APM), and a single callback would make the use of them exclusive. That's why I used an event emitter here. |
|
I guess in my ideal world I would like to see this: setCallback((code) => {
security(code);
compliance(code);
apm(code);
})do people think this is unworkable? |
|
It would require the end user to set this up and assume no library does it without the end user knowing. Overall, I found out that in the scope of instrumentation, end users don't really want to know about implementation and vendors often do their own things without considering the other ones really. |
|
Well I won't block on this, but it is certainly not ideal. |
|
@cjihrig thanks for the review, it should be good :) |
|
I don't understand the use case for this - why would I use this? |
|
@benjamingr there are multiple reasons why one could want to listen to |
|
Adding WIP flag as I need to fix a build issue (warning emitted when compiling the callback) |
The 'codeGenerationFromString' event is emitted when a call is made to `eval` or `new Function`.
321b52b
to
f1ca100
|
Converting to draft: the error flow is weird, throwing an error in the event listener makes it ignored unless there is certain calls after |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesThis is an alternative to #34863 following a suggestion from @addaleax.
As for #34863, the goal is to provide a way to listen to unsafe code generation from strings as it is not possible to monkeypatch
eval.The event will only be emitted if there is at least one listener on it and removing all listeners on this event will result in the handler in V8 to never be called. In other words, if there is no listener on this event, there should be no performance impact on calling
evalor theFunctionconstructor.The text was updated successfully, but these errors were encountered: