Saving property with HTML - encode on entry, or on display? -
i have system allows users enter html-reserved characters text area, post application. information saved database later retrieval , display. alarms (should be) going off in head. need make sure avoid xss attacks, because display data somewhere else in application. here options see it:
encode before save db
i can html-encode data on way in database, no html characters ever entered in database.
pros:
- developers don't have remember html encode data when displayed on web page.
cons:
- the data doesn't make sense desktop-based applications (or other html). stuff shows
< > &
etc.
don't html encode before saving db
i can html encode data whenever need display on web page.
pros:
- feels right because keeps integrity of data entered user.
- allows non-html based applications display data without having worry html encoding.
cons:
- we might display data in lot of places, , we'll have make sure every developer knows when display field, you'll need html encode it.
- people forget things. there @ least once instance when forget html encode data.
scrub data before saving db (don't html encode)
i can use well-tested third party library remove potentially dangerous html , safe html fragment save database, not html encoded.
pros:
- preserves of original input display in non-html format makes sense.
- less catastrophic if developer forgets html encode information display on web page.
cons:
- still messes data user entered it. if want type
<script>
or<object>
tag, won't make it, , we'll support calls , emails because of that.
my question is: best option, or if there way of going this, it?
the right thing not mangle/change user input.
so, do not encode before saving.
yes, puts onus on developers remember , know need encode coming out of db, practice regardless.
Comments
Post a Comment