关于系统
我的项目中有这种格式的URL: -
http://project_name/browse_by_exam/type/tutor_search/keyword/class/new_search/1/search_exam/0/search_subject/0
Run Code Online (Sandbox Code Playgroud)
其中关键字/类对意味着使用"class"关键字进行搜索.
我有一个常见的index.php文件,它为项目中的每个模块执行.只有一个重写规则可以从URL中删除index.php: -
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,QSA]
Run Code Online (Sandbox Code Playgroud)
我在阅读搜索URL时准备搜索URL和urldecode()时使用urlencode().
问题
只有正斜杠字符会破坏导致404页面未找到错误的URL.例如,如果我搜索one/twoURL是
http://project_name/browse_by_exam/type/tutor_search/keyword/one%2Ftwo/new_search/1/search_exam/0/search_subject/0/page_sort/
Run Code Online (Sandbox Code Playgroud)
我该如何解决?我需要将index.php隐藏在URL中.否则,如果不需要,那么正斜杠就没有问题了,我可以使用这个URL: -
http://project_name/index.php?browse_by_exam/type/tutor_search/keyword/one
%2Ftwo/new_search/1/search_exam/0/search_subject/0
Run Code Online (Sandbox Code Playgroud) 我有一种情况,我想在URI(%2F)中编码斜杠,但我.htaccess发出请求时会忽略我的规则,而是发送给404页面.我很快找到了AllowEncodedSlashes我打算开启的Apache指令,但我仍然不明白为什么它首先是安全风险.如果他们试图邪恶的话,难道没有人能手动将编码的斜杠转换为真正的斜杠吗?(虽然我看不出他们能做什么伤害......)
我正在测试的应用程序是用PHP编写的,与它接口的mod_rewrite规则如下所示:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^test/(.*)$ /test.php?_escaped_fragment_=$1 [NE,QSA,L]
Run Code Online (Sandbox Code Playgroud)
我只想确保在继续之前了解风险.
澄清一下:Apache不允许在路径中使用编码斜杠,但在查询字符串中允许使用它们.查询字符串与下面的Christian列出的漏洞一样容易受到攻击("远程代码执行,本地文件访问和目录遍历").
那么ASF为什么要创建一个特殊的指令只是为了允许这种行为呢?我不是很难,我真的不明白.我认为不用说任何用户输入(包括URI)都需要在任何数据库或文件系统功能中使用之前进行验证.
我看到Django的urlencode过滤器默认不编码斜杠:
https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#urlencode
我知道我可以对斜杠进行编码,但为什么不默认呢?是不是接受了对斜杠进行编码的行为,因为它是URL中的保留字符?
Salvete!我发现某种url编码方式打破了链接.记录%2f代表正斜杠字符:/
现在,考虑一下:原始链接: http://dottech.org/95285/this-is-the-pacific-barreleye-a-fish-with-a-transparent-head-amazing-photo-of-the-day
javascript(encodeURIComponent)urlencoded链接:http://dottech.org%2f95285%2fthis-is-the-pacific-barreleye-a-fish-with-a-transparent-head-amazing-photo-of-the-day
现在,如果您将编码的链接粘贴到浏览器的地址栏中,它就会被破坏(Firefox,Chrome,IE).
但是,如果你没有对第一个正斜杠进行url编码,它就可以完美地运行:http://dottech.org/95285%2fthis-is-the-pacific-barreleye-a-fish-with-a-transparent-head-amazing-photo-of-the-day
为什么?
我有一个控制器,其方法有一个在路由中传递的变量 - 控制器:
\n\n[Route("cont/{MyParameter}")]\npublic ActionResult Index(string MyParameter)\n{\n...\n}\nRun Code Online (Sandbox Code Playgroud)\n\n当我像这样在 URL 中传递一个值 (abcdef) 时,就可以了:
\n\nhttp://localhost/my-website/cont/abcdef\nRun Code Online (Sandbox Code Playgroud)\n\n但是,当我传递带有编码斜杠的一个时,它失败了,就好像斜杠没有编码一样,例如:
\n\nhttp://localhost/my-website/cont/abc%2fdef\nRun Code Online (Sandbox Code Playgroud)\n\n我在 IIS 中收到“无法找到资源”的消息 - 请求的 URL 显示在以下内容中:
\n\nRequested URL\n\xc2\xa0\xc2\xa0\xc2\xa0http://localhost:80/f-website/cont/abc/def\nRun Code Online (Sandbox Code Playgroud)\n\n它似乎添加了斜杠 - 尽管它们已被编码。
\n\n但地址栏仍然显示原始 URL,其中包含 %2f。
\n\n如何将 / 作为参数传入?我认为 URL 编码是这里的解决方案,但它显然没有效果。
\n\n我在谷歌上找不到任何关于这个具体问题的信息。
\n我目前正在尝试对字符串进行编码以插入到 URL 中。我的问题是,当我的字符串包含反斜杠时,这似乎会失败。到目前为止,我已经使用 URLencode、curlEscape(来自 RCurl)和curlPercentEncode(来自 RCurl)函数尝试了 4 种方法,但没有一个成功。
> URLencode("hello\hello")
Error: '\h' is an unrecognized escape in character string starting ""hello\h"
> curlEscape("hello\hello")
Error: '\h' is an unrecognized escape in character string starting ""hello\h"
> curlPercentEncode("hello\hello")
Error: '\h' is an unrecognized escape in character string starting ""hello\h"
> curlPercentEncode("hello\hello", amp=TRUE)
Error: '\h' is an unrecognized escape in character string starting ""hello\h"
Run Code Online (Sandbox Code Playgroud) urlencode ×3
url ×2
.htaccess ×1
apache ×1
c# ×1
django ×1
hyperlink ×1
javascript ×1
mod-rewrite ×1
php ×1
python ×1
r ×1
rcurl ×1
url-encoding ×1