开发者

Minimum requirements for escaping HTML output

开发者 https://www.devze.com 2023-01-04 03:06 出处:网络
What are the characters that are required and suffice when escaping user-generated content before o开发者_运维百科utput? (in other words: what are the characters web developers should escape when outp

What are the characters that are required and suffice when escaping user-generated content before o开发者_运维百科utput? (in other words: what are the characters web developers should escape when outputting text that previously came from an untrusted, anonymous source?)


When echoing to a page, you should encode

  • '&' (ampersand) becomes '&'
  • '"' (double quote) becomes '"'
  • ''' (single quote) becomes '''
  • '<' (less than) becomes '&lt;'
  • '>' (greater than) becomes '&gt;'

From PHP's htmlspecialchars() docs.

Note that the context also matters.

You'll also need to take the character set into account.


I think that escaping the < > & " ' symbols should be enough for any scenario.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号