-
My expectation is the shared library functionality will be very popular (for some definition of "very popular") in web development circles, as it will function both in the browser via WASM and server via shared library. Until we have a proper C-API for constructing values, we are currently limited to providing strings to the Scryer process. For some users, it would be very easy to do something like: with scryer_process() as wam:
results = wam.eval(f"input_searchresults('{user_input}', Results).") perhaps not realizing they are inviting remote code execution or cross site scripting vulnerabilities. It would be good to advise what the correct way of reading user input is -- I'm not even sure myself! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 14 replies
-
If Scryer runs as a library then conceptually speaking the caller is responsible for doing string sanitization. I see at least 2 types of possible problems:
|
Beta Was this translation helpful? Give feedback.
-
I think reversing @bakaq 's algorithm in PR #2493 is probably the key to a convenient API that doesn't expose the user to string injection attacks. It might not be the best "Prolog" approach but from a shared library perspective it would be perfect, and it would be a good stepping stone to the C-API. |
Beta Was this translation helpful? Give feedback.
-
A general remark. When you do the following: wam.eval(f"input_searchresults('{user_input}', Results).") Then If you want a secure interface then possibly some other approaches are needed as discussed here. P.S. This problem isn't Prolog specific, you will have all exactly the same vulnerabilities if you would like for example embed JavaScript into your application. |
Beta Was this translation helpful? Give feedback.
That would be the "deserialization" part (in quotes because there is more to it than that). What I think would actually be necessary to use that as escaping is to have some way of turning a
Value
into something akin to whatwrite_canonical/2
would print, because then you can really just interpolate it into a query string and it would just work. This doesn't seem all that difficult, but there are a lot of edge cases, and any string would get ~7 times bigger because of'.'(a,'.'(b,...))
shenanigans. Even better would be to have an API to put the term directly into the Scryer Prolog heap and let it handle the rest, but with what I know of the internals that seems to have even more tricky edg…