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

[Feature] Continuation callbacks to avoid malicious scripts #478

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

LRagji
Copy link

@LRagji LRagji commented Oct 4, 2020

Hi would like to contribute a feature which can be used to avoid infinite recursions or scripts which can potentially be used to lock up cpu..

Approach: Since the execution was already an iterator loop a callback can be invoked to check if the user wants to proceed with the next step or cancel the execution in async evaluations.

Examples: Script like ($x:= λ($c,$n,$b){ $c=$b?$n%2:$x($c+1,$floor($n/2),$b)};$x(0,number,bitIndex)) which uses recursion to find the bit at a given position can loop infinity if wrong bit index is given like -1, since many application using jsonata use it to run user provided scripts this kind of callback will help them to track cpu time and memory as well if required thus making it a good sandbox for such things.

Signed-off-by: Laukik R

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 5360a44 on LRagji:master into 27724d9 on jsonata-js:master.

@LRagji LRagji marked this pull request as draft October 5, 2020 18:01
@LRagji LRagji marked this pull request as ready for review October 5, 2020 18:07
@LRagji
Copy link
Author

LRagji commented Oct 5, 2020

@andrew-coleman would help if this could be reviewed and merged. also i cant add reviewers

@andrew-coleman
Copy link
Member

Hi @LRagji, thank you for offering this PR, it's certainly an area that needs addressing for reasons you've identified.
I've started to build a JSONata visual debugger, which also has the requirements of breaking into expression evaluation, stepping and potentially aborting, but with the added requirement of examining values and expression position at each step.
The approach I have taken can be seen here:
https://github.com/jsonata-js/jsonata/blob/debugger/src/jsonata.js#L2146

Although your approach fits your needs perfectly, I'd rather hold off merging until I've made more progress with the debugger so we can get a consistent API for all needs. I'll keep this PR open for reference.
Thanks!

@LRagji
Copy link
Author

LRagji commented Oct 7, 2020

@andrew-coleman Thanks for the update, it seems direction was right our paths differ, while you are working on this i agree we should hold the PR, in the interim do we have any solution for sandboxing scripts coming from untrusted sources?, while the on going work is more in terms of Debugger, my challenge was from security perspective(and i believe others may also have the same) do you think extending the callback with context object can serve both our purpose to get this in faster?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants