octavian_krody
3 years agoGuide
How to escape user input in built liql query
Escaping id with js_string or any other escape mechanism change the semantics of what was asked from the user, while not doing it will cause invalid syntax in queries.
Given the input '123' quotes included and the following code snippet.
<#assign id = http.request.parameters.name.get("id", "") />
<#assign query = "/search?q=" + "SELECT * FROM messages where id='${id}'"?url />
${restd("2.0", query, "json")}
produces
{ "status" : "error", "message" : "Invalid query syntax", "data" : { "type" : "error_data", "code" : 603, "developer_message" : "line 1, column 35:\nwhitespaces, regexParser: (AND|OR) , regexParser: ORDER BY, regexParser: LIMIT, regexParser: OFFSET, regexParser: CURSOR or EOF expected, 1 encountered. in: SELECT * FROM messages where id=''123''", "more_info" : "" }, "metadata" : { } }
Is there any recommended way of doing such operations?