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

相关推荐
tan77º5 分钟前
【项目】分布式Json-RPC框架 - 抽象层与具象层实现
linux·服务器·c++·分布式·tcp/ip·rpc·json
做你的猫16 分钟前
深入剖析:基于Vue 3与Three.js的3D知识图谱实现与优化
前端·javascript·vue.js
柯南二号19 分钟前
【开发配置】云服务器配置Gitlab服务
运维·服务器·gitlab
做你的猫25 分钟前
深入剖析:基于Vue 3的高性能AI聊天组件设计与实现
前端·javascript·vue.js
zt1985q27 分钟前
外网访问个人 IT 工具箱 it-tools
服务器·spring cloud·网络安全·云原生·eureka
Lovyk1 小时前
完整实验命令解析:从集群搭建到负载均衡配置(2)
linux·运维·服务器
前端无冕之王1 小时前
分享 HTML 邮件开发的 15 个踩坑实录
前端·html
dreams_dream1 小时前
vue2实现背景颜色渐变
前端·javascript·css
中微子1 小时前
🏆 ES6 异步编程挑战营:从入门到........
javascript
云飞云共享云桌面2 小时前
共享云服务器替代传统电脑做三维设计会卡顿吗
大数据·运维·服务器·数据库·自动化