2 ms·
You don't want the sys:quasi form to evaluate: It can be used as an escape hatch. If you're binding to the null-environment, you can provide everything a user c
by shakna 10y ago
You don't want the sys:quasi form to evaluate: It can be used as an escape hatch. If you're binding to the null-environment, you can provide everything a user can use.
In my above example, a user can do things like:
(fmt post.title post.date)
(fmt post.title "@" post.date)
(fmt (fmt post.title "@" post.date) "by" post.author)
But they can't escape the sandbox and do anything else.
To make a list, they need access to list, or quote, otherwise they just have number and strings, and anything else you give them.
If you give them anything more than a null-environment, you begin to lose the safety of a safe evaluation, which might be something you want to do yourself, but not something that you want a user to have access to, or they'll find an escape hatch, like sys:quasi, and gain access to areas they shouldn't.
Which is as bad as any SQL injection, if not worse.
So, a safe eval, can be created, without the need for any further analysis, if eval is handed an environment, and only uses it.
If the eval then searches the global environment, then the eval is unsafe, and you should never hand it user input, unless you have first ensured it's safe... Which defeats all the niceness provided by first class environments.
Eval is only not evil, if the programmer controls all the bindings to eval's environment.
REPL's usually use an unsafe eval and environment, and that makes sense, as you want to be able to do anything you want in code.
But a templating language doesn't need, and shouldn't use, all the unsafeness of a Turing Complete language, that might have access to your system.