Should HTML be encoded before being persisted?

前端 未结 5 411
我寻月下人不归
我寻月下人不归 2020-12-31 05:11

Should HTML be encoded before being stored in say, a database? Or is it normal practice to encode on its way out to the browser?

Should all my text based field lengt

5条回答
  •  情话喂你
    2020-12-31 05:50

    The practice is to HTML encode before display.

    If you are consistent about encoding before displaying, you have done a good bit of XSS prevention.

    You should save the original form in your database. This preserved the original and you may want to do other processing on that and not on the encoded version.

提交回复
热议问题