检查输入、兼容性与严格性
当解析和验证输入时,两条指令相互矛盾。
检查一切以确保安全。不要让垃圾进来,因为这可能会导致谁知道什么会被扔出去。
对接受输入要宽容(但对产生输出要严格),否则就会造成不必要的不兼容性。
什么原则决定应用哪条规则?我最好的猜测是,(1) 适用于您正在验证将在其他地方传递的数据的情况。还有其他考虑吗?
When parsing and validating input, two dicta are in tension with each other.
Check everything for safety. Don't allow garbage in, because it can lead to who knows what out.
Be permissive about accepting input (but strict about producing output), because otherwise you are creating unnecessary incompatibilities.
What principle decides which 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想说#1更多地应用于输入的内容(它真的是一个人的名字,还是一个DROP TABLE命令?),而#2更多地应用于输入的格式(几乎有效的XML - - 我们知道你的意思,所以我们会接受)。
我还认为,#2 实现的各种情况(接受较差的 HTML 或 XML;允许 javascript 没有分号作为行结尾)已被证明是错误。
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.