通过使用图像源的协议相关URL来防止安全/不安全的错误 [英] Preventing secure/insecure errors by using protocol relative URLs for image source
问题描述
是否有人知道是否有问题使用协议相对URL 以防止混合内容安全警告。
例如,链接一个图像:
< img src =// domain.com/img.jpg/>
而不是:
< img src =http://domain.com/img.jpg/>
或
< img src =https // domain.com / img.jpg/>
在我的测试中,我没有看到任何暗示这是错误的,但我不确定是否它在边缘情况下会产生问题。
编辑我在使用PHP 您必须小心在 来自此处 基本上,尽管没有合理的理由说明,只要请求是由浏览器而不是外部电子邮件客户端发出的,为什么这种方式不适用。 更多信息来自此处: 没有方案的相对URL(http: 你的例子是有效的,应该工作。 Is anyone aware of whether it is problematic to use protocol relative URLs for an image source to prevent mixed content security warnings. For example linking an image like: instead of: In my testing i've not seen anything to suggest this is wrong but i'm not sure if it has edge cases where it will create problems. EDIT i've seen it throw errors when using PHP's getimagesize function. Found an interesting gotcha for the use of protocol relative URLs: You have to be careful to only use
this syntax in pages destined for
browsers. If you put it in an email,
there will be no base page URL to use
in resolving the relative URL. In
Outlook at least, this URL will be
interpreted as a Windows network file,
not what you intended. from here Essentially though there are no valid reasons why this shouldn't work as long as the request is made by a browser and not an external email client. more info from here: A relative URL without a scheme (http:
or https:) is valid, per RTF 3986:
Section 4.2. If a client chokes on it,
then it's the client's fault because
they're not complying with the URI
syntax specified in the RFC. Your example is valid and should work.
I've used that relative URL method
myself on heavily trafficked sites and
have had zero complaints. Also, we
test our sites in Firefox, Safari,
IE6, IE7 and Opera. These browsers all
understand that URL format
这篇关于通过使用图像源的协议相关URL来防止安全/不安全的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
的页面中只使用
这种语法浏览器。如果您将其放入电子邮件
中,则无法使用
解析相对URL的基本页面URL。在
Outlook中,至少该网址将被
解释为Windows网络文件,
不是您想要的。
或https :)对于每个RTF 3986有效:
Section 4.2。如果一个客户端嘲讽它,
,那么这是客户端的错,因为
它们不符合RFC中指定的URI
语法。
我在重度贩卖的网站上使用了相对URL方法
,
没有投诉。此外,我们
测试我们的网站在Firefox,Safari,
IE6,IE7和Opera。这些浏览器全部
了解URL格式
<img src="//domain.com/img.jpg" />
<img src="http://domain.com/img.jpg" />
or
<img src="https//domain.com/img.jpg" />