I can’t find anything in the documentation about val() and prop() and escaping. Are
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Not really.
.val()is used to set a form field’svalueattribute, so escaping isn’t really necessary there. You’ll be setting the value via the DOM, so it’s not like you’re constructing HTML through string concatenation..prop(), on the other hand, doesn’t even interact with attributes at all – just DOM properties, so you don’t need to working about HTML escaping their either.Edit: for the sake of clarification, I’m assuming that you’re asking this because you’re concerned about
.prop()or.val()as an XSS attack vector (or just an opportunity to shoot yourself in the foot)? If that’s the case, you need to remember that when setting attributes and properties via the DOM, the values that you set are essentially sandboxed to the attribute or value you were interacting with. For example, given the following:And you attempted to abuse an attribute value, such as:
You might be concerned that this would result in something like the following:
This will never happen, though. You will indeed have a
relattribute with the evil-looking string as its value, but no new markup or DOM nodes will be created. The string itself isn’t escaped – it’s just simply not interpreted as markup. It’s just a string and that’s it.