Escaping comments when re-filling textarea after false captcha submit
-
Hey guys,
I’m trying to fix a bug in the SimpleCAPTCHA plugin which will escape double and/or single quotes in a comment, but won’t sanitize the display before re-filling the comment field. Plus, when you repeatedly enter the wrong captcha, it will double- and triple- htmlencode ampersands and such.
A comment like this:
Lorem ipsum "Dolor Sit Amet", & consetetur
, submitted with an incorrect captcha, will end up displaying like this:
Lorem ipsum \"Dolor Sit Amet\", & amp; consetetur
. Submit this again with a wrong captcha, and you get
Lorem ipsum \"Dolor Sit Amet\", & amp; amp; consetetur
.*added spaces after the ampersand.
What the plugin does if the captcha is invalid:
– it sends the comment form fields back to the same page, via POST, escaped with htmlspecialchars()
– it pre-fills the comment form with your old comment and escapes it again with htmlspecialchars()So my problem is that I’m looking for a way to re-fill the comment form without opening up a loophole.
Question: Would it be enough to str_replace any backslashes (\) before re-filling the comment form? More specifically, I’m looking for the function that WordPress uses itself to sanitze comments before writing them into the database.
Any ideas?
- The topic ‘Escaping comments when re-filling textarea after false captcha submit’ is closed to new replies.