fmdano
02/04/2022, 9:12 PMdavidrschaller
02/04/2022, 9:22 PMencodeForHTML()
(https://cfdocs.org/encodeforhtml) on the public variable. Why? Because you can never trust the client and what they send, make sure you use the built-in ColdFusion encoding functions in order to avoid XSS hacks or worse on incoming public (rc
) variables.
Note: rc is a structure that is populated with form and url scope.Myka Forrest
02/04/2022, 9:22 PMbdw429s
02/04/2022, 9:23 PMbdw429s
02/04/2022, 9:23 PMbdw429s
02/04/2022, 9:23 PMencodeForHTML()
should be used when building up HTML with untrusted values. Whether that HTML is going ot be used to "pass variables" is largely orthogonal.bdw429s
02/04/2022, 9:24 PMfmdano
02/04/2022, 9:24 PMbdw429s
02/04/2022, 9:24 PMfmdano
02/04/2022, 9:25 PMbdw429s
02/04/2022, 9:25 PMfmdano
02/04/2022, 9:26 PMbdw429s
02/04/2022, 9:26 PMdisplayed on another screen,This depends on what you mean by "displayed". Displayed how? INside a JS string that's appended to the DOM? Inside an HTML tag? Inside an HTML tag's attribute? Inside a query string?
bdw429s
02/04/2022, 9:26 PMfmdano
02/04/2022, 9:26 PMbdw429s
02/04/2022, 9:27 PM<div>#encodeForHTML( unstrustedValue )#</div>
bdw429s
02/04/2022, 9:27 PM<input type="text" value="#encodeForHTMLAttribute( unstrustedValue )#">
fmdano
02/04/2022, 9:28 PMbdw429s
02/04/2022, 9:28 PMbdw429s
02/04/2022, 9:28 PMfmdano
02/04/2022, 9:28 PMzackster
02/04/2022, 9:34 PMbdw429s
02/04/2022, 9:39 PMbdw429s
02/04/2022, 9:39 PMBrad <b>Wood</b>
then who am I to question that or remove any of those characters?bdw429s
02/04/2022, 9:40 PMencodeForHTML()
when I display it back to them, it will show up exactly like that again.bdw429s
02/04/2022, 9:41 PMbdw429s
02/04/2022, 9:42 PMzackster
02/04/2022, 10:21 PMbdw429s
02/04/2022, 10:24 PMAdam Cameron
encodeForHtml
. In an HTML attribute in that doc? encodeForHtmlAttribute
. etc.
Do not second-guess the ultimate usage and encode it for that upon storage. DO NOT encode a value before storing it in a DB(*), and think yer covered. Why? ~Two~Three reasons:
⢠you don't know how it will be used. You don't. Stop thinking you do. And it's just bad coupling anyhow.
⢠It is more difficult to tell from looking at your output code (eg view) whether you are protected or not. If you see a view with every value encoded at use, you know yer safe. If some are and some aren't [because reasons]? How do you now?
⢠Also the source of the data that ends up being rendered in one's view for that particular variable might not come from the value that was encoded before storing. Again: it's bad coupling to assume it will be.
(*) that is not to say that one oughtn't protect any value used in an SQL statement as well. Parameterising data values only gets you so far. When building SQL dynamically one needs to consider the composition of the actual SQL as well. This is tangential to the question asked, but still a consideration.
Oh and never ever rely on anything done on the clientside. That stuff is only for UX, not data-processing / security.bdw429s
02/04/2022, 11:10 PMzackster
02/04/2022, 11:13 PMzackster
02/04/2022, 11:14 PMzackster
02/04/2022, 11:16 PMAdam Cameron
Adam Cameron
fmdano
02/06/2022, 6:24 PM