html通过使用图像源的协议(protocol)相对 URL 来防止安全/不安全错误

有人知道使用 protocol relative URLs 是否有问题吗?用于图像源以防止混合内容安全警告。

例如链接一张图片:

html 复制代码
<img src="//domain.com/img.jpg" /> 

代替:

html 复制代码
<img src="http://domain.com/img.jpg" /> 
or 
<img src="https//domain.com/img.jpg" /> 

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

编辑 我看到它在使用 PHP 的 getimagesize 时抛出错误功能。

请您参考如下方法:

在使用协议(protocol)相对 URL 时发现了一个有趣的问题:

ou 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.

来自 here

基本上,只要请求是由浏览器而不是外部电子邮件客户端发出的,就没有正当理由说明这不应该起作用。

更多信息来自 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

相关推荐
cmd2 分钟前
别再混淆了!JS类型转换底层:valueOf vs toString vs Symbol.toPrimitive 详解
前端·javascript
用户158159637437011 分钟前
AI Agent 说"完成了",但其实没有——任务验收机制的工程实践
javascript
han_21 分钟前
JavaScript设计模式(四):发布-订阅模式实现与应用
前端·javascript·设计模式
276695829223 分钟前
租车帮(悟空)订单查询算法分析
java·服务器·前端·悟空·悟空app·租车帮·租车帮逆向
青瓦梦滋23 分钟前
Linux进程间通信(IPC)——system V
linux·服务器·c++·文件
蓝队云计算33 分钟前
深耕本土,安全稳定——云南云服务器为何首推蓝队云
运维·服务器·安全·云服务器·蓝队云
用户3266584037433 分钟前
如何初始化 TypeScript + Node.js 项目
javascript
陌上花开缓缓归以39 分钟前
linux boot 烧写纪要以及内存相关分析
linux·服务器·网络
m0_694845571 小时前
Docker 从入门到实践教程:docker_practice 完整学习指南
运维·服务器·docker·容器·云计算·github
hweiyu001 小时前
Linux命令:pgrep
linux·运维·服务器