I'm querying the database directly using the exp:query tag and filtering results on the value of a segment, is this safe?
How can I make it safe?
ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. It only takes a minute to sign up.
Sign up to join this communityNo, it is not. Using segment variables (which is user input, effectively) in a query with the Query module is generally regarded as unsafe.
You should use the Active Record plugin instead.
ee()->security->xss_clean()
or ee()->input->get_post('key', TRUE)
before being stored in the database. There are some great tips on the ExpressionEngine Security Guidelines page. It is also a good idea to escape your values in your query WHERE='{variable}'
Jan 30, 2014 at 9:52