通过使用图像源的协议相关URL来防止安全/不安全的错误 [英] Preventing secure/insecure errors by using protocol relative URLs for image source

查看:134
本文介绍了通过使用图像源的协议相关URL来防止安全/不安全的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有人知道是否有问题使用协议相对URL 以防止混合内容安全警告。



例如,链接一个图像:

 < img src =// domain.com/img.jpg/> 

而不是:

 < img src =http://domain.com/img.jpg/> 

< img src =https // domain.com / img.jpg/>

在我的测试中,我没有看到任何暗示这是错误的,但我不确定是否它在边缘情况下会产生问题。



编辑我在使用PHP

解决方案使用协议相对URL:


您必须小心在
的页面中只使用
这种语法浏览器。如果您将其放入电子邮件
中,则无法使用
解析相对URL的基本页面URL。在
Outlook中,至少该网址将被
解释为Windows网络文件,
不是您想要的。


来自此处



基本上,尽管没有合理的理由说明,只要请求是由浏览器而不是外部电子邮件客户端发出的,为什么这种方式不适用。



更多信息来自此处


没有方案的相对URL(http:
或https :)对于每个RTF 3986有效:
Section 4.2。如果一个客户端嘲讽它,
,那么这是客户端的错,因为
它们不符合RFC中指定的URI
语法。



你的例子是有效的,应该工作。
我在重度贩卖的网站上使用了相对URL方法

没有投诉。此外,我们
测试我们的网站在Firefox,Safari,
IE6,IE7和Opera。这些浏览器全部
了解URL格式



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:

<img src="//domain.com/img.jpg" />

instead of:

<img src="http://domain.com/img.jpg" />
or
<img src="https//domain.com/img.jpg" />

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆