Skip to content

How to sanitize user inputs from untrusted sources? #2500

Answered by jjtolton
jjtolton asked this question in Q&A
Discussion options

You must be logged in to vote

Having progressed a little further with Prolog, the answer and suggested best practice now is fairly clear. Simply take a user input, then

  1. string interpolate as you would naively (unsafe), then
  2. use read_from_chars/3 to convert the string to Prolog terms
  3. then feed the Prolog terms into a Prolog predicate or better yet a meta-interpreter
  4. Under no circumstances use call/N on the result of bullet [1] or [2] and you will be fine.

Replies: 4 comments 14 replies

Comment options

You must be logged in to vote
9 replies
@jjtolton
Comment options

@jjtolton
Comment options

@hurufu
Comment options

@jjtolton
Comment options

@hurufu
Comment options

Comment options

You must be logged in to vote
1 reply
@bakaq
Comment options

Comment options

You must be logged in to vote
4 replies
@hurufu
Comment options

@jjtolton
Comment options

@jjtolton
Comment options

@hurufu
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by jjtolton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants