如何检查 URI 动态生成的变量名称的有效性
我正在为我的自定义 MVC 项目构建路由器。
在我的路由器中,对于漂亮的 URL 名称,我遇到了问题。通过 URI 处理动态生成的变量名称的最佳实践是什么?
示例:
http://knjiskicrv.comoj.com/book/id/2/
将生成:
$page = 'book';
$id = '2';
现在,当有人故意开始搞乱 URI 时,可能会出现问题。喜欢:
http://knjiskicrv.comoj.com/book/id+one/2/
我会得到:
$page = 'book';
$id one = '2';
希望有人能给我一些如何预防和解决这个问题的建议?谢谢。
I am building router for my custom MVC project.
In my router, for pretty URL names, I ran into problem. What is the best practice for dealing with dynamically generated variables names via URI?
Example:
http://knjiskicrv.comoj.com/book/id/2/
Will generate:
$page = 'book';
$id = '2';
Now, problem may arise when someone deliberately start messing up with URI. Like:
http://knjiskicrv.comoj.com/book/id+one/2/
I will get:
$page = 'book';
$id one = '2';
Hope someone could give me some advice how to prevent and solve this? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您是在询问如何减轻“跨站脚本”(XSS)漏洞。
这是一个很大的话题。请记住:(可能是恶意的)用户可以通过多种方式“故意开始搞乱……URI”。
建议:开始阅读:)
这里有一些链接:
http://seancoates.com/blogs/xss-woes< /a>
http://www.cgisecurity.com/xss-faq.html
http://www.uri.edu/webservices/phpGuideline.html
I think you're asking about mitigating "Cross Site Scripting" (XSS) vulnerabilities.
That's a big topic. And remember: there are LOTS of ways for a (potentially malicious) user to "deliberately start messing ... with the URI".
Suggestion: start reading :)
Here are some links:
http://seancoates.com/blogs/xss-woes
http://www.cgisecurity.com/xss-faq.html
http://www.uri.edu/webservices/phpGuideline.html
首先,输入清理该网址。不要从可欺骗的输入源创建动态变量。好吧,您必须知道给定页面上会发生什么。这些变量保存什么变量以及什么类型的变量。
如果您必须显示一组类别,并且其中一个类别的名称是“id”
/products/monkeys/white/id/,该怎么办 - 您正确地...d
选择不同的约定来处理您的 URI。
就像将 URI 划分为区域、部分和页面元素一样。
http://www.oink.com/products/pigs/spottyones/angry /the_big_spotty_pig.html
区域 = '产品'
节 = array('spottyones','愤怒')
page = the_big_spotty_pig (这唯一标识了文章、产品等)。
当我必须使用变量时,这些变量主要与排序、页码等有关。因此可以将这些变量作为查询字符串参数附加。
更新
消毒:
你必须为自己设定规则。假设 URI 只能包含某些字符。
First of all, input sanitize that url. Do not create dynamic variables from a spoofable input source. Well, you have to know, what to expect on the given page. What variables and what type of variables these hold.
What if you have to display a set of categories and one of the categories' name is 'id'
/products/monkeys/white/id/ - you are properly ...d
Choose a different convention for processing your URI.
Like divide the URI into area, section and page elements.
http://www.oink.com/products/pigs/spottyones/angry/the_big_spotty_pig.html
area = 'products'
section = array('spottyones','angry')
page = the_big_spotty_pig (this uniquely identifies the article, product etc.)
When I have to use variables, these are mostly about ordering, page nr, etc. So these can be appended as query string parameters.
UPDATE
Sanitization:
You have to set the rules for yourself. Let's say the URI can only contain certain characters.
您可以将这些变量存储在数组中,这样您
就得到了我的建议。
You could store those variables in an array, so you get
Just my suggestion.