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

Handle LFE bytes in REST handler #9

Open
4 tasks
oubiwann opened this issue Aug 13, 2015 · 7 comments
Open
4 tasks

Handle LFE bytes in REST handler #9

oubiwann opened this issue Aug 13, 2015 · 7 comments
Labels
Milestone

Comments

@oubiwann
Copy link
Member

oubiwann commented Aug 13, 2015

Task:

  • Receive bytes in POST route
  • Convert bytes to string
  • Build list of all mod:func occurrences in string
  • If any of those are not in the allowed/safe list of mod:funcs, reject the entire payload out of hand, returning an appropriate HTTP error and JSON error payload

Depends upon:

@yurrriq
Copy link

yurrriq commented Aug 20, 2015

How tricky would it be to redefine the LFE code that parses funcalls to check a white/blacklist? i.e.

  • User types code and code is sent over the wire to interpreter as string
  • Interpreter parses the string
  • Eval parsed string, checking each funcall against the list
    • If allowed, pass to actual funcall handler
    • Otherwise, return 🚫

@oubiwann
Copy link
Member Author

This discussion should probably be in ticket #4.

This ticket is just for providing the functionality of string parsing for use by the YAWS appmod/REST service. I should have put more detail in the ticket description.

@oubiwann
Copy link
Member Author

Alight, I've made a very first pass at this. Still not sure about going the LFE shell process route or the ENV management route (#14). I'm leaning towards ENV now ...

Anyway, here's a screenie showing some basic evaluation happening in the REST server and then getting passed up to the JS in the browser:

screen shot 2015-08-20 at 1 45 58am

@rvirding
Copy link
Member

These three issues, #8 #9 and #14, are really three sides of the same problem so I will write once and copy and then we will see where the discussion goes.

  • It would be quite easy to open the LFE shell and provide externally callable functions to process commands. run_string and run_script almost do that today.
  • You would then write a new top-loop using these functions.
  • This would not solve the problem of input/output when processing the commands, they by default send to/read from standard_io.

An easier way might then be to use the existing shell but to reset where the shell's, and the processes it starts, standard_io to control input/output. You then automatically handle all io in the commands. This is actually very easy to do, an example*:

http://www.geekherocomic.com/2008/11/12/real-programmers-dont-write-documentation/

This can also make the shell manager easier. The real question is then how we want to interface the "shell".

  • This is also a good example of how versatile the io system really is. :-)

@oubiwann
Copy link
Member Author

The command results coming back into JavaScript from the REST server that executes the LFE code are getting converted to JSON before they do. There's nothing yet that deserializes data structures. For instance, calling (init:get_arguments) in the browser REPL returns [object Object] (but the debug output on the server shows the json that it actually is).

This is one of many things that will have to be addressed by the JS command/results parsing code. I'll update the main description with tasks as I identity them.

@oubiwann
Copy link
Member Author

Addressed this with the following change:

-         (json (ljson:encode `#(result ,result))))
+         (str-result (lists:flatten (lfe_io:fwrite1 "~p~n" `(,result))))
+         (json (ljson:encode `#(result ,(list_to_binary str-result)))))

@oubiwann oubiwann added this to the 0.3.0 milestone Feb 19, 2021
@oubiwann
Copy link
Member Author

I think we're just going to receive bytes ... let me update the title and the description.

@oubiwann oubiwann changed the title Implement command processor Handle LFE bytes in REST handler Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants