Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to put binary image data into html markup and then get the image displayed as usual in any browser?

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

A simple example:

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.

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.

Is there already a possibility?

like image 867
Joern Akkermann Avatar asked Mar 12 '10 01:03

Joern Akkermann


People also ask

How do you display images in binary data?

var img = document. createElement('img'); img. src = 'data:image/jpeg;base64,' + btoa('your-binary-data'); document.

How do I add data to an image in HTML?

Images can be easily inserted at any section in an HTML page. To insert image in an HTML page, use the <img> tags. It is an empty tag, containing only attributes since the closing tag is not required.

Can images be stored in binary?

Digital images are made up of pixels . Each pixel in an image is made up of binary numbers. If we say that 1 is black (or on) and 0 is white (or off), then a simple black and white picture can be created using binary.

What is binary data of image?

A binary image is one that consists of pixels that can have one of exactly two colors, usually black and white. Binary images are also called bi-level or two-level, Pixelart made of two colours is often referred to as 1-Bit or 1bit. This means that each pixel is stored as a single bit—i.e., a 0 or 1.


1 Answers

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

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

like image 62
bmb Avatar answered Nov 09 '22 01:11

bmb