URL 中保留的分号有何用途?
RFC 3986 URI:通用语法 规范将分号列为保留(子分隔符)字符:
reserved = gen-delims / sub-delims
gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="
“;”的保留用途是什么URI 中的分号?就此而言,其他子分隔符的目的是什么(我只知道“&”、“+”和“=”的目的)?
The RFC 3986 URI: Generic Syntax specification lists a semicolon as a reserved (sub-delim) character:
reserved = gen-delims / sub-delims
gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
sub-delims = "!" / "quot; / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="
What is the reserved purpose of the ";" of the semicolon in URIs? For that matter, what is the purpose of the other sub-delims (I'm only aware of purposes for "&", "+", and "=")?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
3.3 节末尾有解释。
换句话说,它是保留的,以便想要 URL 中某些内容的分隔列表的人可以安全地使用
;
作为分隔符,即使这些部分包含;
,只要因为内容是百分比编码的。换句话说,您可以这样做:并将其解释为三个部分:
foo
、bar
、baz;qux
。如果分号不是保留字符,则;
和%3b
将是等效的,因此 URI 将被错误地解释为四个部分:foo
、bar
、baz
、qux
。There is an explanation at the end of section 3.3.
In other words, it is reserved so that people who want a delimited list of something in the URL can safely use
;
as a delimiter even if the parts contain;
, as long as the contents are percent-encoded. In other words, you can do this:and interpret it as three parts:
foo
,bar
,baz;qux
. If semicolon were not a reserved character, the;
and%3b
would be equivalent, so the URI would be incorrectly interpreted as four parts:foo
,bar
,baz
,qux
.如果您返回到规范的旧版本,其意图会更清晰:
我相信它起源于 FTP URI。
The intent is clearer if you go back to older versions of the specification:
I believe it has its origins in FTP URIs.
第 3.3 节介绍了这一点 - 它是一个生成 URI 的应用程序的不透明分隔符方便的话可以使用:
Section 3.3 covers this - it's an opaque delimiter a URI-producing application can use if convenient:
关于其当前用法有一些有趣的约定。这些说明何时使用分号或逗号。来自《RESTful Web Services》一书:
There are some conventions around its current usage that are interesting. These speak to when to use a semicolon or comma. From the book "RESTful Web Services":
自 2014 年以来,已知路径段有助于 反射文件下载攻击。假设我们有一个易受攻击的 API,它反映了我们发送给它的任何内容:
现在,这在浏览器中是无害的,因为它是 JSON,因此不会呈现它,但浏览器宁愿将响应下载为文件。现在,以下路径段可以为攻击者提供帮助:
分号 (
;/setup.bat;
) 之间的所有内容都将不会发送到 Web 服务,而是发送到 Web 服务浏览器会将其解释为文件名...以保存 API 响应。现在,将下载并运行一个名为
setup.bat
的文件,而不会询问运行从 Internet 下载的文件的危险(因为它的名称中包含单词“setup”
)。内容将被解释为 Windows 批处理文件,并且将运行calc.exe
命令。预防措施:
Content-Disposition: Attachment; filename="whatever.txt"
位于不会呈现的 API 上; Google 缺少filename
部分,这实际上使攻击更容易X-Content-Type-Options: nosniff
标头添加到 API 响应中Since 2014, path segments are known to contribute to Reflected File Download attacks. Let's assume we have a vulnerable API that reflects whatever we send to it:
Now, this is harmless in a browser as it's JSON, so it's not going to be rendered, but the browser will rather offer to download the response as a file. Now here's the path segments come to help (for the attacker):
Everything between semicolons (
;/setup.bat;
) will be not sent to the web service, but instead the browser will interpret it as the file name... to save the API response.Now, a file called
setup.bat
will be downloaded and run without asking about dangers of running files downloaded from the Internet (because it contains the word"setup"
in its name). The contents will be interpreted as a Windows batch file, and thecalc.exe
command will be run.Prevention:
Content-Disposition: attachment; filename="whatever.txt"
on APIs that are not going to be rendered; Google was missing thefilename
part which actually made the attack easierX-Content-Type-Options: nosniff
header to API responses我发现了以下用例:
它是 HTML 实体的最终字符:
XML 和 HTML 列表字符实体引用
Apache Tomcat 7(或更新版本?!)将其用作
路径参数
:三个分号漏洞
URI 方案将 MIME 和数据分开:
数据 URI 方案
IIS 5 和 IIS 6 中存在绕过文件上传限制的错误:
无限制文件上传
结论:
不要在 URL 中使用分号,否则可能会意外生成 HTML 实体或 URI 方案。
I found the following use cases:
It's the final character of an HTML entity:
List of XML and HTML character entity references
Apache Tomcat 7 (or newer versions?!) us it as
path parameter
:Three Semicolon Vulnerabilities
URI scheme splits by it the MIME and data:
Data URI scheme
And there was a bug in IIS 5 and IIS 6 to bypass file upload restrictions:
Unrestricted File Upload
Conclusion:
Do not use semicolons in URLs or they could accidentally produce an HTML entity or URI scheme.