ogallagher / tejos_textiles

An online arts journal for publishing works in a new medium
MIT License
1 stars 0 forks source link

Escaped puzzle search #16

Closed ogallagher closed 4 years ago

ogallagher commented 4 years ago

My solution for preventing SQL injection (using mysql.escape()) makes the current dp api endpoint for puzzle search unusable. The way search used to work was by tokenizing a search query, inserting each search term into “like” string:

column like '%term_1%' or column like '%term_2%' or ...

This will no longer work because the escape method in the db server converts the whole expression to a string. I will make the following changes to fix this:

  1. Pass the terms as arguments from dbclient
  2. Create a new boolean special member to denote api endpoints with special implementations
  3. Update dbserver.get_query() to check for special endpoints
  4. Create the __search_puzzles endpoint handler, which inserts the search terms into an expression like so (the terms will be filtered so as not to include the apostrophe ’__ character:
column regexp '.*((term_1)|(term_2)|...).*'