security - HTML encode user input when storing or when displaying -
simple question keeps bugging me.
should html encode user input right away , store encoded contents in database, or should store raw values , html encode when displaying?
storing encoded data reduces risk of developer forgetting encode data when it's being displayed. however, storing encoded data make datamining more cumbersome , take bit more space, though that's non-issue.
i'd suggest encoding information on way out. storing raw data in database useful if wish change way it's viewed @ point. flow should similar to:
sanitize user input -> protect against sql injection -> db -> encode display
think situation might want display information rss feed instead. having redo html specific encoding before re-display seems bit silly. development should follow "don't trust input" meme, whether input user or database.
Comments
Post a Comment