Injection or bad in anyway? - Printable Version +- MyBB Community Forums (https://community.mybb.com) +-- Forum: Extensions (https://community.mybb.com/forum-201.html) +--- Forum: Plugins (https://community.mybb.com/forum-73.html) +---- Forum: Plugin Development (https://community.mybb.com/forum-68.html) +---- Thread: Injection or bad in anyway? (/thread-185532.html) |
Injection or bad in anyway? - sleeping - 2015-10-23 I need to programmatically create a thread with some data in it and currently I achieve it in the following way:
It does work, and I only have 1 concern, I am not using "escape_string" on the message field, the message field is mainly predefined by me with the exception of 2 entries the URL and the username. I do use:
Just in case this is my Slug function: To make both the username and product name safe and I was wondering if interpolating it inside my $tmessage could cause a security issue.Thanks. RE: Injection or bad in anyway? - Omar G. - 2015-10-23 Escape it. RE: Injection or bad in anyway? - Nathan Malcolm - 2015-10-24 Escape everything which goes into the database. No exceptions. RE: Injection or bad in anyway? - sleeping - 2015-10-24 (2015-10-23, 11:21 PM)Omar G. Wrote: Escape it. When I escape $tmessage I can never get it to display the newlines, the thread doesn't read it or parse it after posted. How can I make the new lines work? Like it creates the thread fine but newlines show up as \n\n since the escape will escape em. RE: Injection or bad in anyway? - dragonexpert - 2015-10-24 Use nl2br to make new lines actually show a new line. RE: Injection or bad in anyway? - sleeping - 2015-10-24 (2015-10-24, 01:04 PM)dragonexpert Wrote: Use nl2br to make new lines actually show a new line. Well I don't want to change the code of how a thread is read, I want to figure out how to properly insert the data without having to manipulate where it is read. Otherwise I would have a major headache figuring out why the whole forum is not reading threads in a different way it was. When I manually changed my $tmessage from \n to <br> it simple "parsed" it as it is considered as HTML and result was &qt;br<, which is technically what the nl2br would do, turn it in <br>. I further checked the datahandler and function_post and I don't see nl2br being used at all. RE: Injection or bad in anyway? - Omar G. - 2015-10-24 Did you tried..
RE: Injection or bad in anyway? - sleeping - 2015-10-24 yes, it becomes escaped \n as well, I am trying to find what my insertion code is missing that properly makes new lines accepted. Ok I think I understood it? This is from the newthread.php:
escapes are not used at all in there, then further looking at the post handler the escaping is automatically done there.
So I am technically double escaping it hence why it doesn't work. So in the outside layer I don't have to worry about escaping it and when I send it to the post handler it will do all the work? Did I get it right? RE: Injection or bad in anyway? - Omar G. - 2015-10-25 Yes I think you are correct. The insert_post method already escapes everything. |