Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can something "bad" happen via img src?

Tags:

I know, I know, title is quite bad, but I'll try to explain what I mean here. So, I ask my members to show their photos. They upload it somewhere, then paste their photos' URL into input and I save it to my database (MYSQL). Then, the photo is being seen on their profiles. I get the URL from database and do something like that: <img src="<?=$photo;?>" height="123px" width="123px">"> where $photo is URL taken from MYSQL. Is it totally safe? Can somebody upload for example .php file and harm my website? Do I need to check if URL's ending is .gif, .png, .jpg?
Thank you.

Edit: Yeah, of course I would protect my website from SQL injections and XSS attacks. But is there any way to harm my website in other way?

like image 837
good_evening Avatar asked Jun 24 '10 22:06

good_evening


People also ask

What will img src bad jpg do?

Answer: It will insert the image namef BAD. JPG in your HTML if it exists.

What is the purpose of IMG src?

The <img> src attribute is used to specify the URL of the source image. Attribute Values: It contains single value URL which specifies the link of source image.

Can img src be empty?

Use the getAttribute() method to check if an image src is empty, e.g. img. getAttribute('src') . If the src attribute does not exist, the method returns either null or empty string, depending on the browser's implementation.


2 Answers

What you described may be vulnerable to an XSS (Cross-site Scripting) attack. Essentially, a nefarious user may be able to inject javascript code that could do bad things, while executing as your site.

For an example of this attack vector, check out: http://jarlsberg.appspot.com/part2#2__stored_xss_via_html_attribute

EDIT: It sounds like you are already protecting yourself agains SQL injections and XSS, and you are wondering if there is some way for someone to inject PHP code into your site. I don't think this is possible, since your server-side code will not be executing this string. You are simply instructing the client browser to download an image from a URL.

It may be possible for someone to link to an image file that is infected with a virus, which would then infect other visitors to your site, but it would not affect the site itself.

like image 171
pkaeding Avatar answered Nov 04 '22 07:11

pkaeding


No, it's not safe at all, XSS attacks can be executed through image tags.

A simple example would be:

<IMG SRC=j&#X41vascript:alert('test2')> 

http://www.owasp.org/index.php/Cross-site_Scripting_%28XSS%29

like image 42
Damien Dennehy Avatar answered Nov 04 '22 07:11

Damien Dennehy