开发者

Checking of input, Compatablity vs. Rigour

When parsing and validating input, two dicta are in tension with each other.

  1. Check everything for safety. Don't allow garbage in, because it can lead to who knows what out.

  2. Be permissive about accepting input (but strict about producing output), because otherwise you are creating unnecessary incompatibilities.

What principle decides wh开发者_如何转开发ich rule to apply? My best guess is that (1) applies to cases where you are validating data that will be passed on elsewhere. Is there any other consideration?


I'd say that #1 applies more to the content of the input (is it really a person's name, or is it a DROP TABLE command?), while #2 applies more to the format of the input (almost-valid XML -- we know what you mean, so we'll accept it).

I also think that various situations in which #2 was implemented (accepting poor HTML or XML; allowing javascript without semicolons for line endings) have proved to be mistakes.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜