是否可以将二进制图像数据放入 html 标记中,然后在任何浏览器中照常显示图像? [英] Is it possible to put binary image data into html markup and then get the image displayed as usual in any browser?

查看:18
本文介绍了是否可以将二进制图像数据放入 html 标记中,然后在任何浏览器中照常显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个重要的安全问题,我相信这应该是可能的.

It's an important security issue and I'm sure this should be possible.

一个简单的例子:

您经营社区门户.用户注册并上传他们的照片.每当允许显示图片时,您的应用程序都会提供安全规则.比如用户必须是系统两边的好友,才能看到别人上传的图片.

You run a community portal. Users are registered and upload their pictures. Your application gives security rules whenever a picture is allowed to be displayed. For example users must be friends on each sides by the system, in order that you can view someone else's uploaded pictures.

问题来了:可能有人爬取了您服务器的图像目录.但您希望保护您的用户免受此类攻击.

Here comes the problem: it is possible that someone crawls the image directories of your server. But you want to protect your users from such attacks.

如果可以将图像的二进制数据直接放入 HTML 标记中,您可以将图像目录的用户访问权限限制为用户,并将您的 Web 应用程序运行分组并将图像数据传递给您的 Apache 用户和直接在 HTML 中分组.

If it's possible to put the binary data of an image directly into the HTML markup, you can restrict the user access of your image dirs to the user and group your web application runs of and pass the image data to your Apache user and group directly in the HTML.

唯一可能的弱点是运行您的网络应用程序的用户的密码.

The only possible weakness then is the password of the user that your web app runs as.

已经有可能了吗?

推荐答案

在其他答案中描述了其他(更好)的方法来保护您的文件,但是可以将图像嵌入到您的 html 中.

There are other (better) ways, described in other answers, to secure your files, but yes it is possible to embed the image in your html.

以这种方式使用 标签:

Use the <img> tag this way:

<img src="data:image/gif;base64,xxxxxxxxxxxxx...">

其中 xxxxx... 部分是 gif 图像数据的 base64 编码.

Where the xxxxx... part is a base64 encoding of gif image data.

这篇关于是否可以将二进制图像数据放入 html 标记中,然后在任何浏览器中照常显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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