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

相关推荐
Python私教1 小时前
PrimeVue菜单组件深度解析:构建高效能的Web导航系统
前端·javascript·vue.js
pp-周子晗(努力赶上课程进度版)1 小时前
【Linux】利用多路转接epoll机制、ET模式,基于Reactor设计模式实现
服务器·网络·设计模式
九月镇灵将1 小时前
Ubuntu服务器部署多语言项目(Node.js/Python)方式实践
服务器·ubuntu·node.js·screen·supervisor
明天不下雨(牛客同名)2 小时前
介绍一下 MVCC
java·服务器·数据库
黑匣子~3 小时前
Vue 3 官方 Hooks 的用法与实现原理
前端·javascript·vue.js
一只小灿灿3 小时前
Flask 与 Django 服务器部署
服务器·django·flask
Clownseven3 小时前
[安全清单] Linux 服务器安全基线:一份可以照着做的加固 Checklist
linux·服务器·安全
尬尬_4 小时前
【计算机网络】TCP如何保障传输可靠性_笔记
服务器·笔记·tcp/ip·计算机网络·考研
Geek-SX5 小时前
Seata1.8.0安装部署流程linux
linux·运维·服务器
霍志杰5 小时前
iframe加载或者切换时候,短暂的白屏频闪问题解决
前端·javascript·chrome